Use Markdown for presentation texts all around
This commit is contained in:
parent
c9b1ccc5c9
commit
3fbd7b5859
11 changed files with 86 additions and 19 deletions
|
@ -28,6 +28,7 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'solo',
|
'solo',
|
||||||
|
'markdownx',
|
||||||
'mainsite',
|
'mainsite',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,11 @@ from django.conf.urls import url, include
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
import mainsite.urls
|
import mainsite.urls
|
||||||
|
import markdownx.urls
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^admin/', admin.site.urls),
|
url(r'^admin/', admin.site.urls),
|
||||||
|
url(r'^markdownx/', include(markdownx.urls)),
|
||||||
url(r'^', include(mainsite.urls.urlpatterns)),
|
url(r'^', include(mainsite.urls.urlpatterns)),
|
||||||
]
|
]
|
||||||
|
|
31
mainsite/migrations/0006_auto_20170923_1847.py
Normal file
31
mainsite/migrations/0006_auto_20170923_1847.py
Normal file
|
@ -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)'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -2,16 +2,16 @@ from django.db import models
|
||||||
from django.db.models import DateField, \
|
from django.db.models import DateField, \
|
||||||
CharField, \
|
CharField, \
|
||||||
BooleanField, \
|
BooleanField, \
|
||||||
IntegerField, \
|
IntegerField
|
||||||
TextField
|
|
||||||
from solo.models import SingletonModel
|
from solo.models import SingletonModel
|
||||||
|
from markdownx.models import MarkdownxField
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
class SiteConfiguration(SingletonModel):
|
class SiteConfiguration(SingletonModel):
|
||||||
homepageText = TextField("Texte de la page d'accueil (HTML)")
|
homepageText = MarkdownxField("Texte de la page d'accueil (Markdown)")
|
||||||
writearticleText = TextField("Texte de la page « écrire » (HTML)")
|
writearticleText = MarkdownxField("Texte de la page « écrire » (Markdown)")
|
||||||
email = CharField("Adresse de contact du BOcal",
|
email = CharField("Adresse de contact du BOcal",
|
||||||
max_length=128,
|
max_length=128,
|
||||||
help_text="Attention au spam…")
|
help_text="Attention au spam…")
|
||||||
|
@ -60,7 +60,7 @@ class PublicationYear(models.Model):
|
||||||
startYear = IntegerField('Année de début',
|
startYear = IntegerField('Année de début',
|
||||||
help_text='Année scolaire à partir du 1/08',
|
help_text='Année scolaire à partir du 1/08',
|
||||||
primary_key=True)
|
primary_key=True)
|
||||||
descr = TextField('Accroche de l\'année')
|
descr = MarkdownxField("Accroche de l'année (Markdown)")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{}-{}'.format(self.startYear, self.startYear+1)
|
return '{}-{}'.format(self.startYear, self.startYear+1)
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load solo_tags %}
|
{% load solo_tags %}
|
||||||
|
{% load markdown_tags %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% get_solo 'mainsite.SiteConfiguration' as site_config %}
|
{% get_solo 'mainsite.SiteConfiguration' as site_config %}
|
||||||
|
|
||||||
{{ site_config.homepageText | safe }}
|
{{ site_config.homepageText | markdownify }}
|
||||||
|
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
{% load markdown_tags %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
<p class="intro_text">{{ intro_text | markdownify }}</p>
|
||||||
|
|
||||||
{% for bocal in publications %}
|
{% for bocal in publications %}
|
||||||
<ul class="publication-list">
|
<ul class="publication-list">
|
||||||
<li class="publication-entry">
|
<li class="publication-entry">
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load solo_tags %}
|
{% load solo_tags %}
|
||||||
|
{% load markdown_tags %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% get_solo 'mainsite.SiteConfiguration' as site_config %}
|
{% get_solo 'mainsite.SiteConfiguration' as site_config %}
|
||||||
|
|
||||||
{{ site_config.writearticleText | safe }}
|
{{ site_config.writearticleText | markdownify }}
|
||||||
|
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
0
mainsite/templatetags/__init__.py
Normal file
0
mainsite/templatetags/__init__.py
Normal file
15
mainsite/templatetags/markdown_tags.py
Normal file
15
mainsite/templatetags/markdown_tags.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
from django import template
|
||||||
|
from django.template.defaultfilters import stringfilter
|
||||||
|
from django.utils.html import conditional_escape
|
||||||
|
from django.utils.safestring import mark_safe
|
||||||
|
from markdownx import utils
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter(needs_autoescape=True)
|
||||||
|
@stringfilter
|
||||||
|
def markdownify(v, autoescape=True):
|
||||||
|
esc = conditional_escape if autoescape else (lambda x: x)
|
||||||
|
result = utils.markdownify(esc(v))
|
||||||
|
return mark_safe(result)
|
|
@ -1,11 +1,8 @@
|
||||||
# from django.shortcuts import render
|
from django.shortcuts import get_object_or_404
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.db.models import Q
|
|
||||||
|
|
||||||
from datetime import date
|
from mainsite.models import Publication, PublicationYear
|
||||||
|
|
||||||
from mainsite.models import Publication
|
|
||||||
|
|
||||||
|
|
||||||
class HomeView(TemplateView):
|
class HomeView(TemplateView):
|
||||||
|
@ -26,8 +23,15 @@ class PublicationListView(TemplateView):
|
||||||
|
|
||||||
template_name = 'mainsite/publications_list_view.html'
|
template_name = 'mainsite/publications_list_view.html'
|
||||||
|
|
||||||
|
def initView(self):
|
||||||
|
''' Cannot be __init__, we don't have **kwargs there '''
|
||||||
|
pass
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
self.initView(**kwargs)
|
||||||
|
|
||||||
context = super(PublicationListView, self).get_context_data(**kwargs)
|
context = super(PublicationListView, self).get_context_data(**kwargs)
|
||||||
|
context.update(self.additional_context(**kwargs))
|
||||||
|
|
||||||
publications = self.get_publications(**kwargs)
|
publications = self.get_publications(**kwargs)
|
||||||
|
|
||||||
|
@ -40,21 +44,25 @@ class PublicationListView(TemplateView):
|
||||||
|
|
||||||
class YearView(PublicationListView):
|
class YearView(PublicationListView):
|
||||||
''' Display a year worth of BOcals '''
|
''' Display a year worth of BOcals '''
|
||||||
def get_publications(self, year, nYear):
|
|
||||||
|
def initView(self, year, nYear):
|
||||||
try:
|
try:
|
||||||
year, nYear = int(year), int(nYear)
|
year, nYear = int(year), int(nYear)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise Http404
|
raise Http404
|
||||||
|
|
||||||
if year + 1 != nYear:
|
if year + 1 != nYear:
|
||||||
raise Http404
|
raise Http404
|
||||||
|
self.year = year
|
||||||
|
|
||||||
publications = Publication.objects.filter(
|
self.pubYear = get_object_or_404(PublicationYear, startYear=year)
|
||||||
Q(is_special=False) | Q(in_year_view_anyway=True),
|
|
||||||
date__gte=date(year, 8, 1),
|
|
||||||
date__lt=date(nYear, 8, 1))
|
|
||||||
|
|
||||||
return publications
|
def additional_context(self, year, nYear):
|
||||||
|
return {
|
||||||
|
'intro_text': self.pubYear.descr,
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_publications(self, year, nYear):
|
||||||
|
return self.pubYear.publis()
|
||||||
|
|
||||||
|
|
||||||
class SpecialPublicationsView(PublicationListView):
|
class SpecialPublicationsView(PublicationListView):
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
Django==1.11.5
|
Django==1.11.5
|
||||||
|
django-markdownx==2.0.21
|
||||||
django-solo==1.1.2
|
django-solo==1.1.2
|
||||||
|
Markdown==2.6.9
|
||||||
|
olefile==0.44
|
||||||
|
Pillow==4.2.1
|
||||||
pytz==2017.2
|
pytz==2017.2
|
||||||
|
|
Loading…
Reference in a new issue