Views with example content

This commit is contained in:
Jens Kadenbach 2019-09-12 14:27:39 +02:00
parent 74869da4bc
commit 3c3456431a
3 changed files with 31 additions and 2 deletions

View file

@ -1,10 +1,13 @@
from django.urls import path 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' 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"), path("renderhtml", view=HtmlRenderView.as_view(), name="renderhtml"),
path("samplehtml", view=SampleHTMLView.as_view(), name="samplehtml"),
path("samplepdf", view=SamplePDFView.as_view(), name="samplepdf"),
] ]

View file

@ -1,7 +1,8 @@
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, TemplateView from django.views.generic import TemplateView
from django_weasyprint import WeasyTemplateView from django_weasyprint import WeasyTemplateView
from django.utils.timezone import datetime
from markdownx.utils import markdownify from markdownx.utils import markdownify
from schickmacher.renderer.forms import RendererForm from schickmacher.renderer.forms import RendererForm
@ -36,3 +37,22 @@ class HtmlRenderView(TemplateView):
class RenderView(HtmlRenderView, WeasyTemplateView): class RenderView(HtmlRenderView, WeasyTemplateView):
pass 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

View file

@ -49,6 +49,12 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{% url 'renderer:form' %}">Renderer</a> <a class="nav-link" href="{% url 'renderer:form' %}">Renderer</a>
</li> </li>
<li class="nav-item">
<a class="nav-link" href="{% url 'renderer:samplehtml' %}">Example HTML</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'renderer:samplepdf' %}">Example PDF</a>
</li>
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
<li class="nav-item"> <li class="nav-item">
{# URL provided by django-allauth/account/urls.py #} {# URL provided by django-allauth/account/urls.py #}