Skip to content

Commit

Permalink
Merge branch 'apluslms:master' into news_languages
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelGusse authored Mar 19, 2024
2 parents a4ed9b6 + d00b501 commit 12099c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions course/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ class CourseInstance(CourseInstanceProto, models.Model):
('ROMAN', 2, _('NUMBERING_ROMAN')),
('HIDDEN', 3, _('NUMBERING_HIDDEN_ARABIC')),
])
RESERVED_URLS = ("instances",) # strings which cannot be used as course instance URL identifiers

course = models.ForeignKey(Course,
verbose_name=_('LABEL_COURSE'),
Expand Down Expand Up @@ -735,10 +736,9 @@ def __str__(self):
def clean(self):
super().clean()
errors = {}
RESERVED = ("instances",)
if self.instance_name in RESERVED:
if self.instance_name in self.RESERVED_URLS:
errors['instance_name'] = format_lazy(_('COURSE_INSTANCE_ERROR_INSTANCE_NAME -- {}'), self.instance_name)
if self.url in RESERVED:
if self.url in self.RESERVED_URLS:
errors['url'] = format_lazy(_('COURSE_INSTANCE_ERROR_URL -- {}'), self.url)
if self.ending_time and self.starting_time and self.ending_time <= self.starting_time:
errors['ending_time'] = _('COURSE_INSTANCE_ERROR_ENDING_TIME_BEFORE_STARTING')
Expand Down
2 changes: 2 additions & 0 deletions edit_course/course_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ def clean_url(self):
# having invalid values.
generate_url_key_validator()(self.cleaned_data['url'])
url = self.cleaned_data['url']
if url in self.instance.RESERVED_URLS:
raise ValidationError(_('ERROR_URL_ALREADY_TAKEN'))
if url != self.instance.url and CourseInstance.objects.filter(course=self.instance.course, url=url).exists():
raise ValidationError(_('ERROR_URL_ALREADY_TAKEN'))
return url
Expand Down

0 comments on commit 12099c1

Please sign in to comment.