-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Additional validation when changing the project language #3790
Additional validation when changing the project language #3790
Conversation
5fe1985
to
c6b5763
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great addition! I'm really happy we're able to address some of these problems around translations.
I noted a couple changes here, but looks good otherwise.
readthedocs/projects/forms.py
Outdated
if main_project and main_project.language == language: | ||
msg = ( | ||
'The translation can not have the same ' | ||
'language as the parent.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So two things:
- We should also be testing for overlapping languages in sibling translations. That is, we should be checking for
project.main_language_project.translations
- I think we can reduce all the error messages to something more clear:
There is already a {lang} translation for the {proj} project
self.assertIn( | ||
'The translation can not have the same language', | ||
''.join(form.errors['language']) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, we should test for sibling projects.
c6b5763
to
453be3b
Compare
That test shouldn't pass, I'm going to add one more test |
@agjohnson done, I forgot about checking the siblings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good!
Take a look at my comment regarding the form used. Besides the test, could you make a simple QA manually to check if it's working as you expect in your local instance?
This is one of the things that I don't like when only testing the forms and not the real request to the view. I'd like if you also add a test that make the real request to this private url.
readthedocs/projects/forms.py
Outdated
.exclude(pk=project.pk) | ||
.exists()) | ||
if siblings: | ||
raise forms.ValidationError(format_msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, the project
in the message, shouldn't be main_project
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, all the messages here point to the current project. Should I change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is, mentioning project
will the messsage still be valid?
Which is the case of this validation error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take this from #3790 (comment)
I think is kind of unnecessary to show the project here, right? Maybe just There is already a "{lang}" translation for this project.
is enough, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think mentioning the project is a good idea, I'm +1 on altering the message to reference main_project
.
readthedocs/projects/forms.py
Outdated
@@ -175,6 +175,29 @@ class Meta(object): | |||
widget=forms.Textarea, | |||
) | |||
|
|||
def clean_language(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not the form you want.
ProjectExtraForm
is used when importing a project via the Wizard. You need to write this logic in UpdateProjectForm
which is the one used under https://readthedocs.org/dashboard/{project_slug}/edit/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was in doubt where to put it (in case it was reused on others parts). And since the ProjectExtraForm
has the language
field.
99a23dc
to
634dbec
Compare
9fcb9bb
to
49e3744
Compare
@humitos done, I have added some test with manual requests. Also, I did a manual test in my instance, works as expected. I just need a answer for #3790 (comment) |
I agree with @humitos on the error message, otherwise this looks good to me! My original feedback has been addressed. |
@agjohnson done |
This looks like a solid addition. Merging it. 👍 |
Closes #3778