dnscms: improve venue selection for event occurrences

This commit is contained in:
2026-05-26 01:57:04 +02:00
parent 089970a5cd
commit ec94d82863
2 changed files with 38 additions and 1 deletions
+10 -1
View File
@@ -478,7 +478,7 @@ class EventOccurrence(Orderable):
), ),
FieldRowPanel( FieldRowPanel(
children=[ children=[
FieldPanel("venue", heading=_("Venue")), FieldPanel("venue", heading=_("Venue"), widget=forms.Select),
FieldPanel("venue_custom", heading=_("Venue as free text")), FieldPanel("venue_custom", heading=_("Venue as free text")),
], ],
), ),
@@ -492,6 +492,15 @@ class EventOccurrence(Orderable):
] ]
def clean(self): def clean(self):
if self.venue_custom:
trimmed = self.venue_custom.strip()
self.venue_custom = trimmed
if trimmed:
match = VenuePage.objects.filter(title=trimmed).first()
if match:
self.venue = match
self.venue_custom = ""
if self.venue and self.venue_custom: if self.venue and self.venue_custom:
raise ValidationError( raise ValidationError(
{ {
+28
View File
@@ -104,6 +104,34 @@ def test_eventoccurrence_clean_rejects_both_venue_and_venue_custom(event_index,
assert "venue_custom" in exc.value.message_dict assert "venue_custom" in exc.value.message_dict
def test_eventoccurrence_clean_promotes_matching_custom_text_to_venue(event_index, venue):
event = EventPageFactory(parent=event_index)
occurrence = EventOccurrence(
event=event,
start=timezone.now(),
venue_custom=f" {venue.title} ",
)
occurrence.clean()
assert occurrence.venue_id == venue.pk
assert occurrence.venue_custom == ""
def test_eventoccurrence_clean_keeps_custom_text_when_no_venue_matches(event_index):
event = EventPageFactory(parent=event_index)
occurrence = EventOccurrence(
event=event,
start=timezone.now(),
venue_custom=" Frederikkeplassen ",
)
occurrence.clean()
assert occurrence.venue is None
assert occurrence.venue_custom == "Frederikkeplassen"
def test_eventoccurrence_clean_requires_venue_or_venue_custom(event_index): def test_eventoccurrence_clean_requires_venue_or_venue_custom(event_index):
event = EventPageFactory(parent=event_index) event = EventPageFactory(parent=event_index)
occurrence = EventOccurrence(event=event, start=timezone.now()) occurrence = EventOccurrence(event=event, start=timezone.now())