35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
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"
|
|
icon = "group"
|
|
per_page = 30
|
|
page_title = _("Choose organizers")
|
|
choose_one_text = _("Choose an organizer")
|
|
choose_another_text = _("Choose another organizer")
|
|
edit_item_text = _("Edit this organizer")
|
|
creation_form_class = EventOrganizerCreationForm
|
|
|
|
|
|
event_organizer_chooser_viewset = EventOrganizerChooserViewSet("event_organizer_chooser")
|