[PATCH 2/7] trivial: Cleanup of 'views/base.py'

Stephen Finucane stephen.finucane at intel.com
Wed Sep 9 22:59:09 AEST 2015


Resolve some issues with the aforementioned file. These are mostly
stylistic changes.

Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
---
 patchwork/views/base.py | 73 +++++++++++++++++++++++++++++--------------------
 1 file changed, 44 insertions(+), 29 deletions(-)

diff --git a/patchwork/views/base.py b/patchwork/views/base.py
index 6d7dd13..55f10ea 100644
--- a/patchwork/views/base.py
+++ b/patchwork/views/base.py
@@ -17,50 +17,61 @@
 # along with Patchwork; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-
-from patchwork.models import Patch, Project, Person, EmailConfirmation
-from django.shortcuts import render_to_response, get_object_or_404
-from django.http import HttpResponse, HttpResponseRedirect, Http404
-from patchwork.requestcontext import PatchworkRequestContext
-from django.core import serializers, urlresolvers
-from django.template.loader import render_to_string
 from django.conf import settings
+from django.contrib.auth.models import User
+from django.core import serializers, urlresolvers
 from django.db.models import Q
+from django.http import HttpResponse, HttpResponseRedirect, Http404
+from django.shortcuts import render_to_response, get_object_or_404
+from django.template.loader import render_to_string
+
+from patchwork.models import Project, Person, EmailConfirmation
+from patchwork.requestcontext import PatchworkRequestContext
+
 
 def projects(request):
     context = PatchworkRequestContext(request)
-    projects = Project.objects.all()
+    projects_ = Project.objects.all()
 
-    if projects.count() == 1:
+    if projects_.count() == 1:
         return HttpResponseRedirect(
-                urlresolvers.reverse('patchwork.views.patch.list',
-                    kwargs = {'project_id': projects[0].linkname}))
+            urlresolvers.reverse('patchwork.views.patch.list',
+                                 kwargs={'project_id': projects_[0].linkname}))
 
     context['projects'] = projects
+
     return render_to_response('patchwork/projects.html', context)
 
+
 def pwclientrc(request, project_id):
-    project = get_object_or_404(Project, linkname = project_id)
+    project = get_object_or_404(Project, linkname=project_id)
+
     context = PatchworkRequestContext(request)
     context.project = project
     if settings.FORCE_HTTPS_LINKS or request.is_secure():
         context['scheme'] = 'https'
     else:
         context['scheme'] = 'http'
-    response = HttpResponse(content_type = "text/plain")
+
+    response = HttpResponse(content_type='text/plain')
     response['Content-Disposition'] = 'attachment; filename=.pwclientrc'
     response.write(render_to_string('patchwork/pwclientrc', context))
+
     return response
 
+
 def pwclient(request):
     context = PatchworkRequestContext(request)
-    response = HttpResponse(content_type = "text/x-python")
+    response = HttpResponse(content_type='text/x-python')
     response['Content-Disposition'] = 'attachment; filename=pwclient'
     response.write(render_to_string('patchwork/pwclient', context))
     return response
 
+
 def confirm(request, key):
-    import patchwork.views.user, patchwork.views.mail
+    import patchwork.views.user
+    import patchwork.views.mail
+
     views = {
         'userperson': patchwork.views.user.link_confirm,
         'registration': patchwork.views.user.register_confirm,
@@ -68,10 +79,9 @@ def confirm(request, key):
         'optin': patchwork.views.mail.optin_confirm,
     }
 
-    conf = get_object_or_404(EmailConfirmation, key = key)
+    conf = get_object_or_404(EmailConfirmation, key=key)
     if conf.type not in views:
         raise Http404
-
     if conf.active and conf.is_valid():
         return views[conf.type](request, conf)
 
@@ -84,16 +94,17 @@ def confirm(request, key):
 
     return render_to_response('patchwork/confirm-error.html', context)
 
+
 def submitter_complete(request):
     search = request.GET.get('q', '')
     limit = request.GET.get('l', None)
-    response = HttpResponse(content_type = "text/plain")
+    response = HttpResponse(content_type='text/plain')
 
     if len(search) <= 3:
         return response
 
-    queryset = Person.objects.filter(Q(name__icontains = search) |
-                                     Q(email__icontains = search))
+    queryset = Person.objects.filter(Q(name__icontains=search) |
+                                     Q(email__icontains=search))
     if limit is not None:
         try:
             limit = int(limit)
@@ -103,20 +114,24 @@ def submitter_complete(request):
     if limit is not None and limit > 0:
             queryset = queryset[:limit]
 
-    json_serializer = serializers.get_serializer("json")()
+    json_serializer = serializers.get_serializer('json')()
     json_serializer.serialize(queryset, ensure_ascii=False, stream=response)
-    return response
 
-help_pages = {'':           'index.html',
-              'about/':     'about.html',
-             }
+    return response
 
-if settings.ENABLE_XMLRPC:
-    help_pages['pwclient/'] = 'pwclient.html'
 
 def help(request, path):
+    help_pages = {
+        '': 'index.html',
+        'about/': 'about.html',
+    }
+
+    if settings.ENABLE_XMLRPC:
+        help_pages['pwclient/'] = 'pwclient.html'
+
     context = PatchworkRequestContext(request)
     if path in help_pages:
-        return render_to_response('patchwork/help/' + help_pages[path], context)
-    raise Http404
+        return render_to_response('patchwork/help/%s' % help_pages[path],
+                                  context)
 
+    raise Http404
-- 
2.0.0



More information about the Patchwork mailing list