Merge branch 'master' of git.qabel.de:Qabel/schickmacher

This commit is contained in:
Niklas rust 2019-09-12 12:02:57 +02:00
commit d7d8d8dc61
3 changed files with 11 additions and 16 deletions

View file

@ -1,9 +1,10 @@
from django.urls import path from django.urls import path
from schickmacher.renderer.views import form_view, RenderView from schickmacher.renderer.views import form_view, RenderView, HtmlRenderView
app_name = 'renderer' app_name = 'renderer'
urlpatterns = [ urlpatterns = [
path("", view=form_view, name="form"), path("", view=form_view, name="form"),
path("render", view=RenderView.as_view(), name="render") path("render", view=RenderView.as_view(), name="render"),
path("renderhtml", view=HtmlRenderView.as_view(), name="renderhtml"),
] ]

View file

@ -1,6 +1,6 @@
from django.core.handlers.wsgi import WSGIRequest from django.core.handlers.wsgi import WSGIRequest
from django.shortcuts import render from django.shortcuts import render
from django.views.generic import FormView from django.views.generic import FormView, TemplateView
from django_weasyprint import WeasyTemplateView from django_weasyprint import WeasyTemplateView
from markdownx.utils import markdownify from markdownx.utils import markdownify
@ -8,21 +8,11 @@ from schickmacher.renderer.forms import RendererForm
def form_view(request: WSGIRequest): def form_view(request: WSGIRequest):
if request.method == 'POST': ctx = {"form": (RendererForm())}
form = RendererForm(request.POST)
if form.is_valid():
return render(request, 'renderer/rendered.html', {
'date': form.cleaned_data['date'],
'content': markdownify(form.cleaned_data['render_content']),
'title': form.cleaned_data['title']
})
else:
form = RendererForm()
ctx = {"form": form}
return render(request, 'renderer/render_form.html', ctx) return render(request, 'renderer/render_form.html', ctx)
class RenderView(WeasyTemplateView): class HtmlRenderView(TemplateView):
template_name = 'renderer/rendered.html' template_name = 'renderer/rendered.html'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
@ -42,3 +32,7 @@ class RenderView(WeasyTemplateView):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs) return self.get(request, *args, **kwargs)
class RenderView(HtmlRenderView, WeasyTemplateView):
pass

View file

@ -5,7 +5,7 @@
<title>{{ title }}</title> <title>{{ title }}</title>
<link href="{% static 'css/render.css' %}" rel="stylesheet"> <link href="{% static 'css/render.css' %}" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro&display=swap" rel="stylesheet">
</head> </head>
<style> <style>
@page{ @page{