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 (
|
2018-10-06 12:35:49 +02:00
|
|
|
FieldPanel,
|
|
|
|
FieldRowPanel,
|
|
|
|
MultiFieldPanel,
|
|
|
|
StreamFieldPanel,
|
2017-06-12 01:51:10 +02:00
|
|
|
)
|
|
|
|
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
|
|
|
|
|
|
|
|
from kfet.cms.context_processors import get_articles
|
|
|
|
|
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
@register_snippet
|
|
|
|
class MemberTeam(models.Model):
|
|
|
|
first_name = models.CharField(
|
2018-10-06 12:35:49 +02:00
|
|
|
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(
|
2018-10-06 12:35:49 +02:00
|
|
|
verbose_name=_("Nom"), blank=True, default="", max_length=255
|
2017-06-12 01:51:10 +02:00
|
|
|
)
|
|
|
|
nick_name = models.CharField(
|
2018-10-06 12:35:49 +02:00
|
|
|
verbose_name=_("Alias"), blank=True, default="", max_length=255
|
2017-06-12 01:51:10 +02:00
|
|
|
)
|
|
|
|
photo = models.ForeignKey(
|
2018-10-06 12:35:49 +02:00
|
|
|
"wagtailimages.Image",
|
|
|
|
verbose_name=_("Photo"),
|
2017-06-12 01:51:10 +02:00
|
|
|
on_delete=models.SET_NULL,
|
2018-10-06 12:35:49 +02:00
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
related_name="+",
|
2017-05-30 20:44:30 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2018-10-06 12:35:49 +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 = [
|
2018-10-06 12:35:49 +02:00
|
|
|
FieldPanel("first_name"),
|
|
|
|
FieldPanel("last_name"),
|
|
|
|
FieldPanel("nick_name"),
|
|
|
|
ImageChooserPanel("photo"),
|
2017-06-12 01:51:10 +02:00
|
|
|
]
|
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):
|
2018-10-06 12:35:49 +02:00
|
|
|
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:
|
2018-10-06 12:35:49 +02:00
|
|
|
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):
|
|
|
|
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(
|
2018-10-06 12:35:49 +02:00
|
|
|
label=_("Montrer seulement"),
|
2017-06-12 01:51:10 +02:00
|
|
|
required=False,
|
2017-05-30 20:44:30 +02:00
|
|
|
help_text=_(
|
2018-10-06 12:35:49 +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),
|
2018-10-06 12:35:49 +02:00
|
|
|
label=_("K-Fêt-eux-ses"),
|
|
|
|
classname="team-group",
|
2017-06-12 01:51:10 +02:00
|
|
|
)
|
2017-05-30 20:44:30 +02:00
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
class Meta:
|
2018-10-06 12:35:49 +02:00
|
|
|
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):
|
2018-10-06 12:35:49 +02:00
|
|
|
rich = blocks.RichTextBlock(label=_("Éditeur"))
|
2017-06-12 01:51:10 +02:00
|
|
|
carte = MenuBlock()
|
|
|
|
group_team = GroupTeamBlock()
|
2017-05-30 20:44:30 +02:00
|
|
|
|
|
|
|
|
2017-06-12 01:51:10 +02:00
|
|
|
class KFetStreamBlock(ChoicesStreamBlock):
|
2018-10-06 12:35:49 +02:00
|
|
|
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
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
content = StreamField(KFetStreamBlock, verbose_name=_("Contenu"))
|
2017-06-12 01:51:10 +02:00
|
|
|
|
|
|
|
# Layout fields
|
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
TEMPLATE_COL_1 = "kfet/base_col_1.html"
|
|
|
|
TEMPLATE_COL_2 = "kfet/base_col_2.html"
|
|
|
|
TEMPLATE_COL_MULT = "kfet/base_col_mult.html"
|
2017-06-12 01:51:10 +02:00
|
|
|
|
|
|
|
no_header = models.BooleanField(
|
2018-10-06 12:35:49 +02:00
|
|
|
verbose_name=_("Sans en-tête"),
|
2017-06-12 01:51:10 +02:00
|
|
|
default=False,
|
2018-10-06 12:35:49 +02:00
|
|
|
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(
|
2018-10-06 12:35:49 +02:00
|
|
|
verbose_name=_("Template"),
|
2017-06-12 01:51:10 +02:00
|
|
|
choices=[
|
2018-10-06 12:35:49 +02:00
|
|
|
(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")),
|
2017-06-12 01:51:10 +02:00
|
|
|
],
|
2018-10-06 12:35:49 +02:00
|
|
|
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(
|
2018-10-06 12:35:49 +02:00
|
|
|
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(
|
2018-10-06 12:35:49 +02:00
|
|
|
verbose_name=_("Nombre de colonnes"),
|
|
|
|
blank=True,
|
|
|
|
max_length=255,
|
2017-06-12 01:51:10 +02:00
|
|
|
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
|
|
|
|
2018-10-06 12:35:49 +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 = [
|
2018-10-06 12:35:49 +02:00
|
|
|
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 = [
|
2018-10-06 12:35:49 +02:00
|
|
|
MultiFieldPanel(layout_panel, _("Affichage"))
|
2017-06-12 01:51:10 +02:00
|
|
|
] + Page.settings_panels
|
|
|
|
|
|
|
|
# Base template
|
|
|
|
template = "kfetcms/base.html"
|
|
|
|
|
|
|
|
class Meta:
|
2018-10-06 12:35:49 +02:00
|
|
|
verbose_name = _("page K-Fêt")
|
|
|
|
verbose_name_plural = _("pages K-Fêt")
|
2017-06-12 01:51:10 +02:00
|
|
|
|
|
|
|
def get_context(self, request, *args, **kwargs):
|
|
|
|
context = super().get_context(request, *args, **kwargs)
|
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
page = context["page"]
|
2017-06-12 01:51:10 +02:00
|
|
|
|
|
|
|
if not page.seo_title:
|
|
|
|
page.seo_title = page.title
|
|
|
|
|
|
|
|
return context
|