2017-05-30 20:44:30 +02:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
from wagtail.wagtailadmin.edit_handlers import (
|
|
|
|
FieldPanel, FieldRowPanel, MultiFieldPanel, StreamFieldPanel
|
|
|
|
)
|
|
|
|
from wagtail.wagtailcore import blocks
|
|
|
|
from wagtail.wagtailcore.fields import StreamField
|
|
|
|
from wagtail.wagtailcore.models import Page
|
2017-05-30 20:44:30 +02:00
|
|
|
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
|
2017-06-12 01:51:10 +02:00
|
|
|
from wagtail.wagtailsnippets.blocks import SnippetChooserBlock
|
2017-05-30 20:44:30 +02:00
|
|
|
from wagtail.wagtailsnippets.models import register_snippet
|
|
|
|
|
2017-10-16 00:07:30 +02:00
|
|
|
from .utils import get_page_model_names
|
2017-05-30 20:44:30 +02:00
|
|
|
|
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
@register_snippet
|
|
|
|
class MemberTeam(models.Model):
|
|
|
|
first_name = models.CharField(
|
|
|
|
verbose_name=_('Prénom'),
|
|
|
|
blank=True, default='', max_length=255,
|
2017-05-30 20:44:30 +02:00
|
|
|
)
|
2017-06-12 01:51:10 +02:00
|
|
|
last_name = models.CharField(
|
|
|
|
verbose_name=_('Nom'),
|
|
|
|
blank=True, default='', max_length=255,
|
|
|
|
)
|
|
|
|
nick_name = models.CharField(
|
|
|
|
verbose_name=_('Alias'),
|
|
|
|
blank=True, default='', max_length=255,
|
|
|
|
)
|
|
|
|
photo = models.ForeignKey(
|
|
|
|
'wagtailimages.Image',
|
|
|
|
verbose_name=_('Photo'),
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
null=True, blank=True,
|
|
|
|
related_name='+',
|
2017-05-30 20:44:30 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2017-06-12 01:51:10 +02:00
|
|
|
verbose_name = _('K-Fêt-eux-se')
|
2017-05-30 20:44:30 +02:00
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
panels = [
|
|
|
|
FieldPanel('first_name'),
|
|
|
|
FieldPanel('last_name'),
|
|
|
|
FieldPanel('nick_name'),
|
|
|
|
ImageChooserPanel('photo'),
|
|
|
|
]
|
2017-05-30 20:44:30 +02:00
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
def __str__(self):
|
|
|
|
return self.get_full_name()
|
2017-05-30 20:44:30 +02:00
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
def get_full_name(self):
|
|
|
|
return '{} {}'.format(self.first_name, self.last_name).strip()
|
2017-05-30 20:44:30 +02:00
|
|
|
|
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
class MenuBlock(blocks.StaticBlock):
|
|
|
|
class Meta:
|
|
|
|
icon = 'list-ul'
|
|
|
|
label = _('Carte')
|
|
|
|
template = 'kfetcms/block_menu.html'
|
2017-05-30 20:44:30 +02:00
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
def get_context(self, *args, **kwargs):
|
2017-10-16 00:07:30 +02:00
|
|
|
from .context_processors import get_articles
|
2017-06-12 01:51:10 +02:00
|
|
|
context = super().get_context(*args, **kwargs)
|
|
|
|
context.update(get_articles())
|
2017-05-30 20:44:30 +02:00
|
|
|
return context
|
|
|
|
|
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
class GroupTeamBlock(blocks.StructBlock):
|
|
|
|
show_only = blocks.IntegerBlock(
|
|
|
|
label=_('Montrer seulement'),
|
|
|
|
required=False,
|
2017-05-30 20:44:30 +02:00
|
|
|
help_text=_(
|
2017-06-12 01:51:10 +02:00
|
|
|
'Nombre initial de membres affichés. Laisser vide pour tou-te-s '
|
|
|
|
'les afficher.'
|
2017-05-30 20:44:30 +02:00
|
|
|
),
|
|
|
|
)
|
2017-06-12 01:51:10 +02:00
|
|
|
members = blocks.ListBlock(
|
|
|
|
SnippetChooserBlock(MemberTeam),
|
|
|
|
label=_('K-Fêt-eux-ses'),
|
|
|
|
classname='team-group',
|
|
|
|
)
|
2017-05-30 20:44:30 +02:00
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
class Meta:
|
|
|
|
icon = 'group'
|
|
|
|
label = _('Groupe de K-Fêt-eux-ses')
|
|
|
|
template = 'kfetcms/block_teamgroup.html'
|
2017-05-30 20:44:30 +02:00
|
|
|
|
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
class ChoicesStreamBlock(blocks.StreamBlock):
|
|
|
|
rich = blocks.RichTextBlock(label=_('Éditeur'))
|
|
|
|
carte = MenuBlock()
|
|
|
|
group_team = GroupTeamBlock()
|
2017-05-30 20:44:30 +02:00
|
|
|
|
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
class KFetStreamBlock(ChoicesStreamBlock):
|
|
|
|
group = ChoicesStreamBlock(label=_('Contenu groupé'))
|
2017-05-30 20:44:30 +02:00
|
|
|
|
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
class KFetPage(Page):
|
2017-05-30 20:44:30 +02:00
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
content = StreamField(KFetStreamBlock, verbose_name=_('Contenu'))
|
|
|
|
|
|
|
|
# Layout fields
|
|
|
|
|
|
|
|
TEMPLATE_COL_1 = 'kfet/base_col_1.html'
|
|
|
|
TEMPLATE_COL_2 = 'kfet/base_col_2.html'
|
|
|
|
TEMPLATE_COL_MULT = 'kfet/base_col_mult.html'
|
|
|
|
|
|
|
|
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é."
|
|
|
|
),
|
2017-05-30 20:44:30 +02:00
|
|
|
)
|
2017-06-12 01:51:10 +02:00
|
|
|
layout = models.CharField(
|
|
|
|
verbose_name=_('Template'),
|
|
|
|
choices=[
|
|
|
|
(TEMPLATE_COL_1, _('Une colonne : centrée sur la page')),
|
|
|
|
(TEMPLATE_COL_2, _('Deux colonnes : fixe à gauche, contenu à droite')),
|
|
|
|
(TEMPLATE_COL_MULT, _('Contenu scindé sur plusieurs colonnes')),
|
|
|
|
],
|
|
|
|
default=TEMPLATE_COL_MULT, max_length=255,
|
|
|
|
help_text=_(
|
|
|
|
"Comment cette page devrait être affichée ?"
|
|
|
|
),
|
2017-05-30 20:44:30 +02:00
|
|
|
)
|
2017-06-12 01:51:10 +02:00
|
|
|
main_size = models.CharField(
|
|
|
|
verbose_name=_('Taille de la colonne de contenu'),
|
|
|
|
blank=True, max_length=255,
|
2017-05-30 20:44:30 +02:00
|
|
|
)
|
2017-06-12 01:51:10 +02:00
|
|
|
col_count = models.CharField(
|
|
|
|
verbose_name=_('Nombre de colonnes'),
|
|
|
|
blank=True, max_length=255,
|
|
|
|
help_text=_(
|
|
|
|
"S'applique au page dont le contenu est scindé sur plusieurs colonnes."
|
|
|
|
),
|
2017-05-30 20:44:30 +02:00
|
|
|
)
|
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
# Panels
|
2017-05-30 20:44:30 +02:00
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
content_panels = Page.content_panels + [
|
|
|
|
StreamFieldPanel('content'),
|
|
|
|
]
|
2017-05-30 20:44:30 +02:00
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
layout_panel = [
|
|
|
|
FieldPanel('no_header'),
|
|
|
|
FieldPanel('layout'),
|
|
|
|
FieldRowPanel([
|
|
|
|
FieldPanel('main_size'),
|
|
|
|
FieldPanel('col_count'),
|
|
|
|
]),
|
2017-05-30 20:44:30 +02:00
|
|
|
]
|
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
settings_panels = [
|
|
|
|
MultiFieldPanel(layout_panel, _('Affichage'))
|
|
|
|
] + Page.settings_panels
|
|
|
|
|
|
|
|
# Base template
|
|
|
|
template = "kfetcms/base.html"
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _('page K-Fêt')
|
|
|
|
verbose_name_plural = _('pages K-Fêt')
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
return context
|
2017-10-16 00:07:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
# Helpers for kfetauth app
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
class CmsPermissionManager(models.Manager):
|
|
|
|
def get_queryset(self):
|
|
|
|
return (
|
|
|
|
super().get_queryset()
|
|
|
|
.filter(content_type__app_label='kfetcms')
|
|
|
|
# Permissions of Page-based models are unused.
|
|
|
|
.exclude(content_type__model__in=get_page_model_names())
|
|
|
|
)
|