Add a checkbox to disable the title
This commit is contained in:
parent
44d168e332
commit
7d4425831f
4 changed files with 28 additions and 0 deletions
|
@ -6,6 +6,7 @@ from markdownx.fields import MarkdownxFormField
|
||||||
|
|
||||||
class RendererForm(forms.Form):
|
class RendererForm(forms.Form):
|
||||||
title = forms.CharField(label=_('Title'), required=False)
|
title = forms.CharField(label=_('Title'), required=False)
|
||||||
|
show_title = forms.BooleanField(label=_('Show Title'), required=False)
|
||||||
date = forms.DateField(label=_('Date'),
|
date = forms.DateField(label=_('Date'),
|
||||||
initial=lambda: timezone.now().strftime('%Y-%m-%d'),
|
initial=lambda: timezone.now().strftime('%Y-%m-%d'),
|
||||||
widget=forms.TextInput(
|
widget=forms.TextInput(
|
||||||
|
@ -14,3 +15,7 @@ class RendererForm(forms.Form):
|
||||||
render_content = MarkdownxFormField(
|
render_content = MarkdownxFormField(
|
||||||
label=_('Content'),
|
label=_('Content'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.fields['show_title'].initial = True
|
||||||
|
|
|
@ -24,3 +24,23 @@ class TestRendererFormView:
|
||||||
assert b'Example' in response.content
|
assert b'Example' in response.content
|
||||||
assert response.content.startswith(b'%PDF')
|
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'<h1>Sample Title</h1>' 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'<h1>Sample Title</h1>' not in response.content
|
||||||
|
assert b'Example' in response.content
|
||||||
|
|
|
@ -21,6 +21,7 @@ class HtmlRenderView(TemplateView):
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
return {
|
return {
|
||||||
'date': form.cleaned_data['date'],
|
'date': form.cleaned_data['date'],
|
||||||
|
'show_title': form.cleaned_data['show_title'],
|
||||||
'content': markdownify(form.cleaned_data['render_content']),
|
'content': markdownify(form.cleaned_data['render_content']),
|
||||||
'title': form.cleaned_data['title']
|
'title': form.cleaned_data['title']
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,11 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
{% if show_title %}
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<h1>{{ title }}</h1>
|
<h1>{{ title }}</h1>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
<div class="document">
|
<div class="document">
|
||||||
{{ content | safe }}
|
{{ content | safe }}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue