Skip to content

Commit 12a2144

Browse files
authored
Merge pull request #6166 from stsewd/cleanup-views
Clean up views
2 parents 72972b5 + 07bf708 commit 12a2144

File tree

7 files changed

+34
-63
lines changed

7 files changed

+34
-63
lines changed

readthedocs/builds/urls.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
# -*- coding: utf-8 -*-
2-
31
"""URL configuration for builds app."""
4-
from django.conf.urls import url
52

6-
from .views import builds_redirect_detail, builds_redirect_list
3+
from django.conf.urls import url
4+
from django.views.generic.base import RedirectView
75

86

97
urlpatterns = [
108
url(
11-
r'^(?P<project_slug>[-\w]+)/(?P<pk>\d+)/$',
12-
builds_redirect_detail,
9+
r'^(?P<project_slug>[-\w]+)/(?P<build_pk>\d+)/$',
10+
RedirectView.as_view(pattern_name='builds_detail', permanent=True),
1311
name='old_builds_detail',
1412
),
1513
url(
1614
r'^(?P<project_slug>[-\w]+)/$',
17-
builds_redirect_list,
15+
RedirectView.as_view(pattern_name='builds_project_list', permanent=True),
1816
name='old_builds_project_list',
1917
),
2018
]

readthedocs/builds/views.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1-
# -*- coding: utf-8 -*-
2-
31
"""Views for builds app."""
42

53
import logging
64
import textwrap
5+
from urllib.parse import urlparse
76

87
from django.contrib import messages
98
from django.contrib.auth.decorators import login_required
109
from django.http import (
1110
HttpResponseForbidden,
12-
HttpResponsePermanentRedirect,
1311
HttpResponseRedirect,
1412
)
1513
from django.shortcuts import get_object_or_404
1614
from django.urls import reverse
1715
from django.utils.decorators import method_decorator
1816
from django.views.generic import DetailView, ListView
1917
from requests.utils import quote
20-
from urllib.parse import urlparse
2118

22-
from readthedocs.doc_builder.exceptions import BuildEnvironmentError
2319
from readthedocs.builds.models import Build, Version
2420
from readthedocs.core.permissions import AdminPermission
2521
from readthedocs.core.utils import trigger_build
22+
from readthedocs.doc_builder.exceptions import BuildEnvironmentError
2623
from readthedocs.projects.models import Project
2724

2825

2926
log = logging.getLogger(__name__)
3027

3128

3229
class BuildBase:
30+
3331
model = Build
3432

3533
def get_queryset(self):
@@ -103,6 +101,7 @@ def get_context_data(self, **kwargs):
103101

104102

105103
class BuildDetail(BuildBase, DetailView):
104+
106105
pk_url_kwarg = 'build_pk'
107106

108107
def get_context_data(self, **kwargs):
@@ -152,18 +151,3 @@ def get_context_data(self, **kwargs):
152151
issue_url = urlparse(issue_url).geturl()
153152
context['issue_url'] = issue_url
154153
return context
155-
156-
157-
# Old build view redirects
158-
159-
160-
def builds_redirect_list(request, project_slug): # pylint: disable=unused-argument
161-
return HttpResponsePermanentRedirect(
162-
reverse('builds_project_list', args=[project_slug]),
163-
)
164-
165-
166-
def builds_redirect_detail(request, project_slug, pk): # pylint: disable=unused-argument
167-
return HttpResponsePermanentRedirect(
168-
reverse('builds_detail', args=[project_slug, pk]),
169-
)

readthedocs/core/views/hooks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44

55
from readthedocs.builds.constants import EXTERNAL
6-
from readthedocs.builds.models import Version
76
from readthedocs.core.utils import trigger_build
87
from readthedocs.projects.tasks import sync_repository_task
98

readthedocs/projects/urls/private.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# -*- coding: utf-8 -*-
2-
31
"""Project URLs for authenticated users."""
42

53
from django.conf.urls import url
4+
from django.views.generic.base import RedirectView
65

