diff --git a/schickmacher/renderer/urls.py b/schickmacher/renderer/urls.py index 9f32ba6..2513f13 100644 --- a/schickmacher/renderer/urls.py +++ b/schickmacher/renderer/urls.py @@ -1,9 +1,10 @@ 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' urlpatterns = [ 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"), ] diff --git a/schickmacher/renderer/views.py b/schickmacher/renderer/views.py index ea861e9..09ceb40 100644 --- a/schickmacher/renderer/views.py +++ b/schickmacher/renderer/views.py @@ -1,6 +1,6 @@ from django.core.handlers.wsgi import WSGIRequest from django.shortcuts import render -from django.views.generic import FormView +from django.views.generic import FormView, TemplateView from django_weasyprint import WeasyTemplateView from markdownx.utils import markdownify @@ -8,21 +8,11 @@ from schickmacher.renderer.forms import RendererForm def form_view(request: WSGIRequest): - if request.method == 'POST': - 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} + ctx = {"form": (RendererForm())} return render(request, 'renderer/render_form.html', ctx) -class RenderView(WeasyTemplateView): +class HtmlRenderView(TemplateView): template_name = 'renderer/rendered.html' def get_context_data(self, **kwargs): @@ -42,3 +32,7 @@ class RenderView(WeasyTemplateView): def post(self, request, *args, **kwargs): return self.get(request, *args, **kwargs) + + +class RenderView(HtmlRenderView, WeasyTemplateView): + pass diff --git a/schickmacher/templates/renderer/rendered.html b/schickmacher/templates/renderer/rendered.html index a8be7a9..079b80c 100644 --- a/schickmacher/templates/renderer/rendered.html +++ b/schickmacher/templates/renderer/rendered.html @@ -5,7 +5,7 @@ {{ title }} - +