Add custom module form with custom clean method
Relates to MS-758
This commit is contained in:
parent
dbec89ca8d
commit
2e5fa555d6
|
|
@ -1,8 +1,10 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django import forms
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
from wagtail.admin.panels import FieldPanel, TabbedInterface, ObjectList
|
from wagtail.admin.panels import FieldPanel, TabbedInterface, ObjectList
|
||||||
from wagtail.fields import RichTextField
|
from wagtail.fields import RichTextField
|
||||||
|
from wagtail.admin.forms import WagtailAdminPageForm
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from core.constants import DEFAULT_RICH_TEXT_FEATURES
|
from core.constants import DEFAULT_RICH_TEXT_FEATURES
|
||||||
from core.wagtail_utils import StrictHierarchyPage, get_default_settings
|
from core.wagtail_utils import StrictHierarchyPage, get_default_settings
|
||||||
|
|
@ -42,6 +44,22 @@ class ModuleCategory(models.Model):
|
||||||
return f"{self.name}"
|
return f"{self.name}"
|
||||||
|
|
||||||
|
|
||||||
|
class ModulePageForm(WagtailAdminPageForm):
|
||||||
|
def clean(self):
|
||||||
|
cleaned_data = super().clean()
|
||||||
|
if "slug" in self.cleaned_data:
|
||||||
|
page_slug = cleaned_data["slug"]
|
||||||
|
if not Module._slug_is_available(page_slug, self.instance):
|
||||||
|
self.add_error(
|
||||||
|
"slug",
|
||||||
|
forms.ValidationError(
|
||||||
|
_("The slug '%(page_slug)s' is already in use")
|
||||||
|
% {"page_slug": page_slug}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return cleaned_data
|
||||||
|
|
||||||
|
|
||||||
class Module(StrictHierarchyPage):
|
class Module(StrictHierarchyPage):
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Modul"
|
verbose_name = "Modul"
|
||||||
|
|
@ -81,6 +99,7 @@ class Module(StrictHierarchyPage):
|
||||||
FieldPanel("teaser"),
|
FieldPanel("teaser"),
|
||||||
FieldPanel("intro"),
|
FieldPanel("intro"),
|
||||||
]
|
]
|
||||||
|
base_form_class = ModulePageForm
|
||||||
|
|
||||||
edit_handler = TabbedInterface(
|
edit_handler = TabbedInterface(
|
||||||
[ObjectList(content_panels, heading="Content"), get_default_settings()]
|
[ObjectList(content_panels, heading="Content"), get_default_settings()]
|
||||||
|
|
@ -150,6 +169,13 @@ class Module(StrictHierarchyPage):
|
||||||
def get_admin_display_title(self):
|
def get_admin_display_title(self):
|
||||||
return f"{self.meta_title} - {self.title}"
|
return f"{self.meta_title} - {self.title}"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _slug_is_available(slug, page):
|
||||||
|
# modeled after `Page._slug_is_available`
|
||||||
|
modules = Module.objects.filter(slug=slug).not_page(page)
|
||||||
|
|
||||||
|
return not modules.exists()
|
||||||
|
|
||||||
|
|
||||||
class RecentModule(models.Model):
|
class RecentModule(models.Model):
|
||||||
module = models.ForeignKey(
|
module = models.ForeignKey(
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ from wagtail.models import Locale
|
||||||
from api.utils import get_object
|
from api.utils import get_object
|
||||||
from core.logger import get_logger
|
from core.logger import get_logger
|
||||||
from .connections import TopicConnection, ModuleConnection
|
from .connections import TopicConnection, ModuleConnection
|
||||||
<<<<<<< HEAD
|
|
||||||
from .nodes import (
|
from .nodes import (
|
||||||
ContentBlockNode,
|
ContentBlockNode,
|
||||||
ChapterNode,
|
ChapterNode,
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2023-04-12 13:50+0000\n"
|
"POT-Creation-Date: 2023-08-23 13:04+0000\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
|
@ -22,7 +22,7 @@ msgstr ""
|
||||||
msgid "assignment"
|
msgid "assignment"
|
||||||
msgstr "Auftrag"
|
msgstr "Auftrag"
|
||||||
|
|
||||||
#: assignments/models.py:52 books/models/module.py:49
|
#: assignments/models.py:52
|
||||||
msgid "assignments"
|
msgid "assignments"
|
||||||
msgstr "Aufträge"
|
msgstr "Aufträge"
|
||||||
|
|
||||||
|
|
@ -56,45 +56,23 @@ msgstr "instrumente"
|
||||||
msgid "Instruments"
|
msgid "Instruments"
|
||||||
msgstr "Instrumente"
|
msgstr "Instrumente"
|
||||||
|
|
||||||
#: books/models/module.py:43
|
#: books/models/module.py:30
|
||||||
msgid "Assignment"
|
|
||||||
msgstr "Auftrag"
|
|
||||||
|
|
||||||
#: books/models/module.py:45
|
|
||||||
#| msgid "assignments"
|
|
||||||
msgid "linked assignments"
|
|
||||||
msgstr "Verlinkte Aufträge"
|
|
||||||
|
|
||||||
#: books/models/module.py:47 books/models/module.py:57
|
|
||||||
#, python-format
|
#, python-format
|
||||||
msgid ""
|
msgid "The slug '%(page_slug)s' is already in use"
|
||||||
"These %s are automatically linked, they are shown here only to provide an "
|
msgstr "Der Slug '%(page_slug)s' wird bereits verwendet"
|
||||||
"overview. Please don't change anything here."
|
|
||||||
msgstr ""
|
|
||||||
"Diese %s sind automatisch verlinkt, sie werden hier als Übersicht angezeigt. "
|
|
||||||
"Bitte hier nichts verändern."
|
|
||||||
|
|
||||||
#: books/models/module.py:53
|
#: core/settings.py:197
|
||||||
#| msgid "surveys"
|
|
||||||
msgid "linked surveys"
|
|
||||||
msgstr "Verlinkte Surveys"
|
|
||||||
|
|
||||||
#: books/models/module.py:54
|
|
||||||
msgid "Survey"
|
|
||||||
msgstr "Survey"
|
|
||||||
|
|
||||||
#: books/models/module.py:59
|
|
||||||
msgid "surveys"
|
|
||||||
msgstr "Übungen"
|
|
||||||
|
|
||||||
#: core/settings.py:193
|
|
||||||
msgid "German"
|
msgid "German"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: core/settings.py:194
|
#: core/settings.py:198
|
||||||
msgid "English"
|
msgid "English"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: core/settings.py:199
|
||||||
|
msgid "French"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: core/templates/registration/login.html:9
|
#: core/templates/registration/login.html:9
|
||||||
msgid "Melden Sie sich jetzt an."
|
msgid "Melden Sie sich jetzt an."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
@ -300,11 +278,11 @@ msgstr ""
|
||||||
msgid "Drag"
|
msgid "Drag"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: core/templates/wagtailadmin/pages/listing/_list.html:79
|
#: core/templates/wagtailadmin/pages/listing/_list.html:80
|
||||||
msgid "Edit this page"
|
msgid "Edit this page"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: core/templates/wagtailadmin/pages/listing/_list.html:106
|
#: core/templates/wagtailadmin/pages/listing/_list.html:107
|
||||||
#, python-format
|
#, python-format
|
||||||
msgid ""
|
msgid ""
|
||||||
"%(time_period)s\n"
|
"%(time_period)s\n"
|
||||||
|
|
@ -327,7 +305,7 @@ msgstr ""
|
||||||
msgid "News Article URL"
|
msgid "News Article URL"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: news/models.py:12
|
#: news/models.py:13
|
||||||
msgid "Image Source"
|
msgid "Image Source"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
@ -367,6 +345,31 @@ msgstr ""
|
||||||
msgid "Das alte Passwort muss angegeben werden"
|
msgid "Das alte Passwort muss angegeben werden"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#~ msgid "Assignment"
|
||||||
|
#~ msgstr "Auftrag"
|
||||||
|
|
||||||
|
#~| msgid "assignments"
|
||||||
|
#~ msgid "linked assignments"
|
||||||
|
#~ msgstr "Verlinkte Aufträge"
|
||||||
|
|
||||||
|
#, python-format
|
||||||
|
#~ msgid ""
|
||||||
|
#~ "These %s are automatically linked, they are shown here only to provide an "
|
||||||
|
#~ "overview. Please don't change anything here."
|
||||||
|
#~ msgstr ""
|
||||||
|
#~ "Diese %s sind automatisch verlinkt, sie werden hier als Übersicht "
|
||||||
|
#~ "angezeigt. Bitte hier nichts verändern."
|
||||||
|
|
||||||
|
#~| msgid "surveys"
|
||||||
|
#~ msgid "linked surveys"
|
||||||
|
#~ msgstr "Verlinkte Surveys"
|
||||||
|
|
||||||
|
#~ msgid "Survey"
|
||||||
|
#~ msgstr "Survey"
|
||||||
|
|
||||||
|
#~ msgid "surveys"
|
||||||
|
#~ msgstr "Übungen"
|
||||||
|
|
||||||
#~ msgid "Assignments"
|
#~ msgid "Assignments"
|
||||||
#~ msgstr "Aufträge"
|
#~ msgstr "Aufträge"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue