From patchwork Wed Sep 9 12:59:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 515836 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1BF5F1400CB for ; Wed, 9 Sep 2015 23:00:07 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 00F4C1A2BCF for ; Wed, 9 Sep 2015 23:00:07 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lists.ozlabs.org (Postfix) with ESMTP id C6BF51A2B14 for ; Wed, 9 Sep 2015 22:59:23 +1000 (AEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP; 09 Sep 2015 05:59:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,496,1437462000"; d="scan'208";a="800839325" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga002.jf.intel.com with ESMTP; 09 Sep 2015 05:59:20 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t89CxJjL023606; Wed, 9 Sep 2015 13:59:19 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id t89CxJ8a032527; Wed, 9 Sep 2015 13:59:19 +0100 Received: (from sfinucan@localhost) by sivswdev01.ir.intel.com with id t89CxJbT032523; Wed, 9 Sep 2015 13:59:19 +0100 From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH 4/7] trivial: Cleanup of 'views/__init__.py' Date: Wed, 9 Sep 2015 13:59:11 +0100 Message-Id: <1441803554-31677-5-git-send-email-stephen.finucane@intel.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1441803554-31677-1-git-send-email-stephen.finucane@intel.com> References: <1441803554-31677-1-git-send-email-stephen.finucane@intel.com> X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Resolve some issues with the aforementioned file. These are mostly stylistic changes. Signed-off-by: Stephen Finucane --- patchwork/views/__init__.py | 90 +++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/patchwork/views/__init__.py b/patchwork/views/__init__.py index b64f604..be442bd 100644 --- a/patchwork/views/__init__.py +++ b/patchwork/views/__init__.py @@ -17,44 +17,51 @@ # along with Patchwork; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -from base import * -from patchwork.utils import Order, get_patch_ids, bundle_actions, set_bundle -from patchwork.paginator import Paginator -from patchwork.forms import MultiplePatchForm -from patchwork.models import Comment -import re import datetime +import email.utils +import re try: - from email.mime.nonmultipart import MIMENonMultipart from email.encoders import encode_7or8bit - from email.parser import HeaderParser from email.header import Header + from email.mime.nonmultipart import MIMENonMultipart + from email.parser import HeaderParser import email.utils except ImportError: # Python 2.4 compatibility - from email.MIMENonMultipart import MIMENonMultipart from email.Encoders import encode_7or8bit - from email.Parser import HeaderParser from email.Header import Header + from email.MIMENonMultipart import MIMENonMultipart + from email.Parser import HeaderParser import email.Utils email.utils = email.Utils -def generic_list(request, project, view, - view_args = {}, filter_settings = [], patches = None, - editable_order = False): +from base import * +from patchwork.forms import MultiplePatchForm +from patchwork.models import Comment, Patch +from patchwork.paginator import Paginator +from patchwork.requestcontext import PatchworkRequestContext +from patchwork.utils import Order, get_patch_ids, bundle_actions, set_bundle - context = PatchworkRequestContext(request, - list_view = view, - list_view_params = view_args) +def generic_list(request, project, view, view_args=None, filter_settings=None, + patches=None, editable_order=False): + if view_args is None: + view_args = {} + if filter_settings is None: + filter_settings = [] + + context = PatchworkRequestContext(request, + list_view=view, + list_view_params=view_args) context.project = project + data = {} if request.method == 'GET': data = request.GET elif request.method == 'POST': data = request.POST + order = Order(data.get('order'), editable=editable_order) # Explicitly set data to None because request.POST will be an empty dict @@ -63,8 +70,10 @@ def generic_list(request, project, view, # there's been a form submission. if request.method != 'POST': data = None - user = request.user + properties_form = None + + user = request.user if project.is_editable(user): # we only pass the post data to the MultiplePatchForm if that was @@ -73,7 +82,7 @@ def generic_list(request, project, view, if data and data.get('form', '') == 'patchlistform': data_tmp = data - properties_form = MultiplePatchForm(project, data = data_tmp) + properties_form = MultiplePatchForm(project, data=data_tmp) if request.method == 'POST' and data.get('form') == 'patchlistform': action = data.get('action', '').lower() @@ -83,7 +92,7 @@ def generic_list(request, project, view, if data.get('bundle_name', False): action = 'create' - ps = Patch.objects.filter(id__in = get_patch_ids(data)) + ps = Patch.objects.filter(id__in=get_patch_ids(data)) if action in bundle_actions: errors = set_bundle(user, project, action, data, ps, context) @@ -126,11 +135,11 @@ def generic_list(request, project, view, paginator = Paginator(request, patches) context.update({ - 'page': paginator.current_page, - 'patchform': properties_form, - 'project': project, - 'order': order, - }) + 'page': paginator.current_page, + 'patchform': properties_form, + 'project': project, + 'order': order, + }) return context @@ -141,28 +150,29 @@ def process_multiplepatch_form(form, user, action, patches, context): return ['The submitted form data was invalid'] if len(patches) == 0: - context.add_message("No patches selected; nothing updated") + context.add_message('No patches selected; nothing updated') return errors changed_patches = 0 for patch in patches: if not patch.is_editable(user): - errors.append("You don't have permissions to edit patch '%s'" - % patch.name) + errors.append("You don't have permissions to edit patch '%s'" % ( + patch.name)) continue changed_patches += 1 form.save(patch) if changed_patches == 1: - context.add_message("1 patch updated") + context.add_message('1 patch updated') elif changed_patches > 1: - context.add_message("%d patches updated" % changed_patches) + context.add_message('%d patches updated' % changed_patches) else: - context.add_message("No patches updated") + context.add_message('No patches updated') return errors + class PatchMbox(MIMENonMultipart): patch_charset = 'utf-8' def __init__(self, _text): @@ -171,29 +181,30 @@ class PatchMbox(MIMENonMultipart): self.set_payload(_text.encode(self.patch_charset)) encode_7or8bit(self) + def patch_to_mbox(patch): postscript_re = re.compile('\n-{2,3} ?\n') comment = None try: - comment = Comment.objects.get(patch = patch, msgid = patch.msgid) - except Exception: + comment = Comment.objects.get(patch=patch, msgid=patch.msgid) + except Comment.DoesNotExist: pass body = '' if comment: - body = comment.content.strip() + "\n" + body = comment.content.strip() + '\n' parts = postscript_re.split(body, 1) if len(parts) == 2: (body, postscript) = parts - body = body.strip() + "\n" + body = body.strip() + '\n' postscript = postscript.rstrip() else: postscript = '' - for comment in Comment.objects.filter(patch = patch) \ - .exclude(msgid = patch.msgid): + for comment in Comment.objects.filter(patch=patch).exclude( + msgid=patch.msgid): body += comment.patch_responses() if postscript: @@ -208,13 +219,12 @@ def patch_to_mbox(patch): mail = PatchMbox(body) mail['Subject'] = patch.name mail['From'] = email.utils.formataddr(( - str(Header(patch.submitter.name, mail.patch_charset)), - patch.submitter.email)) + str(Header(patch.submitter.name, mail.patch_charset)), + patch.submitter.email)) mail['X-Patchwork-Id'] = str(patch.id) mail['Message-Id'] = patch.msgid mail.set_unixfrom('From patchwork ' + patch.date.ctime()) - copied_headers = ['To', 'Cc', 'Date'] orig_headers = HeaderParser().parsestr(str(patch.headers)) for header in copied_headers: