dnscms: better organizer chooser, fixes slugs for organizers, better slugs
This commit is contained in:
+19
-1
@@ -1,6 +1,24 @@
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from wagtail.admin.forms import WagtailAdminModelForm
|
||||
from wagtail.admin.viewsets.chooser import ChooserViewSet
|
||||
|
||||
from dnscms.utils import slugify
|
||||
from events.models import EventOrganizer
|
||||
|
||||
|
||||
class EventOrganizerCreationForm(WagtailAdminModelForm):
|
||||
class Meta:
|
||||
model = EventOrganizer
|
||||
fields = ["name", "association", "external_url"]
|
||||
|
||||
def save(self, commit=True):
|
||||
instance = super().save(commit=False)
|
||||
if not instance.slug:
|
||||
instance.slug = slugify(instance.name)
|
||||
if commit:
|
||||
instance.save()
|
||||
return instance
|
||||
|
||||
|
||||
class EventOrganizerChooserViewSet(ChooserViewSet):
|
||||
model = "events.EventOrganizer"
|
||||
@@ -10,7 +28,7 @@ class EventOrganizerChooserViewSet(ChooserViewSet):
|
||||
choose_one_text = _("Choose an organizer")
|
||||
choose_another_text = _("Choose another organizer")
|
||||
edit_item_text = _("Edit this organizer")
|
||||
form_fields = ["name", "association", "external_url"]
|
||||
creation_form_class = EventOrganizerCreationForm
|
||||
|
||||
|
||||
event_organizer_chooser_viewset = EventOrganizerChooserViewSet("event_organizer_chooser")
|
||||
|
||||
Reference in New Issue
Block a user