Message ID | 20170207221524.22394-2-stephen@that.guru |
---|---|
State | Superseded |
Headers | show |
I like this - good call. I haven't reviewed every single one of the renames - I trust you're able to do that correctly :) With that caveat: Reviewed-by: Daniel Axtens <dja@axtens.net> Regards, Daniel Stephen Finucane <stephen@that.guru> writes: > The 'setbundles' view is also removed as it's not called by > anything/anyone. > > Signed-off-by: Stephen Finucane <stephen@that.guru> > --- > patchwork/urls.py | 28 ++++++++--------- > patchwork/views/bundle.py | 76 +++++----------------------------------------- > patchwork/views/cover.py | 2 +- > patchwork/views/help.py | 2 +- > patchwork/views/patch.py | 20 ++++++------ > patchwork/views/project.py | 4 +-- > 6 files changed, 35 insertions(+), 97 deletions(-) > > diff --git a/patchwork/urls.py b/patchwork/urls.py > index 68aefc2..11548eb 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<project_id>[^/]+)/list/$', patch_views.patches, > + url(r'^$', project_views.project_list, name='project-list'), > + url(r'^project/(?P<project_id>[^/]+)/list/$', patch_views.patch_list, > name='patch-list'), > - url(r'^project/(?P<project_id>[^/]+)/bundles/$', bundle_views.bundles, > + url(r'^project/(?P<project_id>[^/]+)/bundles/$', bundle_views.bundle_list, > name='bundle-list'), > - url(r'^project/(?P<project_id>[^/]+)/$', project_views.project, > + url(r'^project/(?P<project_id>[^/]+)/$', project_views.project_detail, > name='project-detail'), > > # patch views > - url(r'^patch/(?P<patch_id>\d+)/$', patch_views.patch, > + url(r'^patch/(?P<patch_id>\d+)/$', patch_views.patch_detail, > name='patch-detail'), > - url(r'^patch/(?P<patch_id>\d+)/raw/$', patch_views.content, > + url(r'^patch/(?P<patch_id>\d+)/raw/$', patch_views.patch_raw, > name='patch-raw'), > - url(r'^patch/(?P<patch_id>\d+)/mbox/$', patch_views.mbox, > + url(r'^patch/(?P<patch_id>\d+)/mbox/$', patch_views.patch_mbox, > name='patch-mbox'), > > # cover views > - url(r'^cover/(?P<cover_id>\d+)/$', cover_views.cover, > + url(r'^cover/(?P<cover_id>\d+)/$', cover_views.cover_detail, > name='cover-detail'), > > # comment urls > @@ -71,7 +71,7 @@ urlpatterns = [ > name='user-todos'), > url(r'^user/todo/(?P<project_id>[^/]+)/$', 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<username>[^/]*)/(?P<bundlename>[^/]*)/$', > - bundle_views.bundle, > + bundle_views.bundle_detail, > name='bundle-detail'), > url(r'^bundle/(?P<username>[^/]*)/(?P<bundlename>[^/]*)/mbox/$', > - bundle_views.mbox, > + bundle_views.bundle_mbox, > name='bundle-mbox'), > > url(r'^confirm/(?P<key>[0-9a-f]+)/$', notification_views.confirm, > @@ -128,7 +128,7 @@ urlpatterns = [ > url(r'^mail/optin/$', mail_views.optin, name='mail-optin'), > > # help! > - url(r'^help/(?P<path>.*)$', help_views.detail, name='help'), > + url(r'^help/(?P<path>.*)$', help_views.help_detail, name='help'), > ] > > if 'debug_toolbar' in settings.INSTALLED_APPS: > @@ -218,9 +218,9 @@ if settings.ENABLE_REST_API: > if settings.COMPAT_REDIR: > urlpatterns += [ > url(r'^user/bundle/(?P<bundle_id>[^/]+)/$', > - bundle_views.bundle_redir, > + bundle_views.bundle_detail_redir, > name='bundle-redir'), > url(r'^user/bundle/(?P<bundle_id>[^/]+)/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 e717429..1886b7a 100644 > --- a/patchwork/views/bundle.py > +++ b/patchwork/views/bundle.py > @@ -27,74 +27,12 @@ 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 > > > @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': > @@ -125,7 +63,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)] > @@ -189,7 +127,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) > > @@ -208,13 +146,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 a9cf0ad..fe3eaf2 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/help.py b/patchwork/views/help.py > index 7666b0a..2c525ce 100644 > --- a/patchwork/views/help.py > +++ b/patchwork/views/help.py > @@ -33,7 +33,7 @@ if settings.ENABLE_XMLRPC: > help_pages['pwclient/'] = 'pwclient.html' > > > -def detail(request, path): > +def help_detail(request, path): > if path in help_pages: > return render(request, > 'patchwork/help/' + help_pages[path]) > diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py > index caabdd7..469a53a 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 4c59c10..de0c67d 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) > > -- > 2.9.3 > > _______________________________________________ > Patchwork mailing list > Patchwork@lists.ozlabs.org > https://lists.ozlabs.org/listinfo/patchwork
diff --git a/patchwork/urls.py b/patchwork/urls.py index 68aefc2..11548eb 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<project_id>[^/]+)/list/$', patch_views.patches, + url(r'^$', project_views.project_list, name='project-list'), + url(r'^project/(?P<project_id>[^/]+)/list/$', patch_views.patch_list, name='patch-list'), - url(r'^project/(?P<project_id>[^/]+)/bundles/$', bundle_views.bundles, + url(r'^project/(?P<project_id>[^/]+)/bundles/$', bundle_views.bundle_list, name='bundle-list'), - url(r'^project/(?P<project_id>[^/]+)/$', project_views.project, + url(r'^project/(?P<project_id>[^/]+)/$', project_views.project_detail, name='project-detail'), # patch views - url(r'^patch/(?P<patch_id>\d+)/$', patch_views.patch, + url(r'^patch/(?P<patch_id>\d+)/$', patch_views.patch_detail, name='patch-detail'), - url(r'^patch/(?P<patch_id>\d+)/raw/$', patch_views.content, + url(r'^patch/(?P<patch_id>\d+)/raw/$', patch_views.patch_raw, name='patch-raw'), - url(r'^patch/(?P<patch_id>\d+)/mbox/$', patch_views.mbox, + url(r'^patch/(?P<patch_id>\d+)/mbox/$', patch_views.patch_mbox, name='patch-mbox'), # cover views - url(r'^cover/(?P<cover_id>\d+)/$', cover_views.cover, + url(r'^cover/(?P<cover_id>\d+)/$', cover_views.cover_detail, name='cover-detail'), # comment urls @@ -71,7 +71,7 @@ urlpatterns = [ name='user-todos'), url(r'^user/todo/(?P<project_id>[^/]+)/$', 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<username>[^/]*)/(?P<bundlename>[^/]*)/$', - bundle_views.bundle, + bundle_views.bundle_detail, name='bundle-detail'), url(r'^bundle/(?P<username>[^/]*)/(?P<bundlename>[^/]*)/mbox/$', - bundle_views.mbox, + bundle_views.bundle_mbox, name='bundle-mbox'), url(r'^confirm/(?P<key>[0-9a-f]+)/$', notification_views.confirm, @@ -128,7 +128,7 @@ urlpatterns = [ url(r'^mail/optin/$', mail_views.optin, name='mail-optin'), # help! - url(r'^help/(?P<path>.*)$', help_views.detail, name='help'), + url(r'^help/(?P<path>.*)$', help_views.help_detail, name='help'), ] if 'debug_toolbar' in settings.INSTALLED_APPS: @@ -218,9 +218,9 @@ if settings.ENABLE_REST_API: if settings.COMPAT_REDIR: urlpatterns += [ url(r'^user/bundle/(?P<bundle_id>[^/]+)/$', - bundle_views.bundle_redir, + bundle_views.bundle_detail_redir, name='bundle-redir'), url(r'^user/bundle/(?P<bundle_id>[^/]+)/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 e717429..1886b7a 100644 --- a/patchwork/views/bundle.py +++ b/patchwork/views/bundle.py @@ -27,74 +27,12 @@ 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 @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': @@ -125,7 +63,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)] @@ -189,7 +127,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) @@ -208,13 +146,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 a9cf0ad..fe3eaf2 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/help.py b/patchwork/views/help.py index 7666b0a..2c525ce 100644 --- a/patchwork/views/help.py +++ b/patchwork/views/help.py @@ -33,7 +33,7 @@ if settings.ENABLE_XMLRPC: help_pages['pwclient/'] = 'pwclient.html' -def detail(request, path): +def help_detail(request, path): if path in help_pages: return render(request, 'patchwork/help/' + help_pages[path]) diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py index caabdd7..469a53a 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 4c59c10..de0c67d 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)
The 'setbundles' view is also removed as it's not called by anything/anyone. Signed-off-by: Stephen Finucane <stephen@that.guru> --- patchwork/urls.py | 28 ++++++++--------- patchwork/views/bundle.py | 76 +++++----------------------------------------- patchwork/views/cover.py | 2 +- patchwork/views/help.py | 2 +- patchwork/views/patch.py | 20 ++++++------ patchwork/views/project.py | 4 +-- 6 files changed, 35 insertions(+), 97 deletions(-)