Skip to content

Commit

Permalink
Validate for sibblings
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd committed Mar 16, 2018
1 parent cf87a16 commit 453be3b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,19 @@ def clean_language(self):
language = self.cleaned_data['language']
project = self.instance
if project:
msg = _(
'There is already a "{lang}" translation '
'for the {proj} project.'
)
format_msg = msg.format(lang=language, proj=project.slug)
if project.translations.filter(language=language).exists():
msg = 'There is a translation for the "{lang}" language.'
raise forms.ValidationError(
_(msg).format(lang=language)
)
raise forms.ValidationError(format_msg)
main_project = project.main_language_project
if main_project and main_project.language == language:
msg = (
'The translation can not have the same '
'language as the parent.'
)
raise forms.ValidationError(_(msg))
if main_project:
if main_project.language == language:
raise forms.ValidationError(format_msg)
if main_project.translations.filter(language=language).exists():
raise forms.ValidationError(format_msg)
return language


Expand Down

0 comments on commit 453be3b

Please sign in to comment.