From 08fae0d0dcd7a95fc5603ff1f396075ed5a78a35 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 25 Jan 2023 13:13:42 -0600 Subject: [PATCH] Add slug validator for org --- .../0146_alter_organization_slug.py | 29 +++++++++++++++++++ judge/models/profile.py | 3 ++ 2 files changed, 32 insertions(+) create mode 100644 judge/migrations/0146_alter_organization_slug.py diff --git a/judge/migrations/0146_alter_organization_slug.py b/judge/migrations/0146_alter_organization_slug.py new file mode 100644 index 0000000..dbd475d --- /dev/null +++ b/judge/migrations/0146_alter_organization_slug.py @@ -0,0 +1,29 @@ +# Generated by Django 3.2.16 on 2023-01-25 19:12 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("judge", "0145_alter_organization_slug"), + ] + + operations = [ + migrations.AlterField( + model_name="organization", + name="slug", + field=models.SlugField( + help_text="Organization name shown in URL", + max_length=128, + unique=True, + validators=[ + django.core.validators.RegexValidator( + "^[-a-zA-Z0-9]+$", "Only alphanumeric and hyphens" + ) + ], + verbose_name="organization slug", + ), + ), + ] diff --git a/judge/models/profile.py b/judge/models/profile.py index d14f9b8..79b6ad8 100644 --- a/judge/models/profile.py +++ b/judge/models/profile.py @@ -34,6 +34,9 @@ class Organization(models.Model): verbose_name=_("organization slug"), help_text=_("Organization name shown in URL"), unique=True, + validators=[ + RegexValidator("^[-a-zA-Z0-9]+$", _("Only alphanumeric and hyphens")) + ], ) short_name = models.CharField( max_length=20,