Skip to content

Make 'default_version` field as readonly if no active versions are found. #5374

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

Merged
merged 1 commit into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,13 @@ def __init__(self, *args, **kwargs):
)

active_versions = self.get_all_active_versions()
self.fields['default_version'].widget = forms.Select(
choices=active_versions,
)

if active_versions:
self.fields['default_version'].widget = forms.Select(
choices=active_versions,
)
else:
self.fields['default_version'].widget.attrs['readonly'] = True

def clean_conf_py_file(self):
filename = self.cleaned_data.get('conf_py_file', '').strip()
Expand All @@ -269,7 +273,7 @@ def get_all_active_versions(self):
version_qs = sort_version_aware(version_qs)
all_versions = [(version.slug, version.verbose_name) for version in version_qs]
return all_versions
return [()]
return None


class UpdateProjectForm(
Expand Down
11 changes: 11 additions & 0 deletions readthedocs/rtd_tests/tests/test_project_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,17 @@ def test_list_all_versions_on_default_branch(self):
},
)

def test_default_version_field_if_no_active_version(self):
project_1 = get(Project)
project_1.versions.filter(active=True).update(active=False)

# No active versions of project exists
self.assertFalse(project_1.versions.filter(active=True).exists())

form = ProjectAdvancedForm(instance=project_1)
self.assertTrue(form.fields['default_version'].widget.attrs['readonly'])
self.assertEqual(form.fields['default_version'].initial, 'latest')


class TestTranslationForms(TestCase):

Expand Down