From 6023211ab09a46a8c9c873def0fec847ac46af1e Mon Sep 17 00:00:00 2001 From: Evarin Date: Wed, 9 Aug 2017 00:07:56 +0200 Subject: [PATCH] Models des pages et traductions --- gestioncof/cms/__init__.py | 1 + gestioncof/cms/apps.py | 7 + gestioncof/cms/migrations/0001_initial.py | 165 ++++++++++++++++++++-- gestioncof/cms/models.py | 101 ++++++++++++- gestioncof/cms/translation.py | 40 +++++- 5 files changed, 296 insertions(+), 18 deletions(-) create mode 100644 gestioncof/cms/apps.py diff --git a/gestioncof/cms/__init__.py b/gestioncof/cms/__init__.py index e69de29b..9892db53 100644 --- a/gestioncof/cms/__init__.py +++ b/gestioncof/cms/__init__.py @@ -0,0 +1 @@ +default_app_config = 'gestioncof.cms.apps.COFCMSAppConfig' diff --git a/gestioncof/cms/apps.py b/gestioncof/cms/apps.py new file mode 100644 index 00000000..cbc58688 --- /dev/null +++ b/gestioncof/cms/apps.py @@ -0,0 +1,7 @@ +from django.apps import AppConfig + + +class COFCMSAppConfig(AppConfig): + name = 'gestioncof.cms' + label = 'cofcms' + verbose_name = 'CMS COF' diff --git a/gestioncof/cms/migrations/0001_initial.py b/gestioncof/cms/migrations/0001_initial.py index 5b48c5ec..19cf61c7 100644 --- a/gestioncof/cms/migrations/0001_initial.py +++ b/gestioncof/cms/migrations/0001_initial.py @@ -2,33 +2,170 @@ from __future__ import unicode_literals from django.db import migrations, models +import django.db.models.deletion +import wagtail.wagtailimages.blocks +import wagtail.wagtailcore.blocks import wagtail.wagtailcore.fields class Migration(migrations.Migration): dependencies = [ + ('wagtailimages', '0019_delete_filter'), ('wagtailcore', '0033_remove_golive_expiry_help_text'), ] operations = [ + migrations.CreateModel( + name='COFActuIndexPage', + fields=[ + ('page_ptr', models.OneToOneField(primary_key=True, parent_link=True, serialize=False, auto_created=True, to='wagtailcore.Page')), + ('title_fr', models.CharField(null=True, verbose_name='title', help_text="The page title as you'd like it to be seen by the public", max_length=255)), + ('title_en', models.CharField(null=True, verbose_name='title', help_text="The page title as you'd like it to be seen by the public", max_length=255)), + ('slug_fr', models.SlugField(null=True, verbose_name='slug', help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=255)), + ('slug_en', models.SlugField(null=True, verbose_name='slug', help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=255)), + ('url_path_fr', models.TextField(null=True, blank=True, verbose_name='URL path', editable=False)), + ('url_path_en', models.TextField(null=True, blank=True, verbose_name='URL path', editable=False)), + ('seo_title_fr', models.CharField(null=True, blank=True, verbose_name='page title', help_text="Optional. 'Search Engine Friendly' title. This will appear at the top of the browser window.", max_length=255)), + ('seo_title_en', models.CharField(null=True, blank=True, verbose_name='page title', help_text="Optional. 'Search Engine Friendly' title. This will appear at the top of the browser window.", max_length=255)), + ('search_description_fr', models.TextField(null=True, blank=True, verbose_name='search description')), + ('search_description_en', models.TextField(null=True, blank=True, verbose_name='search description')), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), + migrations.CreateModel( + name='COFActuPage', + fields=[ + ('page_ptr', models.OneToOneField(primary_key=True, parent_link=True, serialize=False, auto_created=True, to='wagtailcore.Page')), + ('title_fr', models.CharField(null=True, verbose_name='title', help_text="The page title as you'd like it to be seen by the public", max_length=255)), + ('title_en', models.CharField(null=True, verbose_name='title', help_text="The page title as you'd like it to be seen by the public", max_length=255)), + ('slug_fr', models.SlugField(null=True, verbose_name='slug', help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=255)), + ('slug_en', models.SlugField(null=True, verbose_name='slug', help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=255)), + ('url_path_fr', models.TextField(null=True, blank=True, verbose_name='URL path', editable=False)), + ('url_path_en', models.TextField(null=True, blank=True, verbose_name='URL path', editable=False)), + ('seo_title_fr', models.CharField(null=True, blank=True, verbose_name='page title', help_text="Optional. 'Search Engine Friendly' title. This will appear at the top of the browser window.", max_length=255)), + ('seo_title_en', models.CharField(null=True, blank=True, verbose_name='page title', help_text="Optional. 'Search Engine Friendly' title. This will appear at the top of the browser window.", max_length=255)), + ('search_description_fr', models.TextField(null=True, blank=True, verbose_name='search description')), + ('search_description_en', models.TextField(null=True, blank=True, verbose_name='search description')), + ('body', wagtail.wagtailcore.fields.RichTextField(verbose_name='Contenu')), + ('body_fr', wagtail.wagtailcore.fields.RichTextField(null=True, verbose_name='Contenu')), + ('body_en', wagtail.wagtailcore.fields.RichTextField(null=True, verbose_name='Contenu')), + ('date', models.DateField(verbose_name='Date du post')), + ('Image à la Une', models.ForeignKey(null=True, to='wagtailimages.Image', on_delete=django.db.models.deletion.SET_NULL, blank=True, related_name='+')), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), + migrations.CreateModel( + name='COFDirectoryEntryPage', + fields=[ + ('page_ptr', models.OneToOneField(primary_key=True, parent_link=True, serialize=False, auto_created=True, to='wagtailcore.Page')), + ('title_fr', models.CharField(null=True, verbose_name='title', help_text="The page title as you'd like it to be seen by the public", max_length=255)), + ('title_en', models.CharField(null=True, verbose_name='title', help_text="The page title as you'd like it to be seen by the public", max_length=255)), + ('slug_fr', models.SlugField(null=True, verbose_name='slug', help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=255)), + ('slug_en', models.SlugField(null=True, verbose_name='slug', help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=255)), + ('url_path_fr', models.TextField(null=True, blank=True, verbose_name='URL path', editable=False)), + ('url_path_en', models.TextField(null=True, blank=True, verbose_name='URL path', editable=False)), + ('seo_title_fr', models.CharField(null=True, blank=True, verbose_name='page title', help_text="Optional. 'Search Engine Friendly' title. This will appear at the top of the browser window.", max_length=255)), + ('seo_title_en', models.CharField(null=True, blank=True, verbose_name='page title', help_text="Optional. 'Search Engine Friendly' title. This will appear at the top of the browser window.", max_length=255)), + ('search_description_fr', models.TextField(null=True, blank=True, verbose_name='search description')), + ('search_description_en', models.TextField(null=True, blank=True, verbose_name='search description')), + ('body', wagtail.wagtailcore.fields.RichTextField(verbose_name='Description')), + ('body_fr', wagtail.wagtailcore.fields.RichTextField(null=True, verbose_name='Description')), + ('body_en', wagtail.wagtailcore.fields.RichTextField(null=True, verbose_name='Description')), + ('links', wagtail.wagtailcore.fields.StreamField((('lien', wagtail.wagtailcore.blocks.StructBlock((('url', wagtail.wagtailcore.blocks.URLBlock(required=True)), ('texte', wagtail.wagtailcore.blocks.CharBlock())))), ('contact', wagtail.wagtailcore.blocks.StructBlock((('email', wagtail.wagtailcore.blocks.EmailBlock(required=True)), ('texte', wagtail.wagtailcore.blocks.CharBlock()))))))), + ('links_fr', wagtail.wagtailcore.fields.StreamField((('lien', wagtail.wagtailcore.blocks.StructBlock((('url', wagtail.wagtailcore.blocks.URLBlock(required=True)), ('texte', wagtail.wagtailcore.blocks.CharBlock())))), ('contact', wagtail.wagtailcore.blocks.StructBlock((('email', wagtail.wagtailcore.blocks.EmailBlock(required=True)), ('texte', wagtail.wagtailcore.blocks.CharBlock()))))), null=True)), + ('links_en', wagtail.wagtailcore.fields.StreamField((('lien', wagtail.wagtailcore.blocks.StructBlock((('url', wagtail.wagtailcore.blocks.URLBlock(required=True)), ('texte', wagtail.wagtailcore.blocks.CharBlock())))), ('contact', wagtail.wagtailcore.blocks.StructBlock((('email', wagtail.wagtailcore.blocks.EmailBlock(required=True)), ('texte', wagtail.wagtailcore.blocks.CharBlock()))))), null=True)), + ('Image', models.ForeignKey(null=True, to='wagtailimages.Image', on_delete=django.db.models.deletion.SET_NULL, blank=True, related_name='+')), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), + migrations.CreateModel( + name='COFDirectoryPage', + fields=[ + ('page_ptr', models.OneToOneField(primary_key=True, parent_link=True, serialize=False, auto_created=True, to='wagtailcore.Page')), + ('title_fr', models.CharField(null=True, verbose_name='title', help_text="The page title as you'd like it to be seen by the public", max_length=255)), + ('title_en', models.CharField(null=True, verbose_name='title', help_text="The page title as you'd like it to be seen by the public", max_length=255)), + ('slug_fr', models.SlugField(null=True, verbose_name='slug', help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=255)), + ('slug_en', models.SlugField(null=True, verbose_name='slug', help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=255)), + ('url_path_fr', models.TextField(null=True, blank=True, verbose_name='URL path', editable=False)), + ('url_path_en', models.TextField(null=True, blank=True, verbose_name='URL path', editable=False)), + ('seo_title_fr', models.CharField(null=True, blank=True, verbose_name='page title', help_text="Optional. 'Search Engine Friendly' title. This will appear at the top of the browser window.", max_length=255)), + ('seo_title_en', models.CharField(null=True, blank=True, verbose_name='page title', help_text="Optional. 'Search Engine Friendly' title. This will appear at the top of the browser window.", max_length=255)), + ('search_description_fr', models.TextField(null=True, blank=True, verbose_name='search description')), + ('search_description_en', models.TextField(null=True, blank=True, verbose_name='search description')), + ('introduction', wagtail.wagtailcore.fields.RichTextField(verbose_name='Introduction')), + ('introduction_fr', wagtail.wagtailcore.fields.RichTextField(null=True, verbose_name='Introduction')), + ('introduction_en', wagtail.wagtailcore.fields.RichTextField(null=True, verbose_name='Introduction')), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), + migrations.CreateModel( + name='COFEvent', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('title', models.TextField(verbose_name='Titre')), + ('title_fr', models.TextField(null=True, verbose_name='Titre')), + ('title_en', models.TextField(null=True, verbose_name='Titre')), + ('description', wagtail.wagtailcore.fields.RichTextField(verbose_name='Description (concise)')), + ('description_fr', wagtail.wagtailcore.fields.RichTextField(null=True, verbose_name='Description (concise)')), + ('description_en', wagtail.wagtailcore.fields.RichTextField(null=True, verbose_name='Description (concise)')), + ('date_start', models.DateTimeField(verbose_name='Date et heure de début')), + ('date_end', models.DateTimeField(null=True, verbose_name='Date et heure de fin')), + ('all_day', models.BooleanField(verbose_name='Toute la journée', default=False)), + ], + ), migrations.CreateModel( name='COFPage', fields=[ - ('page_ptr', models.OneToOneField(primary_key=True, to='wagtailcore.Page', parent_link=True, auto_created=True, serialize=False)), - ('title_fr', models.CharField(help_text="The page title as you'd like it to be seen by the public", null=True, max_length=255, verbose_name='title')), - ('title_en', models.CharField(help_text="The page title as you'd like it to be seen by the public", null=True, max_length=255, verbose_name='title')), - ('slug_fr', models.SlugField(help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', null=True, max_length=255, verbose_name='slug')), - ('slug_en', models.SlugField(help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', null=True, max_length=255, verbose_name='slug')), - ('url_path_fr', models.TextField(blank=True, null=True, editable=False, verbose_name='URL path')), - ('url_path_en', models.TextField(blank=True, null=True, editable=False, verbose_name='URL path')), - ('seo_title_fr', models.CharField(help_text="Optional. 'Search Engine Friendly' title. This will appear at the top of the browser window.", null=True, blank=True, max_length=255, verbose_name='page title')), - ('seo_title_en', models.CharField(help_text="Optional. 'Search Engine Friendly' title. This will appear at the top of the browser window.", null=True, blank=True, max_length=255, verbose_name='page title')), - ('search_description_fr', models.TextField(blank=True, null=True, verbose_name='search description')), - ('search_description_en', models.TextField(blank=True, null=True, verbose_name='search description')), - ('corps', wagtail.wagtailcore.fields.RichTextField()), - ('corps_fr', wagtail.wagtailcore.fields.RichTextField(null=True)), - ('corps_en', wagtail.wagtailcore.fields.RichTextField(null=True)), + ('page_ptr', models.OneToOneField(primary_key=True, parent_link=True, serialize=False, auto_created=True, to='wagtailcore.Page')), + ('title_fr', models.CharField(null=True, verbose_name='title', help_text="The page title as you'd like it to be seen by the public", max_length=255)), + ('title_en', models.CharField(null=True, verbose_name='title', help_text="The page title as you'd like it to be seen by the public", max_length=255)), + ('slug_fr', models.SlugField(null=True, verbose_name='slug', help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=255)), + ('slug_en', models.SlugField(null=True, verbose_name='slug', help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=255)), + ('url_path_fr', models.TextField(null=True, blank=True, verbose_name='URL path', editable=False)), + ('url_path_en', models.TextField(null=True, blank=True, verbose_name='URL path', editable=False)), + ('seo_title_fr', models.CharField(null=True, blank=True, verbose_name='page title', help_text="Optional. 'Search Engine Friendly' title. This will appear at the top of the browser window.", max_length=255)), + ('seo_title_en', models.CharField(null=True, blank=True, verbose_name='page title', help_text="Optional. 'Search Engine Friendly' title. This will appear at the top of the browser window.", max_length=255)), + ('search_description_fr', models.TextField(null=True, blank=True, verbose_name='search description')), + ('search_description_en', models.TextField(null=True, blank=True, verbose_name='search description')), + ('body', wagtail.wagtailcore.fields.StreamField((('heading', wagtail.wagtailcore.blocks.CharBlock(classname='full title')), ('paragraph', wagtail.wagtailcore.blocks.RichTextBlock()), ('image', wagtail.wagtailimages.blocks.ImageChooserBlock())))), + ('body_fr', wagtail.wagtailcore.fields.StreamField((('heading', wagtail.wagtailcore.blocks.CharBlock(classname='full title')), ('paragraph', wagtail.wagtailcore.blocks.RichTextBlock()), ('image', wagtail.wagtailimages.blocks.ImageChooserBlock())), null=True)), + ('body_en', wagtail.wagtailcore.fields.StreamField((('heading', wagtail.wagtailcore.blocks.CharBlock(classname='full title')), ('paragraph', wagtail.wagtailcore.blocks.RichTextBlock()), ('image', wagtail.wagtailimages.blocks.ImageChooserBlock())), null=True)), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), + migrations.CreateModel( + name='COFRootPage', + fields=[ + ('page_ptr', models.OneToOneField(primary_key=True, parent_link=True, serialize=False, auto_created=True, to='wagtailcore.Page')), + ('title_fr', models.CharField(null=True, verbose_name='title', help_text="The page title as you'd like it to be seen by the public", max_length=255)), + ('title_en', models.CharField(null=True, verbose_name='title', help_text="The page title as you'd like it to be seen by the public", max_length=255)), + ('slug_fr', models.SlugField(null=True, verbose_name='slug', help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=255)), + ('slug_en', models.SlugField(null=True, verbose_name='slug', help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=255)), + ('url_path_fr', models.TextField(null=True, blank=True, verbose_name='URL path', editable=False)), + ('url_path_en', models.TextField(null=True, blank=True, verbose_name='URL path', editable=False)), + ('seo_title_fr', models.CharField(null=True, blank=True, verbose_name='page title', help_text="Optional. 'Search Engine Friendly' title. This will appear at the top of the browser window.", max_length=255)), + ('seo_title_en', models.CharField(null=True, blank=True, verbose_name='page title', help_text="Optional. 'Search Engine Friendly' title. This will appear at the top of the browser window.", max_length=255)), + ('search_description_fr', models.TextField(null=True, blank=True, verbose_name='search description')), + ('search_description_en', models.TextField(null=True, blank=True, verbose_name='search description')), + ('introduction', wagtail.wagtailcore.fields.RichTextField(verbose_name='Introduction')), + ('introduction_fr', wagtail.wagtailcore.fields.RichTextField(null=True, verbose_name='Introduction')), + ('introduction_en', wagtail.wagtailcore.fields.RichTextField(null=True, verbose_name='Introduction')), ], options={ 'abstract': False, diff --git a/gestioncof/cms/models.py b/gestioncof/cms/models.py index 17492f08..eb50df48 100644 --- a/gestioncof/cms/models.py +++ b/gestioncof/cms/models.py @@ -1,11 +1,108 @@ from django.db import models -# Create your models here. 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): - corps = RichTextField() + 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'] + diff --git a/gestioncof/cms/translation.py b/gestioncof/cms/translation.py index b705f6ed..705a9c1f 100644 --- a/gestioncof/cms/translation.py +++ b/gestioncof/cms/translation.py @@ -1,11 +1,47 @@ -from .models import COFPage +from .models import COFRootPage, COFPage, COFEvent, COFActuIndexPage, COFActuPage, COFDirectoryPage, COFDirectoryEntryPage from wagtail_modeltranslation.translator import WagtailTranslationOptions from modeltranslation.decorators import register +@register(COFRootPage) +class COFPageTr(WagtailTranslationOptions): + fields = ( + 'introduction', + ) + @register(COFPage) class COFPageTr(WagtailTranslationOptions): fields = ( - 'corps', + 'body', + ) + +@register(COFEvent) +class COFEventTr(WagtailTranslationOptions): + fields = ( + 'title', + 'description', + ) + +@register(COFActuIndexPage) +class COFActuIndexPageTr(WagtailTranslationOptions): + fields = ( + ) + +@register(COFActuPage) +class COFActuPageTr(WagtailTranslationOptions): + fields = ( + 'body', + ) + +@register(COFDirectoryPage) +class COFDirectoryPageTr(WagtailTranslationOptions): + fields = ( + 'introduction', ) +@register(COFDirectoryEntryPage) +class COFDirectoryEntryPageTr(WagtailTranslationOptions): + fields = ( + 'body', + 'links', + )