2017-09-21 10:58:19 +02:00
|
|
|
|
from django.db import models
|
2017-09-21 19:58:42 +02:00
|
|
|
|
from django.db.models import DateField, \
|
2017-09-21 11:34:40 +02:00
|
|
|
|
CharField, \
|
2017-09-22 15:15:05 +02:00
|
|
|
|
BooleanField, \
|
2017-09-23 18:48:29 +02:00
|
|
|
|
IntegerField
|
2017-09-22 18:07:38 +02:00
|
|
|
|
from solo.models import SingletonModel
|
2017-09-23 18:48:29 +02:00
|
|
|
|
from markdownx.models import MarkdownxField
|
2017-09-22 15:15:05 +02:00
|
|
|
|
|
|
|
|
|
import datetime
|
2017-09-21 10:58:19 +02:00
|
|
|
|
|
2017-09-21 11:34:40 +02:00
|
|
|
|
|
2017-09-22 18:07:38 +02:00
|
|
|
|
class SiteConfiguration(SingletonModel):
|
2017-09-23 18:48:29 +02:00
|
|
|
|
homepageText = MarkdownxField("Texte de la page d'accueil (Markdown)")
|
|
|
|
|
writearticleText = MarkdownxField("Texte de la page « écrire » (Markdown)")
|
2017-09-22 18:07:38 +02:00
|
|
|
|
email = CharField("Adresse de contact du BOcal",
|
|
|
|
|
max_length=128,
|
|
|
|
|
help_text="Attention au spam…")
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
return "Configuration du site"
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
verbose_name = "Configuration du site"
|
|
|
|
|
|
|
|
|
|
|
2017-09-21 11:34:40 +02:00
|
|
|
|
class Publication(models.Model):
|
|
|
|
|
num = CharField('Numéro du BOcal', max_length=128)
|
2017-09-21 19:58:42 +02:00
|
|
|
|
url = CharField('Adresse sur le site', max_length=512)
|
|
|
|
|
# ^ This is not a URLField because we need internal URLS, eg `/static/blah`
|
|
|
|
|
|
2017-09-21 11:34:40 +02:00
|
|
|
|
date = DateField('Publication')
|
|
|
|
|
is_special = BooleanField('Numéro spécial',
|
|
|
|
|
help_text='Numéro du BOcal non-numéroté',
|
|
|
|
|
default=False)
|
2017-09-22 19:03:43 +02:00
|
|
|
|
in_year_view_anyway = BooleanField(
|
|
|
|
|
"Aussi dans l'année",
|
|
|
|
|
help_text=("Si le numéro est spécial, l'afficher quand même dans la "
|
|
|
|
|
"page de l'année correspondante."),
|
|
|
|
|
default=False)
|
2017-09-21 11:34:40 +02:00
|
|
|
|
descr = CharField('Description (optionnelle)',
|
2017-09-21 19:58:42 +02:00
|
|
|
|
max_length=512,
|
|
|
|
|
blank=True)
|
2017-09-21 11:34:40 +02:00
|
|
|
|
custom_name = CharField('Nom customisé',
|
|
|
|
|
help_text='Vide pour laisser le numéro seulement',
|
2017-09-21 19:58:42 +02:00
|
|
|
|
max_length=128,
|
|
|
|
|
blank=True)
|
2017-09-21 11:34:40 +02:00
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
if self.custom_name:
|
|
|
|
|
return self.custom_name
|
2017-09-23 16:34:37 +02:00
|
|
|
|
elif self.is_special:
|
|
|
|
|
return self.num
|
2017-09-21 11:34:40 +02:00
|
|
|
|
return 'BOcal n°{}'.format(self.num)
|
2017-09-21 20:21:35 +02:00
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
ordering = ['date']
|
2017-09-22 15:15:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PublicationYear(models.Model):
|
|
|
|
|
startYear = IntegerField('Année de début',
|
|
|
|
|
help_text='Année scolaire à partir du 1/08',
|
|
|
|
|
primary_key=True)
|
2017-09-23 18:48:29 +02:00
|
|
|
|
descr = MarkdownxField("Accroche de l'année (Markdown)")
|
2017-09-22 15:15:05 +02:00
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
return '{}-{}'.format(self.startYear, self.startYear+1)
|
|
|
|
|
|
|
|
|
|
def beg(self):
|
|
|
|
|
''' First day of this publication year (incl.) '''
|
|
|
|
|
return datetime.date(self.startYear, 8, 1)
|
|
|
|
|
|
|
|
|
|
def end(self):
|
|
|
|
|
''' Last day of this publication year (excl.) '''
|
|
|
|
|
return datetime.date(self.startYear + 1, 8, 1)
|
|
|
|
|
|
|
|
|
|
def inYear(self, date):
|
|
|
|
|
return self.beg() <= date < self.end()
|
|
|
|
|
|
|
|
|
|
def publis(self):
|
|
|
|
|
''' List of publications from this year '''
|
|
|
|
|
return Publication.objects.filter(
|
|
|
|
|
date__gte=self.beg(),
|
|
|
|
|
date__lt=self.end())
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def url(self):
|
|
|
|
|
return '/{}/'.format(self)
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def prettyName(self):
|
|
|
|
|
return '{} – {}'.format(self.startYear, self.startYear+1)
|
2017-09-22 19:16:41 +02:00
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
ordering = ['-startYear']
|