2019-01-06 00:17:57 +01:00
|
|
|
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
|
2017-08-07 23:31:27 +02:00
|
|
|
from django.db import models
|
2019-02-04 22:50:27 +01:00
|
|
|
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
|
2019-02-09 14:37:15 +01:00
|
|
|
from wagtail.contrib.routable_page.models import RoutablePageMixin, route
|
2019-02-04 22:50:27 +01:00
|
|
|
from wagtail.core import blocks
|
|
|
|
from wagtail.core.fields import RichTextField, StreamField
|
|
|
|
from wagtail.core.models import Page
|
|
|
|
from wagtail.images.blocks import ImageChooserBlock
|
|
|
|
from wagtail.images.edit_handlers import ImageChooserPanel
|
2019-01-06 00:17:57 +01:00
|
|
|
|
2017-08-07 23:31:27 +02:00
|
|
|
|
2017-08-19 01:32:26 +02:00
|
|
|
# Page pouvant afficher des actualités
|
2018-04-28 15:59:49 +02:00
|
|
|
class COFActuIndexMixin:
|
2017-08-19 01:32:26 +02:00
|
|
|
@property
|
|
|
|
def actus(self):
|
2019-01-06 00:25:41 +01:00
|
|
|
actus = COFActuPage.objects.live().order_by("-date_start").descendant_of(self)
|
2018-01-22 21:24:20 +01:00
|
|
|
return actus
|
2019-01-06 00:17:57 +01:00
|
|
|
|
|
|
|
|
2017-08-09 00:07:56 +02:00
|
|
|
# Racine du site du COF
|
2019-02-04 22:50:27 +01:00
|
|
|
class COFRootPage(RoutablePageMixin, Page, COFActuIndexMixin):
|
2017-08-09 00:07:56 +02:00
|
|
|
introduction = RichTextField("Introduction")
|
|
|
|
|
|
|
|
content_panels = Page.content_panels + [
|
2019-01-06 00:25:41 +01:00
|
|
|
FieldPanel("introduction", classname="full")
|
2017-08-09 00:07:56 +02:00
|
|
|
]
|
2019-01-06 00:17:57 +01:00
|
|
|
|
2019-02-04 22:50:27 +01:00
|
|
|
subpage_types = ["COFActuIndexPage", "COFPage", "COFDirectoryPage"]
|
2019-01-06 00:17:57 +01:00
|
|
|
|
2017-08-19 01:32:26 +02:00
|
|
|
class Meta:
|
|
|
|
verbose_name = "Racine site du COF"
|
|
|
|
verbose_name_plural = "Racines site du COF"
|
2018-01-28 23:44:48 +01:00
|
|
|
|
2019-02-04 22:50:27 +01:00
|
|
|
# Mini calendrier
|
|
|
|
@route(r"^calendar/(\d+)/(\d+)/$")
|
|
|
|
def calendar(self, request, year, month):
|
|
|
|
from .views import raw_calendar_view
|
|
|
|
|
|
|
|
return raw_calendar_view(request, int(year), int(month))
|
|
|
|
|
2019-01-06 00:17:57 +01:00
|
|
|
|
2018-03-21 21:50:57 +01:00
|
|
|
# Block iframe
|
|
|
|
class IFrameBlock(blocks.StructBlock):
|
|
|
|
url = blocks.URLBlock("Adresse de la page")
|
|
|
|
height = blocks.CharBlock("Hauteur (en pixels)")
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Page incluse (iframe, à utiliser avec précaution)"
|
|
|
|
verbose_name_plural = "Pages incluses (iframes, à utiliser avec précaution)"
|
|
|
|
template = "cofcms/iframe_block.html"
|
2019-01-06 00:17:57 +01:00
|
|
|
|
|
|
|
|
2017-08-09 00:07:56 +02:00
|
|
|
# Page lambda du site
|
2017-08-07 23:31:27 +02:00
|
|
|
class COFPage(Page):
|
2019-01-06 00:25:41 +01:00
|
|
|
body = StreamField(
|
|
|
|
[
|
|
|
|
("heading", blocks.CharBlock(classname="full title")),
|
|
|
|
("paragraph", blocks.RichTextBlock()),
|
|
|
|
("image", ImageChooserBlock()),
|
|
|
|
("iframe", IFrameBlock()),
|
|
|
|
]
|
|
|
|
)
|
2017-08-09 00:07:56 +02:00
|
|
|
|
2019-01-06 00:25:41 +01:00
|
|
|
content_panels = Page.content_panels + [StreamFieldPanel("body")]
|
2019-01-06 00:17:57 +01:00
|
|
|
|
2019-01-06 00:25:41 +01:00
|
|
|
subpage_types = ["COFDirectoryPage", "COFPage"]
|
|
|
|
parent_page_types = ["COFPage", "COFRootPage"]
|
2017-08-09 00:07:56 +02:00
|
|
|
|
2017-08-19 01:32:26 +02:00
|
|
|
class Meta:
|
|
|
|
verbose_name = "Page normale COF"
|
|
|
|
verbose_name_plural = "Pages normales COF"
|
2017-08-09 00:07:56 +02:00
|
|
|
|
2019-01-06 00:17:57 +01:00
|
|
|
|
2017-08-09 00:07:56 +02:00
|
|
|
# Actualités
|
2017-08-19 01:32:26 +02:00
|
|
|
class COFActuIndexPage(Page, COFActuIndexMixin):
|
2019-01-06 00:25:41 +01:00
|
|
|
subpage_types = ["COFActuPage"]
|
|
|
|
parent_page_types = ["COFRootPage"]
|
2019-01-06 00:17:57 +01:00
|
|
|
|
2017-08-19 01:32:26 +02:00
|
|
|
class Meta:
|
|
|
|
verbose_name = "Index des actualités"
|
|
|
|
verbose_name_plural = "Indexs des actualités"
|
2017-08-09 00:07:56 +02:00
|
|
|
|
2018-01-20 19:33:50 +01:00
|
|
|
def get_context(self, request):
|
2018-04-28 15:59:49 +02:00
|
|
|
context = super().get_context(request)
|
2019-01-06 00:25:41 +01:00
|
|
|
actus = COFActuPage.objects.live().descendant_of(self).order_by("-date_end")
|
2018-01-20 19:33:50 +01:00
|
|
|
|
2019-01-06 00:25:41 +01:00
|
|
|
page = request.GET.get("page")
|
2018-01-20 19:33:50 +01:00
|
|
|
paginator = Paginator(actus, 5)
|
|
|
|
try:
|
|
|
|
actus = paginator.page(page)
|
|
|
|
except PageNotAnInteger:
|
|
|
|
actus = paginator.page(1)
|
|
|
|
except EmptyPage:
|
|
|
|
actus = paginator.page(paginator.num_pages)
|
|
|
|
|
2019-01-06 00:25:41 +01:00
|
|
|
context["actus"] = actus
|
2018-01-20 19:33:50 +01:00
|
|
|
return context
|
|
|
|
|
2019-01-06 00:17:57 +01:00
|
|
|
|
2018-01-28 23:44:48 +01:00
|
|
|
class COFActuPage(RoutablePageMixin, Page):
|
2018-01-22 21:24:20 +01:00
|
|
|
chapo = models.TextField("Description rapide", blank=True)
|
2017-08-09 00:07:56 +02:00
|
|
|
body = RichTextField("Contenu")
|
|
|
|
image = models.ForeignKey(
|
2019-01-06 00:25:41 +01:00
|
|
|
"wagtailimages.Image",
|
|
|
|
verbose_name="Image à la Une",
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
related_name="+",
|
2017-08-09 00:07:56 +02:00
|
|
|
)
|
2019-01-06 00:17:57 +01:00
|
|
|
is_event = models.BooleanField("Évènement", default=True, blank=True)
|
2017-08-19 01:32:26 +02:00
|
|
|
date_start = models.DateTimeField("Date et heure de début")
|
2019-01-06 00:25:41 +01:00
|
|
|
date_end = models.DateTimeField(
|
|
|
|
"Date et heure de fin", blank=True, default=None, null=True
|
|
|
|
)
|
2017-08-19 01:32:26 +02:00
|
|
|
all_day = models.BooleanField("Toute la journée", default=False, blank=True)
|
2018-01-22 21:24:20 +01:00
|
|
|
|
2017-08-19 01:32:26 +02:00
|
|
|
content_panels = Page.content_panels + [
|
2019-01-06 00:25:41 +01:00
|
|
|
ImageChooserPanel("image"),
|
|
|
|
FieldPanel("chapo"),
|
|
|
|
FieldPanel("body", classname="full"),
|
2018-01-22 21:24:20 +01:00
|
|
|
FieldPanel("is_event"),
|
2017-08-19 01:32:26 +02:00
|
|
|
FieldPanel("date_start"),
|
|
|
|
FieldPanel("date_end"),
|
|
|
|
FieldPanel("all_day"),
|
|
|
|
]
|
|
|
|
|
|
|
|
subpage_types = []
|
2019-01-06 00:25:41 +01:00
|
|
|
parent_page_types = ["COFActuIndexPage"]
|
2017-08-22 00:58:18 +02:00
|
|
|
|
2017-08-19 01:32:26 +02:00
|
|
|
class Meta:
|
2018-01-22 21:24:20 +01:00
|
|
|
verbose_name = "Actualité"
|
|
|
|
verbose_name_plural = "Actualités"
|
2019-01-06 00:17:57 +01:00
|
|
|
|
|
|
|
|
2017-08-09 00:07:56 +02:00
|
|
|
# Annuaires (Clubs, partenaires, bonnes adresses)
|
|
|
|
class COFDirectoryPage(Page):
|
|
|
|
introduction = RichTextField("Introduction")
|
2019-01-06 00:25:41 +01:00
|
|
|
alphabetique = models.BooleanField(
|
|
|
|
"Tri par ordre alphabétique ?", default=True, blank=True
|
|
|
|
)
|
2019-01-06 00:17:57 +01:00
|
|
|
|
2017-08-19 01:32:26 +02:00
|
|
|
content_panels = Page.content_panels + [
|
2019-01-06 00:25:41 +01:00
|
|
|
FieldPanel("introduction"),
|
|
|
|
FieldPanel("alphabetique"),
|
2017-08-19 01:32:26 +02:00
|
|
|
]
|
|
|
|
|
2019-01-06 00:25:41 +01:00
|
|
|
subpage_types = ["COFActuPage", "COFDirectoryEntryPage"]
|
|
|
|
parent_page_types = ["COFRootPage", "COFPage"]
|
2017-08-09 00:07:56 +02:00
|
|
|
|
2017-08-19 01:32:26 +02:00
|
|
|
@property
|
|
|
|
def entries(self):
|
2019-01-06 00:25:41 +01:00
|
|
|
entries = COFDirectoryEntryPage.objects.live().descendant_of(self)
|
2018-01-28 19:09:35 +01:00
|
|
|
if self.alphabetique:
|
|
|
|
entries = entries.order_by("title")
|
2017-08-19 01:32:26 +02:00
|
|
|
return entries
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Annuaire (clubs, partenaires, bons plans...)"
|
|
|
|
verbose_name_plural = "Annuaires"
|
|
|
|
|
|
|
|
|
2019-01-06 00:17:57 +01:00
|
|
|
class COFDirectoryEntryPage(Page):
|
2017-08-09 00:07:56 +02:00
|
|
|
body = RichTextField("Description")
|
2019-01-06 00:25:41 +01:00
|
|
|
links = StreamField(
|
|
|
|
[
|
|
|
|
(
|
|
|
|
"lien",
|
|
|
|
blocks.StructBlock(
|
|
|
|
[
|
|
|
|
("url", blocks.URLBlock(required=True)),
|
|
|
|
("texte", blocks.CharBlock()),
|
|
|
|
]
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"contact",
|
|
|
|
blocks.StructBlock(
|
|
|
|
[
|
|
|
|
("email", blocks.EmailBlock(required=True)),
|
|
|
|
("texte", blocks.CharBlock()),
|
|
|
|
]
|
|
|
|
),
|
|
|
|
),
|
2019-12-20 17:29:35 +01:00
|
|
|
],
|
|
|
|
blank=True,
|
2019-01-06 00:25:41 +01:00
|
|
|
)
|
2017-08-19 01:32:26 +02:00
|
|
|
|
2017-08-09 00:07:56 +02:00
|
|
|
image = models.ForeignKey(
|
2019-01-06 00:25:41 +01:00
|
|
|
"wagtailimages.Image",
|
|
|
|
verbose_name="Image",
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
related_name="+",
|
2017-08-09 00:07:56 +02:00
|
|
|
)
|
|
|
|
|
2017-08-19 01:32:26 +02:00
|
|
|
content_panels = Page.content_panels + [
|
2019-01-06 00:25:41 +01:00
|
|
|
ImageChooserPanel("image"),
|
|
|
|
FieldPanel("body", classname="full"),
|
2017-08-19 01:32:26 +02:00
|
|
|
StreamFieldPanel("links"),
|
|
|
|
]
|
|
|
|
|
|
|
|
subpage_types = []
|
2019-01-06 00:25:41 +01:00
|
|
|
parent_page_types = ["COFDirectoryPage"]
|
2017-08-09 00:07:56 +02:00
|
|
|
|
2017-08-19 01:32:26 +02:00
|
|
|
class Meta:
|
2018-01-28 23:44:48 +01:00
|
|
|
verbose_name = "Entrée d'annuaire"
|
|
|
|
verbose_name_plural = "Entrées d'annuaire"
|