From 3c3456431a0f9038844a42edf5d249cde10e994d Mon Sep 17 00:00:00 2001 From: Jens Kadenbach Date: Thu, 12 Sep 2019 14:27:39 +0200 Subject: [PATCH] Views with example content --- schickmacher/renderer/urls.py | 5 ++++- schickmacher/renderer/views.py | 22 +++++++++++++++++++++- schickmacher/templates/base.html | 6 ++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/schickmacher/renderer/urls.py b/schickmacher/renderer/urls.py index 2513f13..c518bdb 100644 --- a/schickmacher/renderer/urls.py +++ b/schickmacher/renderer/urls.py @@ -1,10 +1,13 @@ from django.urls import path -from schickmacher.renderer.views import form_view, RenderView, HtmlRenderView +from schickmacher.renderer.views import form_view, RenderView,\ + HtmlRenderView, SampleHTMLView, SamplePDFView app_name = 'renderer' urlpatterns = [ path("", view=form_view, name="form"), path("render", view=RenderView.as_view(), name="render"), path("renderhtml", view=HtmlRenderView.as_view(), name="renderhtml"), + path("samplehtml", view=SampleHTMLView.as_view(), name="samplehtml"), + path("samplepdf", view=SamplePDFView.as_view(), name="samplepdf"), ] diff --git a/schickmacher/renderer/views.py b/schickmacher/renderer/views.py index 09ceb40..b0b34ea 100644 --- a/schickmacher/renderer/views.py +++ b/schickmacher/renderer/views.py @@ -1,7 +1,8 @@ from django.core.handlers.wsgi import WSGIRequest from django.shortcuts import render -from django.views.generic import FormView, TemplateView +from django.views.generic import TemplateView from django_weasyprint import WeasyTemplateView +from django.utils.timezone import datetime from markdownx.utils import markdownify from schickmacher.renderer.forms import RendererForm @@ -36,3 +37,22 @@ class HtmlRenderView(TemplateView): class RenderView(HtmlRenderView, WeasyTemplateView): pass + + +class SampleHTMLView(TemplateView): + template_name = 'renderer/rendered.html' + + sample_title = 'Test Title 123' + sample_date = datetime.now() + sample_content = markdownify(open('test.md').read()) + + def get_context_data(self, **kwargs): + return { + 'title': self.sample_title, + 'date': self.sample_date, + 'content': self.sample_content + } + + +class SamplePDFView(SampleHTMLView, WeasyTemplateView): + pass diff --git a/schickmacher/templates/base.html b/schickmacher/templates/base.html index 3e64059..d44cadd 100644 --- a/schickmacher/templates/base.html +++ b/schickmacher/templates/base.html @@ -49,6 +49,12 @@ + + {% if request.user.is_authenticated %}