Migration vers Wagtail 2.3 et Wagtail-modeltranslation 0.9

Toutes les pages Wagtail doivent désormais être traduites
Suppression du modèle COFUtilPage devenu inutile
Réinitialisation des migrations de Wagtail à cause des changements de ModelTranslation
This commit is contained in:
Evarin 2019-02-04 22:50:27 +01:00
parent be155f2f2d
commit 0f1e05acdd
16 changed files with 166 additions and 2347 deletions

View file

@ -65,6 +65,12 @@ INSTALLED_APPS = [
"django.contrib.sites", "django.contrib.sites",
"django.contrib.messages", "django.contrib.messages",
"django.contrib.staticfiles", "django.contrib.staticfiles",
# Must be before django admin
# https://github.com/infoportugal/wagtail-modeltranslation/issues/193
"wagtail_modeltranslation",
"wagtail_modeltranslation.makemigrations",
"wagtail_modeltranslation.migrate",
"modeltranslation",
"django.contrib.admin", "django.contrib.admin",
"django.contrib.admindocs", "django.contrib.admindocs",
"bda", "bda",
@ -78,21 +84,20 @@ INSTALLED_APPS = [
"widget_tweaks", "widget_tweaks",
"custommail", "custommail",
"djconfig", "djconfig",
"wagtail.wagtailforms", "wagtail.contrib.forms",
"wagtail.wagtailredirects", "wagtail.contrib.redirects",
"wagtail.wagtailembeds", "wagtail.embeds",
"wagtail.wagtailsites", "wagtail.sites",
"wagtail.wagtailusers", "wagtail.users",
"wagtail.wagtailsnippets", "wagtail.snippets",
"wagtail.wagtaildocs", "wagtail.documents",
"wagtail.wagtailimages", "wagtail.images",
"wagtail.wagtailsearch", "wagtail.search",
"wagtail.wagtailadmin", "wagtail.admin",
"wagtail.wagtailcore", "wagtail.core",
"wagtail.contrib.modeladmin", "wagtail.contrib.modeladmin",
"wagtail.contrib.wagtailroutablepage", "wagtail.contrib.routable_page",
"wagtailmenus", "wagtailmenus",
"wagtail_modeltranslation",
"modelcluster", "modelcluster",
"taggit", "taggit",
"kfet.auth", "kfet.auth",
@ -113,8 +118,8 @@ MIDDLEWARE = [
"django.middleware.clickjacking.XFrameOptionsMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware",
"django.middleware.security.SecurityMiddleware", "django.middleware.security.SecurityMiddleware",
"djconfig.middleware.DjConfigMiddleware", "djconfig.middleware.DjConfigMiddleware",
"wagtail.wagtailcore.middleware.SiteMiddleware", "wagtail.core.middleware.SiteMiddleware",
"wagtail.wagtailredirects.middleware.RedirectMiddleware", "wagtail.contrib.redirects.middleware.RedirectMiddleware",
"django.middleware.locale.LocaleMiddleware", "django.middleware.locale.LocaleMiddleware",
] ]
@ -257,3 +262,6 @@ FORMAT_MODULE_PATH = "cof.locale"
WAGTAIL_SITE_NAME = "GestioCOF" WAGTAIL_SITE_NAME = "GestioCOF"
WAGTAIL_ENABLE_UPDATE_CHECK = False WAGTAIL_ENABLE_UPDATE_CHECK = False
TAGGIT_CASE_INSENSITIVE = True TAGGIT_CASE_INSENSITIVE = True
WAGTAILMENUS_DEFAULT_CHILDREN_MENU_USE_SPECIFIC = 3
WAGTAILMENUS_DEFAULT_SECTION_MENU_USE_SPECIFIC = 3

View file

@ -10,9 +10,9 @@ from django.contrib import admin
from django.contrib.auth import views as django_views from django.contrib.auth import views as django_views
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django_cas_ng import views as django_cas_views from django_cas_ng import views as django_cas_views
from wagtail.wagtailadmin import urls as wagtailadmin_urls from wagtail.admin import urls as wagtailadmin_urls
from wagtail.wagtailcore import urls as wagtail_urls from wagtail.core import urls as wagtail_urls
from wagtail.wagtaildocs import urls as wagtaildocs_urls from wagtail.documents import urls as wagtaildocs_urls
from gestioncof import csv_views, views as gestioncof_views from gestioncof import csv_views, views as gestioncof_views
from gestioncof.autocomplete import autocomplete from gestioncof.autocomplete import autocomplete

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

View file

@ -1,160 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.9 on 2018-04-28 13:46
from __future__ import unicode_literals
import django.db.models.deletion
import wagtail.contrib.wagtailroutablepage.models
import wagtail.wagtailcore.blocks
import wagtail.wagtailcore.fields
import wagtail.wagtailimages.blocks
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("wagtailcore", "0039_collectionviewrestriction"),
("cofcms", "0001_initial"),
]
operations = [
migrations.CreateModel(
name="COFUtilPage",
fields=[
(
"page_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="wagtailcore.Page",
),
)
],
options={
"verbose_name": "Page utilitaire",
"verbose_name_plural": "Pages utilitaires",
},
bases=(
wagtail.contrib.wagtailroutablepage.models.RoutablePageMixin,
"wagtailcore.page",
),
),
migrations.AlterModelOptions(
name="cofdirectoryentrypage",
options={
"verbose_name": "Entrée d'annuaire",
"verbose_name_plural": "Entrées d'annuaire",
},
),
migrations.AddField(
model_name="cofdirectorypage",
name="alphabetique",
field=models.BooleanField(
default=True, verbose_name="Tri par ordre alphabétique ?"
),
),
migrations.AlterField(
model_name="cofpage",
name="body",
field=wagtail.wagtailcore.fields.StreamField(
(
(
"heading",
wagtail.wagtailcore.blocks.CharBlock(classname="full title"),
),
("paragraph", wagtail.wagtailcore.blocks.RichTextBlock()),
("image", wagtail.wagtailimages.blocks.ImageChooserBlock()),
(
"iframe",
wagtail.wagtailcore.blocks.StructBlock(
(
(
"url",
wagtail.wagtailcore.blocks.URLBlock(
"Adresse de la page"
),
),
(
"height",
wagtail.wagtailcore.blocks.CharBlock(
"Hauteur (en pixels)"
),
),
)
),
),
)
),
),
migrations.AlterField(
model_name="cofpage",
name="body_en",
field=wagtail.wagtailcore.fields.StreamField(
(
(
"heading",
wagtail.wagtailcore.blocks.CharBlock(classname="full title"),
),
("paragraph", wagtail.wagtailcore.blocks.RichTextBlock()),
("image", wagtail.wagtailimages.blocks.ImageChooserBlock()),
(
"iframe",
wagtail.wagtailcore.blocks.StructBlock(
(
(
"url",
wagtail.wagtailcore.blocks.URLBlock(
"Adresse de la page"
),
),
(
"height",
wagtail.wagtailcore.blocks.CharBlock(
"Hauteur (en pixels)"
),
),
)
),
),
),
null=True,
),
),
migrations.AlterField(
model_name="cofpage",
name="body_fr",
field=wagtail.wagtailcore.fields.StreamField(
(
(
"heading",
wagtail.wagtailcore.blocks.CharBlock(classname="full title"),
),
("paragraph", wagtail.wagtailcore.blocks.RichTextBlock()),
("image", wagtail.wagtailimages.blocks.ImageChooserBlock()),
(
"iframe",
wagtail.wagtailcore.blocks.StructBlock(
(
(
"url",
wagtail.wagtailcore.blocks.URLBlock(
"Adresse de la page"
),
),
(
"height",
wagtail.wagtailcore.blocks.CharBlock(
"Hauteur (en pixels)"
),
),
)
),
),
),
null=True,
),
),
]

