-
-
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
Fix the form for adopting a project #4721
Changes from 12 commits
92e5142
33048cb
0a542dd
f600593
662c2ca
1c31395
0b0e939
d35cfe0
6653e2e
0294e95
a0d8816
8a252b7
567be81
fc04ac0
886a513
728c9d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from django import forms | ||
|
||
from readthedocs.payments.forms import StripeModelForm, StripeResourceMixin | ||
from readthedocs.projects.models import Project | ||
|
||
from .models import LEVEL_CHOICES, GoldUser | ||
|
||
|
@@ -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() | ||
project_slug = cleaned_data.get('project', '') | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Working on it. |
||
if not project_instance.exists(): | ||
raise forms.ValidationError('No project found.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need support translation for this message (using There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. thanks. |
||
else: | ||
return project_slug | ||
|
||
def clean(self): | ||
cleaned_data = super(GoldProjectForm, self).clean() | ||
if self.projects.count() < self.user.num_supported_projects: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to have an assert about that |
||
self.assertFormError(resp, form='form', field='project', errors='No project found.') | ||
|
||
def test_too_many_projects(self): | ||
self.project2 = get(Project, slug='test2') | ||
|
||
|
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
https://github.com/rtfd/readthedocs.org/blob/90b1e52cfd6a124bf7298a1b3cb1711fddd67ab8/readthedocs/core/forms.py#L59-L65
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.