From 2d4ed86dc028c2b2433daa9ca9fcc79d4d0daadf Mon Sep 17 00:00:00 2001 From: Victoria Earl Date: Fri, 3 Jan 2025 23:56:56 -0500 Subject: [PATCH] Catch identical attraction/feature slugs 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. --- uber/model_checks.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/uber/model_checks.py b/uber/model_checks.py index 6e1532573..038b93a5d 100644 --- a/uber/model_checks.py +++ b/uber/model_checks.py @@ -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 @@ -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: