-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Fix the form for adopting a project #4721
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
Fix the form for adopting a project #4721
Conversation
@stsewd Please review. |
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.
Thanks, but this isn't the solution we want. We need still need to request a project slug, because a project name isn't unique. What we want is to validate this on the form https://github.com/rtfd/readthedocs.org/blob/35695d170ec7e1dfa2553bf70bc406e7c960409a/readthedocs/gold/forms.py#L81-L96
And also add a test for this
@stsewd It's still unclear to me. This is what I am getting till now. |
Yeah, that's it |
@stsewd okay, Working on it. |
I think right now we just have |
@stsewd yeahh, adding a help text would be great. Some people might also not know the meaning of the SLUG, so it will be helpful. |
@stsewd Please review. |
readthedocs/gold/forms.py
Outdated
@@ -90,7 +91,13 @@ def __init__(self, *args, **kwargs): | |||
|
|||
def clean(self): | |||
cleaned_data = super(GoldProjectForm, self).clean() | |||
project_slug = cleaned_data.get('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.
please use single quotes
readthedocs/gold/forms.py
Outdated
self.add_error(None, 'You already have the max number of supported projects.') | ||
# Checking if the project with the entered slug | ||
# is present in the database or not | ||
if Project.objects.filter(slug=project_slug).exists(): |
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.
Maybe this fits better on a clean_project
method?
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.
yeahh... that will be better.
I have implemented it.
readthedocs/gold/forms.py
Outdated
if Project.objects.filter(slug=project_slug).exists(): | ||
return cleaned_data | ||
if project_slug: | ||
self.add_error(None, "No project found.") |
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.
Single quotes
@stsewd Please review. |
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.
Almost done, just some more changes!
readthedocs/gold/forms.py
Outdated
project_instance = Project.objects.filter(slug=project_slug) | ||
|
||
# Checking if the project with the entered slug | ||
# is absent or present in the database. |
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.
We don't need this comment, is clear what we are checking
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.
Working on it.
readthedocs/gold/forms.py
Outdated
@@ -88,6 +89,18 @@ def __init__(self, *args, **kwargs): | |||
self.projects = kwargs.pop('projects', None) | |||
super(GoldProjectForm, self).__init__(*args, **kwargs) | |||
|
|||
def clean_project(self): | |||
cleaned_data = super(GoldProjectForm, self).clean() |
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.
You actually don't need to call to this method here, you can just use cleaned_data like 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.
Wokring on it.
readthedocs/gold/forms.py
Outdated
# Checking if the project with the entered slug | ||
# is absent or present in the database. | ||
if not project_instance.exists(): | ||
raise forms.ValidationError('No project found.') |
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.
We need support translation for this message (using _(msg)
) (like the above code)
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.
Yeah, that's it
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.
thanks.
though i deleted my comment before seeing your comment.
@stsewd I have made the changes, please review it again. |
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.
Looks good, thanks! Just left one comment to improve the test.
@@ -26,6 +26,11 @@ def test_adding_projects(self): | |||
self.assertEqual(self.golduser.projects.count(), 1) | |||
self.assertEqual(resp.status_code, 302) | |||
|
|||
def test_incorrect_input_when_adding_projects(self): | |||
self.assertEqual(self.golduser.projects.count(), 0) | |||
resp = self.client.post(reverse('gold_projects'), data={'project': 'random-incorrect-slug'}) |
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.
Would be good to have an assert about that random-incorrect-slug
doesn't exists on the db
@stsewd Added the improvement. |
This looks good. 👍
Sounds like a good issue to file. |
Fixes #4711