diff --git a/schickmacher/renderer/forms.py b/schickmacher/renderer/forms.py index 4817a29..077259f 100644 --- a/schickmacher/renderer/forms.py +++ b/schickmacher/renderer/forms.py @@ -6,6 +6,7 @@ from markdownx.fields import MarkdownxFormField class RendererForm(forms.Form): title = forms.CharField(label=_('Title'), required=False) + show_title = forms.BooleanField(label=_('Show Title'), required=False) date = forms.DateField(label=_('Date'), initial=lambda: timezone.now().strftime('%Y-%m-%d'), widget=forms.TextInput( @@ -14,3 +15,7 @@ class RendererForm(forms.Form): render_content = MarkdownxFormField( label=_('Content'), ) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['show_title'].initial = True diff --git a/schickmacher/renderer/tests/test_views.py b/schickmacher/renderer/tests/test_views.py index 6860527..a07428e 100644 --- a/schickmacher/renderer/tests/test_views.py +++ b/schickmacher/renderer/tests/test_views.py @@ -24,3 +24,23 @@ class TestRendererFormView: assert b'Example' in response.content assert response.content.startswith(b'%PDF') + def test_html_render(self, client: Client): + response = client.post('/renderer/renderhtml', data={ + 'title': 'Sample Title', + 'date': '2009-11-15', + 'render_content': '# Example', + 'show_title': 'on', + }) + assert b'Sample Title' in response.content + assert b'

Sample Title

' in response.content + assert b'Example' in response.content + + def test_hiding_title(self, client: Client): + response = client.post('/renderer/renderhtml', data={ + 'title': 'Sample Title', + 'date': '2009-11-15', + 'render_content': '# Example' + }) + assert b'Sample Title' in response.content + assert b'

Sample Title

' not in response.content + assert b'Example' in response.content diff --git a/schickmacher/renderer/views.py b/schickmacher/renderer/views.py index b0b34ea..acf7154 100644 --- a/schickmacher/renderer/views.py +++ b/schickmacher/renderer/views.py @@ -21,6 +21,7 @@ class HtmlRenderView(TemplateView): if form.is_valid(): return { 'date': form.cleaned_data['date'], + 'show_title': form.cleaned_data['show_title'], 'content': markdownify(form.cleaned_data['render_content']), 'title': form.cleaned_data['title'] } diff --git a/schickmacher/templates/renderer/rendered.html b/schickmacher/templates/renderer/rendered.html index 29b7775..2ca154b 100644 --- a/schickmacher/templates/renderer/rendered.html +++ b/schickmacher/templates/renderer/rendered.html @@ -25,9 +25,11 @@
+ {% if show_title %}

{{ title }}

+ {% endif %}
{{ content | safe }}