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.messages",
"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.admindocs",
"bda",
@ -78,21 +84,20 @@ INSTALLED_APPS = [
"widget_tweaks",
"custommail",
"djconfig",
"wagtail.wagtailforms",
"wagtail.wagtailredirects",
"wagtail.wagtailembeds",
"wagtail.wagtailsites",
"wagtail.wagtailusers",
"wagtail.wagtailsnippets",
"wagtail.wagtaildocs",
"wagtail.wagtailimages",
"wagtail.wagtailsearch",
"wagtail.wagtailadmin",
"wagtail.wagtailcore",
"wagtail.contrib.forms",
"wagtail.contrib.redirects",
"wagtail.embeds",
"wagtail.sites",
"wagtail.users",
"wagtail.snippets",
"wagtail.documents",
"wagtail.images",
"wagtail.search",
"wagtail.admin",
"wagtail.core",
"wagtail.contrib.modeladmin",
"wagtail.contrib.wagtailroutablepage",
"wagtail.contrib.routable_page",
"wagtailmenus",
"wagtail_modeltranslation",
"modelcluster",
"taggit",
"kfet.auth",
@ -113,8 +118,8 @@ MIDDLEWARE = [
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django.middleware.security.SecurityMiddleware",
"djconfig.middleware.DjConfigMiddleware",
"wagtail.wagtailcore.middleware.SiteMiddleware",
"wagtail.wagtailredirects.middleware.RedirectMiddleware",
"wagtail.core.middleware.SiteMiddleware",
"wagtail.contrib.redirects.middleware.RedirectMiddleware",
"django.middleware.locale.LocaleMiddleware",
]
@ -257,3 +262,6 @@ FORMAT_MODULE_PATH = "cof.locale"
WAGTAIL_SITE_NAME = "GestioCOF"
WAGTAIL_ENABLE_UPDATE_CHECK = False
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.views.generic.base import TemplateView
from django_cas_ng import views as django_cas_views
from wagtail.wagtailadmin import urls as wagtailadmin_urls
from wagtail.wagtailcore import urls as wagtail_urls
from wagtail.wagtaildocs import urls as wagtaildocs_urls
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.core import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls
from gestioncof import csv_views, views as gestioncof_views
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.db import models
from wagtail.contrib.wagtailroutablepage.models import RoutablePageMixin, route
from wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtail.wagtailcore import blocks
from wagtail.wagtailcore.fields import RichTextField, StreamField
from wagtail.wagtailcore.models import Page
from wagtail.wagtailimages.blocks import ImageChooserBlock
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
from wagtail.contrib.routable_page.models import RoutablePageMixin, route
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
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
# Page pouvant afficher des actualités
@ -18,19 +18,26 @@ class COFActuIndexMixin:
# Racine du site du COF
class COFRootPage(Page, COFActuIndexMixin):
class COFRootPage(RoutablePageMixin, Page, COFActuIndexMixin):
introduction = RichTextField("Introduction")
content_panels = Page.content_panels + [
FieldPanel("introduction", classname="full")
]
subpage_types = ["COFActuIndexPage", "COFPage", "COFDirectoryPage", "COFUtilPage"]
subpage_types = ["COFActuIndexPage", "COFPage", "COFDirectoryPage"]
class Meta:
verbose_name = "Racine 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
class IFrameBlock(blocks.StructBlock):
@ -199,36 +206,3 @@ class COFDirectoryEntryPage(Page):
class Meta:
verbose_name = "Entrée 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 %}
<li class="{{ item.active_class }}">
{% if item.link_page %}
<a href="{% pageurl item.link_page.specific %}">
{{ item.link_page.specific.title }}
<a href="{% pageurl item.link_page %}">
{{ item.link_page.title }}
</a>
{% else %}
<a href="{{ item.href }}">

View file

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

View file

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

View file

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

View file

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

View file

@ -2,9 +2,9 @@
from __future__ import unicode_literals
import django.db.models.deletion
import wagtail.wagtailcore.blocks
import wagtail.wagtailcore.fields
import wagtail.wagtailsnippets.blocks
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.snippets.blocks
from django.db import migrations, models
import kfet.cms.models
@ -42,22 +42,22 @@ class Migration(migrations.Migration):
),
(
"content",
wagtail.wagtailcore.fields.StreamField(
wagtail.core.fields.StreamField(
(
(
"rich",
wagtail.wagtailcore.blocks.RichTextBlock(
wagtail.core.blocks.RichTextBlock(
label="Éditeur"
),
),
("carte", kfet.cms.models.MenuBlock()),
(
"group_team",
wagtail.wagtailcore.blocks.StructBlock(
wagtail.core.blocks.StructBlock(
(
(
"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.",
required=False,
label="Montrer seulement",
@ -65,8 +65,8 @@ class Migration(migrations.Migration):
),
(
"members",
wagtail.wagtailcore.blocks.ListBlock(
wagtail.wagtailsnippets.blocks.SnippetChooserBlock(
wagtail.core.blocks.ListBlock(
wagtail.snippets.blocks.SnippetChooserBlock(
kfet.cms.models.MemberTeam
),
classname="team-group",
@ -78,22 +78,22 @@ class Migration(migrations.Migration):
),
(
"group",
wagtail.wagtailcore.blocks.StreamBlock(
wagtail.core.blocks.StreamBlock(
(
(
"rich",
wagtail.wagtailcore.blocks.RichTextBlock(
wagtail.core.blocks.RichTextBlock(
label="Éditeur"
),
),
("carte", kfet.cms.models.MenuBlock()),
(
"group_team",
wagtail.wagtailcore.blocks.StructBlock(
wagtail.core.blocks.StructBlock(
(
(
"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.",
required=False,
label="Montrer seulement",
@ -101,8 +101,8 @@ class Migration(migrations.Migration):
),
(
"members",
wagtail.wagtailcore.blocks.ListBlock(
wagtail.wagtailsnippets.blocks.SnippetChooserBlock(
wagtail.core.blocks.ListBlock(
wagtail.snippets.blocks.SnippetChooserBlock(
kfet.cms.models.MemberTeam
),
classname="team-group",

View file

@ -1,17 +1,17 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from wagtail.wagtailadmin.edit_handlers import (
from wagtail.admin.edit_handlers import (
FieldPanel,
FieldRowPanel,
MultiFieldPanel,
StreamFieldPanel,
)
from wagtail.wagtailcore import blocks
from wagtail.wagtailcore.fields import StreamField
from wagtail.wagtailcore.models import Page
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
from wagtail.wagtailsnippets.blocks import SnippetChooserBlock
from wagtail.wagtailsnippets.models import register_snippet
from wagtail.core import blocks
from wagtail.core.fields import StreamField
from wagtail.core.models import Page
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.snippets.blocks import SnippetChooserBlock
from wagtail.snippets.models import register_snippet
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
python manage.py migrate
python manage.py sync_page_translation_fields
python manage.py loaddata gestion sites articles
python manage.py loaddevdata
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
channels==1.1.5
python-dateutil
wagtail==1.11.*
wagtailmenus==2.2.*
wagtail-modeltranslation==0.6.0rc2
wagtail==2.3.*
wagtailmenus==2.12.*
wagtail-modeltranslation==0.9.*
django-cors-headers==2.2.0
# Production tools