View file

@ -1,12 +1,12 @@
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db import models from django.db import models
from wagtail.contrib.wagtailroutablepage.models import RoutablePageMixin, route from wagtail.contrib.routable_page.models import RoutablePageMixin, route
from wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtail.wagtailcore import blocks from wagtail.core import blocks
from wagtail.wagtailcore.fields import RichTextField, StreamField from wagtail.core.fields import RichTextField, StreamField
from wagtail.wagtailcore.models import Page from wagtail.core.models import Page
from wagtail.wagtailimages.blocks import ImageChooserBlock from wagtail.images.blocks import ImageChooserBlock
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel from wagtail.images.edit_handlers import ImageChooserPanel
# Page pouvant afficher des actualités # Page pouvant afficher des actualités
@ -18,19 +18,26 @@ class COFActuIndexMixin:
# Racine du site du COF # Racine du site du COF
class COFRootPage(Page, COFActuIndexMixin): class COFRootPage(RoutablePageMixin, Page, COFActuIndexMixin):
introduction = RichTextField("Introduction") introduction = RichTextField("Introduction")
content_panels = Page.content_panels + [ content_panels = Page.content_panels + [
FieldPanel("introduction", classname="full") FieldPanel("introduction", classname="full")
] ]
subpage_types = ["COFActuIndexPage", "COFPage", "COFDirectoryPage", "COFUtilPage"] subpage_types = ["COFActuIndexPage", "COFPage", "COFDirectoryPage"]
class Meta: class Meta:
verbose_name = "Racine site du COF" verbose_name = "Racine site du COF"
verbose_name_plural = "Racines site du COF" verbose_name_plural = "Racines site du COF"
# 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))
# Block iframe # Block iframe
class IFrameBlock(blocks.StructBlock): class IFrameBlock(blocks.StructBlock):
@ -199,36 +206,3 @@ class COFDirectoryEntryPage(Page):
class Meta: class Meta:
verbose_name = "Entrée d'annuaire" verbose_name = "Entrée d'annuaire"
verbose_name_plural = "Entrées d'annuaire" verbose_name_plural = "Entrées d'annuaire"
# Pour le calendrier, ne doit pas être pris par ModelTranslation
class COFUtilPage(RoutablePageMixin, Page):
# 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))
"""
ModelTranslation override le système des @route de wagtail, ce qui empêche
COFUtilPage d'être une page traduite pour pouvoir l'utiliser.
Ce qui fait planter `get_absolute_url` pour des problèmes d'héritage des
pages parentes (qui sont, elles, traduites).
Le seul moyen trouvé pour résoudre ce problème est de faire une autre
fonction à qui on fournit request en argument (donc pas un override de
get_absolute_url).
TODO : vérifier si ces problèmes ont été résolus dans les màj de wagtail
et modeltranslation
"""
def debugged_get_url(self, request):
parent = COFRootPage.objects.parent_of(self).live().first()
burl = parent.relative_url(request.site)
return burl + self.slug
class Meta:
verbose_name = "Page utilitaire"
verbose_name_plural = "Pages utilitaires"

