From: Stephen Finucane Date: Thu, 3 Nov 2016 15:38:39 +0000 (+0000) Subject: views: Use consistent 'list'/'detail' names X-Git-Tag: v2.0.0-rc1~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5f65f848b5e91dab3b12d99c4d37d766756f3e9;p=thirdparty%2Fpatchwork.git views: Use consistent 'list'/'detail' names The 'setbundles' view is also removed as it's not called by anything/anyone. Signed-off-by: Stephen Finucane Reviewed-by: Daniel Axtens --- diff --git a/patchwork/urls.py b/patchwork/urls.py index 57d5cd78..34e6e607 100644 --- a/patchwork/urls.py +++ b/patchwork/urls.py @@ -41,24 +41,24 @@ admin.autodiscover() urlpatterns = [ url(r'^admin/', include(admin.site.urls)), - url(r'^$', project_views.projects, name='project-list'), - url(r'^project/(?P[^/]+)/list/$', patch_views.patches, + url(r'^$', project_views.project_list, name='project-list'), + url(r'^project/(?P[^/]+)/list/$', patch_views.patch_list, name='patch-list'), - url(r'^project/(?P[^/]+)/bundles/$', bundle_views.bundles, + url(r'^project/(?P[^/]+)/bundles/$', bundle_views.bundle_list, name='bundle-list'), - url(r'^project/(?P[^/]+)/$', project_views.project, + url(r'^project/(?P[^/]+)/$', project_views.project_detail, name='project-detail'), # patch views - url(r'^patch/(?P\d+)/$', patch_views.patch, + url(r'^patch/(?P\d+)/$', patch_views.patch_detail, name='patch-detail'), - url(r'^patch/(?P\d+)/raw/$', patch_views.content, + url(r'^patch/(?P\d+)/raw/$', patch_views.patch_raw, name='patch-raw'), - url(r'^patch/(?P\d+)/mbox/$', patch_views.mbox, + url(r'^patch/(?P\d+)/mbox/$', patch_views.patch_mbox, name='patch-mbox'), # cover views - url(r'^cover/(?P\d+)/$', cover_views.cover, + url(r'^cover/(?P\d+)/$', cover_views.cover_detail, name='cover-detail'), # comment urls @@ -71,7 +71,7 @@ urlpatterns = [ name='user-todos'), url(r'^user/todo/(?P[^/]+)/$', user_views.todo_list, name='user-todo'), - url(r'^user/bundles/$', bundle_views.bundles, + url(r'^user/bundles/$', bundle_views.bundle_list, name='user-bundles'), url(r'^user/link/$', user_views.link, @@ -109,10 +109,10 @@ urlpatterns = [ # public view for bundles url(r'^bundle/(?P[^/]*)/(?P[^/]*)/$', - bundle_views.bundle, + bundle_views.bundle_detail, name='bundle-detail'), url(r'^bundle/(?P[^/]*)/(?P[^/]*)/mbox/$', - bundle_views.mbox, + bundle_views.bundle_mbox, name='bundle-mbox'), url(r'^confirm/(?P[0-9a-f]+)/$', notification_views.confirm, @@ -235,9 +235,9 @@ if settings.ENABLE_REST_API: if settings.COMPAT_REDIR: urlpatterns += [ url(r'^user/bundle/(?P[^/]+)/$', - bundle_views.bundle_redir, + bundle_views.bundle_detail_redir, name='bundle-redir'), url(r'^user/bundle/(?P[^/]+)/mbox/$', - bundle_views.mbox_redir, + bundle_views.bundle_mbox_redir, name='bundle-mbox-redir'), ] diff --git a/patchwork/views/bundle.py b/patchwork/views/bundle.py index 95c44ae0..b1038393 100644 --- a/patchwork/views/bundle.py +++ b/patchwork/views/bundle.py @@ -28,8 +28,8 @@ from django.shortcuts import render, get_object_or_404 from patchwork.filters import DelegateFilter from patchwork.forms import BundleForm, DeleteBundleForm -from patchwork.models import Patch, Bundle, BundlePatch, Project -from patchwork.views import generic_list, patch_to_mbox, get_patch_ids +from patchwork.models import Bundle, BundlePatch, Project +from patchwork.views import generic_list, patch_to_mbox if settings.ENABLE_REST_API: from rest_framework.authentication import BasicAuthentication # noqa @@ -39,69 +39,7 @@ else: @login_required -def setbundle(request): - bundle = None - - if request.method == 'POST': - action = request.POST.get('action', None) - if action is None: - pass - elif action == 'create': - project = get_object_or_404(Project, - id=request.POST.get('project')) - bundle = Bundle(owner=request.user, project=project, - name=request.POST['name']) - bundle.save() - patch_id = request.POST.get('patch_id', None) - if patch_id: - patch = get_object_or_404(Patch, id=patch_id) - bundle.append_patch(patch) - bundle.save() - elif action == 'add': - bundle = get_object_or_404(Bundle, - owner=request.user, - id=request.POST['id']) - bundle.save() - - patch_id = request.get('patch_id', None) - if patch_id: - patch_ids = patch_id - else: - patch_ids = get_patch_ids(request.POST) - - for patch_id in patch_ids: - patch = Patch.objects.get(id=patch_id) - bundle.append_patch(patch) - - bundle.save() - elif action == 'delete': - try: - bundle = Bundle.objects.get(owner=request.user, - id=request.POST['id']) - bundle.delete() - except Bundle.DoesNotExist: - pass - - bundle = None - else: - bundle = get_object_or_404(Bundle, owner=request.user, - id=request.POST['bundle_id']) - - if bundle: - return HttpResponseRedirect( - django.core.urlresolvers.reverse( - 'bundle-detail', - kwargs={'bundle_id': bundle.id} - ) - ) - else: - return HttpResponseRedirect( - django.core.urlresolvers.reverse('user-bundles') - ) - - -@login_required -def bundles(request, project_id=None): +def bundle_list(request, project_id=None): project = None if request.method == 'POST': @@ -132,7 +70,7 @@ def bundles(request, project_id=None): return render(request, 'patchwork/bundles.html', context) -def bundle(request, username, bundlename): +def bundle_detail(request, username, bundlename): bundle = get_object_or_404(Bundle, owner__username=username, name=bundlename) filter_settings = [(DelegateFilter, DelegateFilter.AnyDelegate)] @@ -196,7 +134,7 @@ def bundle(request, username, bundlename): return render(request, 'patchwork/bundle.html', context) -def mbox(request, username, bundlename): +def bundle_mbox(request, username, bundlename): bundle = get_object_or_404(Bundle, owner__username=username, name=bundlename) @@ -216,13 +154,13 @@ def mbox(request, username, bundlename): @login_required -def bundle_redir(request, bundle_id): +def bundle_detail_redir(request, bundle_id): bundle = get_object_or_404(Bundle, id=bundle_id, owner=request.user) return HttpResponseRedirect(bundle.get_absolute_url()) @login_required -def mbox_redir(request, bundle_id): +def bundle_mbox_redir(request, bundle_id): bundle = get_object_or_404(Bundle, id=bundle_id, owner=request.user) return HttpResponseRedirect(django.core.urlresolvers.reverse( 'bundle-mbox', kwargs={ diff --git a/patchwork/views/cover.py b/patchwork/views/cover.py index a9cf0ad3..fe3eaf2c 100644 --- a/patchwork/views/cover.py +++ b/patchwork/views/cover.py @@ -27,7 +27,7 @@ from django.shortcuts import render_to_response, get_object_or_404 from patchwork.models import CoverLetter, Submission -def cover(request, cover_id): +def cover_detail(request, cover_id): # redirect to patches where necessary try: cover = get_object_or_404(CoverLetter, id=cover_id) diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py index caabdd77..469a53a8 100644 --- a/patchwork/views/patch.py +++ b/patchwork/views/patch.py @@ -33,7 +33,14 @@ from patchwork.models import Patch, Project, Bundle, Submission from patchwork.views import generic_list, patch_to_mbox -def patch(request, patch_id): +def patch_list(request, project_id): + project = get_object_or_404(Project, linkname=project_id) + context = generic_list(request, project, 'patch-list', + view_args={'project_id': project.linkname}) + return render(request, 'patchwork/list.html', context) + + +def patch_detail(request, patch_id): # redirect to cover letters where necessary try: patch = get_object_or_404(Patch, id=patch_id) @@ -108,14 +115,7 @@ def patch(request, patch_id): return render(request, 'patchwork/submission.html', context) -def patches(request, project_id): - project = get_object_or_404(Project, linkname=project_id) - context = generic_list(request, project, 'patch-list', - view_args={'project_id': project.linkname}) - return render(request, 'patchwork/list.html', context) - - -def content(request, patch_id): +def patch_raw(request, patch_id): patch = get_object_or_404(Patch, id=patch_id) response = HttpResponse(content_type="text/x-patch") response.write(patch.diff) @@ -124,7 +124,7 @@ def content(request, patch_id): return response -def mbox(request, patch_id): +def patch_mbox(request, patch_id): patch = get_object_or_404(Patch, id=patch_id) response = HttpResponse(content_type="text/plain") # NOTE(stephenfin) http://stackoverflow.com/a/28584090/613428 diff --git a/patchwork/views/project.py b/patchwork/views/project.py index 4c59c107..de0c67d9 100644 --- a/patchwork/views/project.py +++ b/patchwork/views/project.py @@ -29,7 +29,7 @@ from patchwork.models import Patch from patchwork.models import Project -def projects(request): +def project_list(request): projects = Project.objects.all() if projects.count() == 1: @@ -43,7 +43,7 @@ def projects(request): return render(request, 'patchwork/projects.html', context) -def project(request, project_id): +def project_detail(request, project_id): project = get_object_or_404(Project, linkname=project_id) patches = Patch.objects.filter(project=project)