gestioCOF/gestioncof/cms/models.py
2017-08-09 00:07:56 +02:00

108 lines
3.2 KiB
Python

from django.db import models
from wagtail.wagtailcore.models import Page, Orderable
from wagtail.wagtailcore.fields import RichTextField, StreamField
from wagtail.wagtailcore import blocks
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
from wagtail.wagtailimages.blocks import ImageChooserBlock
from wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtail.wagtailsnippets.models import register_snippet
# Racine du site du COF
class COFRootPage(Page):
introduction = RichTextField("Introduction")
content_panels = Page.content_panels + [
FieldPanel('introduction', classname="full"),
]
subpage_types = ['COFActuIndexPage', 'COFPage', 'COFDirectoryPage']
# Page lambda du site
class COFPage(Page):
body = StreamField([
('heading', blocks.CharBlock(classname="full title")),
('paragraph', blocks.RichTextBlock()),
('image', ImageChooserBlock()),
])
content_panels = Page.content_panels + [
StreamFieldPanel('body'),
]
subpages_types = ['COFDirectoryPage', 'COFPage']
parent_page_types = ['COFPage', 'COFRootPage']
# Évènements
@register_snippet
class COFEvent(models.Model):
title = models.TextField("Titre")
description = RichTextField("Description (concise)")
date_start = models.DateTimeField("Date et heure de début")
date_end = models.DateTimeField("Date et heure de fin", null=True)
all_day = models.BooleanField("Toute la journée", default=False, blank=True)
panels = [
FieldPanel("title"),
FieldPanel("description"),
FieldPanel("date_start"),
FieldPanel("date_end"),
FieldPanel("all_day"),
]
# Actualités
class COFActuIndexPage(Page):
subpages_types = ['COFActuPage']
parent_page_types = ['COFRootPage']
class COFActuPage(Page):
body = RichTextField("Contenu")
date = models.DateField("Date du post")
image = models.ForeignKey(
'wagtailimages.Image', name="Image à la Une",
null=True, blank=True,
on_delete=models.SET_NULL, related_name='+'
)
content_panels = Page.content_panels + [
FieldPanel('date'),
# ImageChooserPanel('image'),
FieldPanel('body', classname="full"),
]
subpages_types = []
parent_page_types = ['COFActuIndexPage']
# Annuaires (Clubs, partenaires, bonnes adresses)
class COFDirectoryPage(Page):
introduction = RichTextField("Introduction")
subpages_types = ['COFActuPage', 'COFDirectoryEntryPage']
parent_page_types = ['COFRootPage', 'COFPage']
class COFDirectoryEntryPage(Page):
body = RichTextField("Description")
links = StreamField([
('lien', blocks.StructBlock([
('url', blocks.URLBlock(required=True)),
('texte', blocks.CharBlock()),
])),
('contact', blocks.StructBlock([
('email', blocks.EmailBlock(required=True)),
('texte', blocks.CharBlock()),
])),
])
image = models.ForeignKey(
'wagtailimages.Image', name="Image",
null=True, blank=True,
on_delete=models.SET_NULL, related_name='+'
)
subpages_types = []
parent_page_types = ['COFDirectoryPage']