Skip to content

Commit

Permalink
Fix organization prefix to include alphanumeric characters (#345)
Browse files Browse the repository at this point in the history
Previously, only alphabetic characters are included.
  • Loading branch information
trantuyet authored Oct 17, 2023
1 parent b676c30 commit 2d2224a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions judge/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def clean_code(self):
if self.org_pk is None:
return code
org = Organization.objects.get(pk=self.org_pk)
prefix = ''.join(x for x in org.slug.lower() if x.isalpha()) + '_'
prefix = ''.join(x for x in org.slug.lower() if x.isalnum()) + '_'
if not code.startswith(prefix):
raise forms.ValidationError(_('Problem id code must starts with `%s`') % (prefix, ),
'problem_id_invalid_prefix')
Expand Down Expand Up @@ -692,7 +692,7 @@ def clean_key(self):
if self.org_pk is None:
return key
org = Organization.objects.get(pk=self.org_pk)
prefix = ''.join(x for x in org.slug.lower() if x.isalpha()) + '_'
prefix = ''.join(x for x in org.slug.lower() if x.isalnum()) + '_'
if not key.startswith(prefix):
raise forms.ValidationError(_('Contest id must starts with `%s`') % (prefix, ),
'contest_id_invalid_prefix')
Expand Down
6 changes: 3 additions & 3 deletions judge/views/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ class ProblemCreateOrganization(AdminOrganizationMixin, ProblemCreate):
def get_initial(self):
initial = super(ProblemCreateOrganization, self).get_initial()
initial = initial.copy()
initial['code'] = ''.join(x for x in self.organization.slug.lower() if x.isalpha()) + '_'
initial['code'] = ''.join(x for x in self.organization.slug.lower() if x.isalnum()) + '_'
return initial

def get_form_kwargs(self):
Expand Down Expand Up @@ -644,7 +644,7 @@ def form_valid(self, form):
with revisions.create_revision(atomic=True):
post = form.save()
post.authors.add(self.request.user.profile)
post.slug = ''.join(x for x in self.organization.slug.lower() if x.isalpha()) # Initial post slug
post.slug = ''.join(x for x in self.organization.slug.lower() if x.isalnum()) # Initial post slug
post.organization = self.organization
post.save()

Expand All @@ -660,7 +660,7 @@ class ContestCreateOrganization(AdminOrganizationMixin, CreateContest):
def get_initial(self):
initial = super(ContestCreateOrganization, self).get_initial()
initial = initial.copy()
initial['key'] = ''.join(x for x in self.organization.slug.lower() if x.isalpha()) + '_'
initial['key'] = ''.join(x for x in self.organization.slug.lower() if x.isalnum()) + '_'
return initial

def get_form_kwargs(self):
Expand Down

0 comments on commit 2d2224a

Please sign in to comment.