Skip to content

Commit f4ad289

Browse files
committed
Clean up views
Some general cleanup. Related readthedocs#5856
1 parent 72972b5 commit f4ad289

File tree

5 files changed

+24
-49
lines changed

5 files changed

+24
-49
lines changed

readthedocs/builds/urls.py

Lines changed: 4 additions & 6 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(
119
r'^(?P<project_slug>[-\w]+)/(?P<pk>\d+)/$',
12-
builds_redirect_detail,
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 & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
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
@@ -17,19 +16,19 @@
1716
from django.utils.decorators import method_decorator
1817
from django.views.generic import DetailView, ListView
1918
from requests.utils import quote
20-
from urllib.parse import urlparse
2119

22-
from readthedocs.doc_builder.exceptions import BuildEnvironmentError
2320
from readthedocs.builds.models import Build, Version
2421
from readthedocs.core.permissions import AdminPermission
2522
from readthedocs.core.utils import trigger_build
23+
from readthedocs.doc_builder.exceptions import BuildEnvironmentError
2624
from readthedocs.projects.models import Project
2725

2826

2927
log = logging.getLogger(__name__)
3028

3129

3230
class BuildBase:
31+
3332
model = Build
3433

3534
def get_queryset(self):
@@ -103,6 +102,7 @@ def get_context_data(self, **kwargs):
103102

104103

105104
class BuildDetail(BuildBase, DetailView):
105+
106106
pk_url_kwarg = 'build_pk'
107107

108108
def get_context_data(self, **kwargs):
@@ -152,18 +152,3 @@ def get_context_data(self, **kwargs):
152152
issue_url = urlparse(issue_url).geturl()
153153
context['issue_url'] = issue_url
154154
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

0 commit comments

Comments
 (0)