Skip to content

Commit

Permalink
Catch identical attraction/feature slugs
Browse files Browse the repository at this point in the history
If someone creates an attraction that results in an identical slug, they would get a giant error instead of a user-friendly error message. We now catch this edge-case.
  • Loading branch information
kitsuta committed Jan 4, 2025
1 parent 822cbac commit 2d4ed86
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions uber/model_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import cherrypy
import phonenumbers
from pockets.autolog import log
from pockets import sluggify
from sqlalchemy import and_, func, or_

from uber.badge_funcs import get_real_badge_type
Expand Down Expand Up @@ -713,12 +714,31 @@ def none_is_none_granular_rating(app):
('description', 'Description')
]

@validation.Attraction
def slug_not_existing(attraction):
with Session() as session:
slug = sluggify(attraction.name)
if session.query(Attraction).filter(Attraction.id != attraction.id,
Attraction.slug == slug).first():
return f"Another attraction has an identical URL to this one ({slug}). \
Please make sure this attraction's name is different from others, not including punctuation."

AttractionFeature.required = [
('name', 'Name'),
('description', 'Description')
]


@validation.AttractionFeature
def slug_not_existing(feature):
with Session() as session:
slug = sluggify(feature.name)
if session.query(AttractionFeature).filter(AttractionFeature.id != feature.id,
AttractionFeature.slug == slug).first():
return f"Another attraction feature has an identical URL to this one ({slug}). \
Please make sure this feature's name is different from others, not including punctuation."


@validation.AttractionEvent
def at_least_one_slot(event):
if event.slots < 1:
Expand Down

0 comments on commit 2d4ed86

Please sign in to comment.