forked from DGNum/gestioCOF
K-Fêt - Integrate wagtail to serve "static" pages of old K-Fêt website - Fixture "kfetcms/kfet_wagtail_17_05" contains a copy of old website (as in May 2017). - Media files can be got until end of June 17 at http://partage.eleves.ens.fr//files/604e6dea2ceebc66b1936c6b3f911744/kfet_media.tar.gz Login/logout - Update package django_cas_ng to last version. - Clean COFCASBackend. - Change CAS version to 3 (version used on eleves.ens). This enables the logout redirection (for CAS ofc). - Add messages and clean existing ones on login/logout (for both outsider and cas users). Misc - Update settings to bypass an incompability between debug-toolbar and wagtailmenus packages. - Better management of dev/test-specific urls (if debug-toolbar wasn't in INSTALLED_APPS, media files were not served). - UI improvements.
166 lines
4.6 KiB
Python
166 lines
4.6 KiB
Python
from django.db import models
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from modelcluster.models import ClusterableModel, ParentalKey
|
|
from wagtail.wagtailadmin.edit_handlers import FieldPanel, InlinePanel
|
|
from wagtail.wagtailcore.fields import RichTextField
|
|
from wagtail.wagtailcore.models import Orderable, Page
|
|
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
|
|
from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel
|
|
from wagtail.wagtailsnippets.models import register_snippet
|
|
|
|
from kfet.cms.context_processors import get_articles
|
|
|
|
|
|
class KFetPage(Page):
|
|
no_header = models.BooleanField(
|
|
verbose_name=_('Sans en-tête'),
|
|
default=False,
|
|
help_text=_(
|
|
"Coché, l'en-tête (avec le titre) de la page n'est pas affiché."
|
|
),
|
|
)
|
|
content = RichTextField(verbose_name=_('Contenu'))
|
|
custom_template = models.CharField(
|
|
verbose_name=_('Template personnalisé'),
|
|
max_length=255,
|
|
blank=True,
|
|
)
|
|
|
|
content_panels = Page.content_panels + [
|
|
FieldPanel('no_header'),
|
|
FieldPanel('content', classname='full'),
|
|
InlinePanel('team_groups', label=_("Groupes de K-Fêt-eux-ses")),
|
|
]
|
|
|
|
settings_panels = Page.settings_panels + [
|
|
FieldPanel('custom_template'),
|
|
]
|
|
|
|
class Meta:
|
|
verbose_name = _('page K-Fêt')
|
|
verbose_name_plural = _('pages K-Fêt')
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.template = "kfetcms/base.html"
|
|
|
|
def get_context(self, request, *args, **kwargs):
|
|
context = super().get_context(request, *args, **kwargs)
|
|
|
|
page = context['page']
|
|
|
|
if not page.seo_title:
|
|
page.seo_title = page.title
|
|
|
|
if self.slug == "carte":
|
|
context.update(get_articles(request))
|
|
|
|
return context
|
|
|
|
def get_template(self, request, *args, **kwargs):
|
|
return self.custom_template or (
|
|
super().get_template(request, *args, **kwargs))
|
|
|
|
|
|
class KFetPageGroupTeam(Orderable, models.Model):
|
|
page = ParentalKey(KFetPage, related_name='team_groups')
|
|
group = models.ForeignKey(
|
|
'kfetcms.GroupTeam',
|
|
verbose_name=_('Groupe de K-Fêt-eux-ses'),
|
|
related_name='+',
|
|
)
|
|
title = models.CharField(
|
|
verbose_name=_('Titre du groupe'),
|
|
max_length=255,
|
|
blank=True,
|
|
)
|
|
content = RichTextField(
|
|
verbose_name=_('Texte de présentation du groupe'),
|
|
)
|
|
show_only = models.IntegerField(
|
|
verbose_name=_('Montrer seulement'),
|
|
blank=True, null=True, default=None,
|
|
help_text=_(
|
|
'Nombre de membres du groupe affichés initialement. Laisser vide '
|
|
'pour tou-te-s les afficher.'
|
|
),
|
|
)
|
|
|
|
panels = [
|
|
FieldPanel('title', classname='full'),
|
|
FieldPanel('show_only', classname='full'),
|
|
FieldPanel('content', classname='full'),
|
|
SnippetChooserPanel('group'),
|
|
]
|
|
|
|
|
|
@register_snippet
|
|
class GroupTeam(ClusterableModel):
|
|
name = models.CharField(
|
|
verbose_name=_('Nom'),
|
|
max_length=255,
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name = _('Groupe de K-Fêt-eux-ses')
|
|
verbose_name_plural = _('Groupes de K-Fêt-eux-ses')
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
panels = [
|
|
FieldPanel('name', classname='full'),
|
|
InlinePanel('members', label=_('Membres du groupe')),
|
|
]
|
|
|
|
|
|
@register_snippet
|
|
class MemberTeam(Orderable, models.Model):
|
|
group = ParentalKey(
|
|
GroupTeam,
|
|
verbose_name=_("Groupe de K-Fêt-eux-ses"),
|
|
on_delete=models.CASCADE,
|
|
related_name='members',
|
|
)
|
|
first_name = models.CharField(
|
|
verbose_name=_('Prénom'),
|
|
max_length=255,
|
|
blank=True, default='',
|
|
)
|
|
last_name = models.CharField(
|
|
verbose_name=_('Nom'),
|
|
max_length=255,
|
|
blank=True, default='',
|
|
)
|
|
nick_name = models.CharField(
|
|
verbose_name=_('Alias'),
|
|
max_length=255,
|
|
blank=True, default='',
|
|
)
|
|
photo = models.ForeignKey(
|
|
'wagtailimages.Image',
|
|
verbose_name=_('Photo'),
|
|
on_delete=models.SET_NULL,
|
|
null=True, blank=True,
|
|
related_name='+',
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name = _('K-Fêt-eux-se')
|
|
|
|
def __str__(self):
|
|
return self.get_full_name()
|
|
|
|
panels = [
|
|
FieldPanel('first_name'),
|
|
FieldPanel('last_name'),
|
|
FieldPanel('nick_name'),
|
|
FieldPanel('group'),
|
|
ImageChooserPanel('photo'),
|
|
]
|
|
|
|
def get_full_name(self):
|
|
full_name = '{} {}'.format(self.first_name, self.last_name)
|
|
return full_name.strip()
|