76
from readthedocs.constants import pattern_opts
87
from readthedocs.projects.backends.views import ImportDemoView, ImportWizardView
@@ -45,7 +44,8 @@
4544
name='projects_import_demo',
4645
),
4746
url(
48-
r'^(?P<project_slug>[-\w]+)/$', private.project_manage,
47+
r'^(?P<project_slug>[-\w]+)/$',
48+
RedirectView.as_view(pattern_name='projects_detail', permanent=True),
4949
name='projects_manage',
5050
),
5151
url(

readthedocs/projects/views/private.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373

7474

7575
class PrivateViewMixin(LoginRequiredMixin):
76+
7677
pass
7778

7879

@@ -110,19 +111,6 @@ def get_context_data(self, **kwargs):
110111
return context
111112

112113

113-
@login_required
114-
def project_manage(__, project_slug):
115-
"""
116-
Project management view.
117-
118-
Where you will have links to edit the projects' configuration, edit the
119-
files associated with that project, etc.
120-
121-
Now redirects to the normal /projects/<slug> view.
122-
"""
123-
return HttpResponseRedirect(reverse('projects_detail', args=[project_slug]))
124-
125-
126114
class ProjectUpdate(ProjectSpamMixin, PrivateViewMixin, UpdateView):
127115

128116
form_class = UpdateProjectForm
@@ -453,17 +441,18 @@ def get_context_data(self, **kwargs):
453441

454442

455443
class ProjectRelationshipCreate(ProjectRelationshipMixin, CreateView):
444+
456445
pass
457446

458447

459448
class ProjectRelationshipUpdate(ProjectRelationshipMixin, UpdateView):
449+
460450
pass
461451

462452

463453
class ProjectRelationshipDelete(ProjectRelationshipMixin, DeleteView):
464454

465-
def get(self, request, *args, **kwargs):
466-
return self.http_method_not_allowed(request, *args, **kwargs)
455+
http_method_names = ['post']
467456

468457

469458
@login_required
@@ -727,14 +716,17 @@ def get_context_data(self, **kwargs):
727716

728717

729718
class DomainCreate(DomainMixin, CreateView):
719+
730720
pass
731721

732722

733723
class DomainUpdate(DomainMixin, UpdateView):
724+
734725
pass
735726

736727

737728
class DomainDelete(DomainMixin, DeleteView):
729+
738730
pass
739731

740732

@@ -776,6 +768,7 @@ def get_template_names(self):
776768

777769

778770
class IntegrationList(IntegrationMixin, ListView):
771+
779772
pass
780773

781774

@@ -824,8 +817,7 @@ def get_template_names(self):
824817

825818
class IntegrationDelete(IntegrationMixin, DeleteView):
826819

827-
def get(self, request, *args, **kwargs):
828-
return self.http_method_not_allowed(request, *args, **kwargs)
820+
http_method_names = ['post']
829821

830822

831823
class IntegrationExchangeDetail(IntegrationMixin, DetailView):
@@ -900,22 +892,23 @@ def get_success_url(self):
900892

901893

902894
class EnvironmentVariableList(EnvironmentVariableMixin, ListView):
895+
903896
pass
904897

905898

906899
class EnvironmentVariableCreate(EnvironmentVariableMixin, CreateView):
900+
907901
pass
908902

909903

910904
class EnvironmentVariableDetail(EnvironmentVariableMixin, DetailView):
905+
911906
pass
912907

913908

914909
class EnvironmentVariableDelete(EnvironmentVariableMixin, DeleteView):
915910

916-
# This removes the delete confirmation
917-
def get(self, request, *args, **kwargs):
918-
return self.http_method_not_allowed(request, *args, **kwargs)
911+
http_method_names = ['post']
919912

920913

921914
@login_required

readthedocs/rtd_tests/tests/test_privacy_urls.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ def is_admin(self):
234234
class PrivateProjectAdminAccessTest(PrivateProjectMixin, TestCase):
235235

236236
response_data = {
237-
# Places where we 302 on success -- These delete pages should probably be 405'ing
237+
# Places where we 302 on success, and 301 for old pages -- These delete pages should probably be 405'ing
238238
'/dashboard/import/manual/demo/': {'status_code': 302},
239-
'/dashboard/pip/': {'status_code': 302},
239+
'/dashboard/pip/': {'status_code': 301},
240240
'/dashboard/pip/subprojects/delete/sub/': {'status_code': 302},
241241
'/dashboard/pip/translations/delete/sub/': {'status_code': 302},
242242

@@ -277,7 +277,7 @@ class PrivateProjectUserAccessTest(PrivateProjectMixin, TestCase):
277277
'/dashboard/import/manual/demo/': {'status_code': 302},
278278

279279
# Unauth access redirect for non-owners
280-
'/dashboard/pip/': {'status_code': 302},
280+
'/dashboard/pip/': {'status_code': 301},
281281

282282
# 405's where we should be POST'ing
283283
'/dashboard/pip/users/delete/': {'status_code': 405},
@@ -311,6 +311,11 @@ class PrivateProjectUnauthAccessTest(PrivateProjectMixin, TestCase):
311311
# Auth protected
312312
default_status_code = 302
313313

314+
response_data = {
315+
# Old url, it redirects to a view that doesn't requires login.
316+
'/dashboard/pip/': {'status_code': 301},
317+
}
318+
314319
def login(self):
315320
pass
316321

readthedocs/rtd_tests/tests/test_views.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import csv
2-
import io
32
from urllib.parse import urlsplit
43

54
import mock
6-
import pytest
75
from django.contrib.auth.models import User
86
from django.test import TestCase
97
from django.urls import reverse
@@ -12,12 +10,10 @@
1210

1311
from readthedocs.builds.constants import EXTERNAL, LATEST
1412
from readthedocs.builds.models import Build, Version
15-
from readthedocs.core.models import UserProfile
1613
from readthedocs.core.permissions import AdminPermission
1714
from readthedocs.projects.constants import PUBLIC
1815
from readthedocs.projects.forms import UpdateProjectForm
19-
from readthedocs.projects.models import Feature, HTMLFile, Project
20-
from readthedocs.search.models import SearchQuery
16+
from readthedocs.projects.models import Feature, Project
2117

2218

2319
class Testmaker(TestCase):
@@ -89,10 +85,6 @@ def test_import_wizard_demo(self):
8985
response = self.client.get('/dashboard/import/manual/demo/')
9086
self.assertRedirectToLogin(response)
9187

92-
def test_projects_manage(self):
93-
response = self.client.get('/dashboard/pip/')
94-
self.assertRedirectToLogin(response)
95-
9688
def test_edit(self):
9789
response = self.client.get('/dashboard/pip/edit/')
9890
self.assertRedirectToLogin(response)

0 commit comments

Comments
 (0)