View file

@ -3,8 +3,8 @@
{% for item in menu_items %} {% for item in menu_items %}
<li class="{{ item.active_class }}"> <li class="{{ item.active_class }}">
{% if item.link_page %} {% if item.link_page %}
<a href="{% pageurl item.link_page.specific %}"> <a href="{% pageurl item.link_page %}">
{{ item.link_page.specific.title }} {{ item.link_page.title }}
</a> </a>
{% else %} {% else %}
<a href="{{ item.href }}"> <a href="{{ item.href }}">

View file

@ -4,7 +4,7 @@ from django import template
from django.utils import formats, timezone from django.utils import formats, timezone
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from ..models import COFActuPage, COFUtilPage from ..models import COFActuPage, COFRootPage
register = template.Library() register = template.Library()
@ -71,11 +71,11 @@ def calendar(context, month=None, year=None):
# Calendar next/prev urls # Calendar next/prev urls
try: try:
utilpage = COFUtilPage.objects.live()[0] utilpage = COFRootPage.objects.live()[0]
except COFUtilPage.DoesNotExist: except COFRootPage.DoesNotExist:
utilpage = None utilpage = None
request = context["request"] request = context["request"]
burl = utilpage.debugged_get_url(request) + "/" burl = utilpage.get_url(request)
prev_url = burl + utilpage.reverse_subpage( prev_url = burl + utilpage.reverse_subpage(
"calendar", args=[str(prev_month.year), str(prev_month.month)] "calendar", args=[str(prev_month.year), str(prev_month.month)]
) )

