From 3fbd7b58597b3bb92ddd5b5d087c304807fbd374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Sat, 23 Sep 2017 18:48:29 +0200 Subject: [PATCH] Use Markdown for presentation texts all around --- bocal/settings_base.py | 1 + bocal/urls.py | 2 ++ .../migrations/0006_auto_20170923_1847.py | 31 ++++++++++++++++++ mainsite/models.py | 10 +++--- mainsite/templates/mainsite/homepage.html | 3 +- .../mainsite/publications_list_view.html | 4 +++ .../templates/mainsite/write_article.html | 3 +- mainsite/templatetags/__init__.py | 0 mainsite/templatetags/markdown_tags.py | 15 +++++++++ mainsite/views.py | 32 ++++++++++++------- requirements.txt | 4 +++ 11 files changed, 86 insertions(+), 19 deletions(-) create mode 100644 mainsite/migrations/0006_auto_20170923_1847.py create mode 100644 mainsite/templatetags/__init__.py create mode 100644 mainsite/templatetags/markdown_tags.py diff --git a/bocal/settings_base.py b/bocal/settings_base.py index d779de1..c2cd606 100644 --- a/bocal/settings_base.py +++ b/bocal/settings_base.py @@ -28,6 +28,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'solo', + 'markdownx', 'mainsite', ] diff --git a/bocal/urls.py b/bocal/urls.py index b7ac9a7..daf78be 100644 --- a/bocal/urls.py +++ b/bocal/urls.py @@ -17,9 +17,11 @@ from django.conf.urls import url, include from django.contrib import admin import mainsite.urls +import markdownx.urls urlpatterns = [ url(r'^admin/', admin.site.urls), + url(r'^markdownx/', include(markdownx.urls)), url(r'^', include(mainsite.urls.urlpatterns)), ] diff --git a/mainsite/migrations/0006_auto_20170923_1847.py b/mainsite/migrations/0006_auto_20170923_1847.py new file mode 100644 index 0000000..ca36df8 --- /dev/null +++ b/mainsite/migrations/0006_auto_20170923_1847.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.5 on 2017-09-23 16:47 +from __future__ import unicode_literals + +from django.db import migrations +import markdownx.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('mainsite', '0005_auto_20170922_1916'), + ] + + operations = [ + migrations.AlterField( + model_name='publicationyear', + name='descr', + field=markdownx.models.MarkdownxField(verbose_name="Accroche de l'année (Markdown)"), + ), + migrations.AlterField( + model_name='siteconfiguration', + name='homepageText', + field=markdownx.models.MarkdownxField(verbose_name="Texte de la page d'accueil (Markdown)"), + ), + migrations.AlterField( + model_name='siteconfiguration', + name='writearticleText', + field=markdownx.models.MarkdownxField(verbose_name='Texte de la page « écrire » (Markdown)'), + ), + ] diff --git a/mainsite/models.py b/mainsite/models.py index 809e224..c1bb545 100644 --- a/mainsite/models.py +++ b/mainsite/models.py @@ -2,16 +2,16 @@ from django.db import models from django.db.models import DateField, \ CharField, \ BooleanField, \ - IntegerField, \ - TextField + IntegerField from solo.models import SingletonModel +from markdownx.models import MarkdownxField import datetime class SiteConfiguration(SingletonModel): - homepageText = TextField("Texte de la page d'accueil (HTML)") - writearticleText = TextField("Texte de la page « écrire » (HTML)") + homepageText = MarkdownxField("Texte de la page d'accueil (Markdown)") + writearticleText = MarkdownxField("Texte de la page « écrire » (Markdown)") email = CharField("Adresse de contact du BOcal", max_length=128, help_text="Attention au spam…") @@ -60,7 +60,7 @@ class PublicationYear(models.Model): startYear = IntegerField('Année de début', help_text='Année scolaire à partir du 1/08', primary_key=True) - descr = TextField('Accroche de l\'année') + descr = MarkdownxField("Accroche de l'année (Markdown)") def __str__(self): return '{}-{}'.format(self.startYear, self.startYear+1) diff --git a/mainsite/templates/mainsite/homepage.html b/mainsite/templates/mainsite/homepage.html index 3846231..b993339 100644 --- a/mainsite/templates/mainsite/homepage.html +++ b/mainsite/templates/mainsite/homepage.html @@ -1,9 +1,10 @@ {% extends "base.html" %} {% load solo_tags %} +{% load markdown_tags %} {% block content %} {% get_solo 'mainsite.SiteConfiguration' as site_config %} -{{ site_config.homepageText | safe }} +{{ site_config.homepageText | markdownify }} {% endblock content %} diff --git a/mainsite/templates/mainsite/publications_list_view.html b/mainsite/templates/mainsite/publications_list_view.html index 3c4a06d..956fe88 100644 --- a/mainsite/templates/mainsite/publications_list_view.html +++ b/mainsite/templates/mainsite/publications_list_view.html @@ -1,6 +1,10 @@ {% extends "base.html" %} +{% load markdown_tags %} {% block content %} + +

{{ intro_text | markdownify }}

+ {% for bocal in publications %}