View file

@ -1,5 +1,5 @@
from modeltranslation.decorators import register from modeltranslation.decorators import register
from wagtail_modeltranslation.translator import WagtailTranslationOptions from modeltranslation.translator import TranslationOptions
from .models import ( from .models import (
COFActuIndexPage, COFActuIndexPage,
@ -12,30 +12,30 @@ from .models import (
@register(COFRootPage) @register(COFRootPage)
class COFRootPageTr(WagtailTranslationOptions): class COFRootPageTr(TranslationOptions):
fields = ("introduction",) fields = ("introduction",)
@register(COFPage) @register(COFPage)
class COFPageTr(WagtailTranslationOptions): class COFPageTr(TranslationOptions):
fields = ("body",) fields = ("body",)
@register(COFActuIndexPage) @register(COFActuIndexPage)
class COFActuIndexPageTr(WagtailTranslationOptions): class COFActuIndexPageTr(TranslationOptions):
fields = () fields = ()
@register(COFActuPage) @register(COFActuPage)
class COFActuPageTr(WagtailTranslationOptions): class COFActuPageTr(TranslationOptions):
fields = ("chapo", "body") fields = ("chapo", "body")
@register(COFDirectoryPage) @register(COFDirectoryPage)
class COFDirectoryPageTr(WagtailTranslationOptions): class COFDirectoryPageTr(TranslationOptions):
fields = ("introduction",) fields = ("introduction",)
@register(COFDirectoryEntryPage) @register(COFDirectoryEntryPage)
class COFDirectoryEntryPageTr(WagtailTranslationOptions): class COFDirectoryEntryPageTr(TranslationOptions):
fields = ("body", "links") fields = ("body", "links")

View file

@ -1,6 +1,6 @@
from django.contrib.staticfiles.templatetags.staticfiles import static from django.contrib.staticfiles.templatetags.staticfiles import static
from django.utils.html import format_html from django.utils.html import format_html
from wagtail.wagtailcore import hooks from wagtail.core import hooks
@hooks.register("insert_editor_css") @hooks.register("insert_editor_css")

View file

@ -1,7 +1,7 @@
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
from django.core.management import call_command from django.core.management import call_command
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from wagtail.wagtailcore.models import Page, Site from wagtail.core.models import Page, Site
class Command(BaseCommand): class Command(BaseCommand):

View file

@ -2,9 +2,9 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import django.db.models.deletion import django.db.models.deletion
import wagtail.wagtailcore.blocks import wagtail.core.blocks
import wagtail.wagtailcore.fields import wagtail.core.fields
import wagtail.wagtailsnippets.blocks import wagtail.snippets.blocks
from django.db import migrations, models from django.db import migrations, models
import kfet.cms.models import kfet.cms.models
@ -42,22 +42,22 @@ class Migration(migrations.Migration):
), ),
( (
"content", "content",
wagtail.wagtailcore.fields.StreamField( wagtail.core.fields.StreamField(
( (
( (
"rich", "rich",
wagtail.wagtailcore.blocks.RichTextBlock( wagtail.core.blocks.RichTextBlock(
label="Éditeur" label="Éditeur"
), ),
), ),
("carte", kfet.cms.models.MenuBlock()), ("carte", kfet.cms.models.MenuBlock()),
( (
"group_team", "group_team",
wagtail.wagtailcore.blocks.StructBlock( wagtail.core.blocks.StructBlock(
( (
( (
"show_only", "show_only",
wagtail.wagtailcore.blocks.IntegerBlock( wagtail.core.blocks.IntegerBlock(
help_text="Nombre initial de membres affichés. Laisser vide pour tou-te-s les afficher.", help_text="Nombre initial de membres affichés. Laisser vide pour tou-te-s les afficher.",
required=False, required=False,
label="Montrer seulement", label="Montrer seulement",
@ -65,8 +65,8 @@ class Migration(migrations.Migration):
), ),
( (
"members", "members",
wagtail.wagtailcore.blocks.ListBlock( wagtail.core.blocks.ListBlock(
wagtail.wagtailsnippets.blocks.SnippetChooserBlock( wagtail.snippets.blocks.SnippetChooserBlock(
kfet.cms.models.MemberTeam kfet.cms.models.MemberTeam
), ),
classname="team-group", classname="team-group",
@ -78,22 +78,22 @@ class Migration(migrations.Migration):
), ),
( (
"group", "group",
wagtail.wagtailcore.blocks.StreamBlock( wagtail.core.blocks.StreamBlock(
( (
( (
"rich", "rich",
wagtail.wagtailcore.blocks.RichTextBlock( wagtail.core.blocks.RichTextBlock(
label="Éditeur" label="Éditeur"
), ),
), ),
("carte", kfet.cms.models.MenuBlock()), ("carte", kfet.cms.models.MenuBlock()),
( (
"group_team", "group_team",
wagtail.wagtailcore.blocks.StructBlock( wagtail.core.blocks.StructBlock(
( (
( (
"show_only", "show_only",
wagtail.wagtailcore.blocks.IntegerBlock( wagtail.core.blocks.IntegerBlock(
help_text="Nombre initial de membres affichés. Laisser vide pour tou-te-s les afficher.", help_text="Nombre initial de membres affichés. Laisser vide pour tou-te-s les afficher.",
required=False, required=False,
label="Montrer seulement", label="Montrer seulement",
@ -101,8 +101,8 @@ class Migration(migrations.Migration):
), ),
( (
"members", "members",
wagtail.wagtailcore.blocks.ListBlock( wagtail.core.blocks.ListBlock(
wagtail.wagtailsnippets.blocks.SnippetChooserBlock( wagtail.snippets.blocks.SnippetChooserBlock(
kfet.cms.models.MemberTeam kfet.cms.models.MemberTeam
), ),
classname="team-group", classname="team-group",

View file

@ -1,17 +1,17 @@
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from wagtail.wagtailadmin.edit_handlers import ( from wagtail.admin.edit_handlers import (
FieldPanel, FieldPanel,
FieldRowPanel, FieldRowPanel,
MultiFieldPanel, MultiFieldPanel,
StreamFieldPanel, StreamFieldPanel,
) )
from wagtail.wagtailcore import blocks from wagtail.core import blocks
from wagtail.wagtailcore.fields import StreamField from wagtail.core.fields import StreamField
from wagtail.wagtailcore.models import Page from wagtail.core.models import Page
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.wagtailsnippets.blocks import SnippetChooserBlock from wagtail.snippets.blocks import SnippetChooserBlock
from wagtail.wagtailsnippets.models import register_snippet from wagtail.snippets.models import register_snippet
from kfet.cms.context_processors import get_articles from kfet.cms.context_processors import get_articles

11
kfet/cms/translation.py Normal file
View file

@ -0,0 +1,11 @@
from modeltranslation.decorators import register
from modeltranslation.translator import TranslationOptions
from .models import (
KFetPage,
)
@register(KFetPage)
class KFetPageTr(TranslationOptions):
fields = []

View file

@ -4,6 +4,7 @@
set -e set -e
python manage.py migrate python manage.py migrate
python manage.py sync_page_translation_fields
python manage.py loaddata gestion sites articles python manage.py loaddata gestion sites articles
python manage.py loaddevdata python manage.py loaddevdata
python manage.py syncmails gestioncof/management/data/custommail.json python manage.py syncmails gestioncof/management/data/custommail.json

View file

@ -20,9 +20,9 @@ git+https://git.eleves.ens.fr/cof-geek/django_custommail.git#egg=django_customma
ldap3 ldap3
channels==1.1.5 channels==1.1.5
python-dateutil python-dateutil
wagtail==1.11.* wagtail==2.3.*
wagtailmenus==2.2.* wagtailmenus==2.12.*
wagtail-modeltranslation==0.6.0rc2 wagtail-modeltranslation==0.9.*
django-cors-headers==2.2.0 django-cors-headers==2.2.0
# Production tools # Production tools