]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/views/__init__.py
tox: Add tox.ini file
[patchwork] / apps / patchwork / views / __init__.py
index 681532a5cfaeb26a86c0f8e1c6211e11cd931f2d..dfca56dd690c990fbd004f38810877a842197253 100644 (file)
@@ -106,7 +106,15 @@ def generic_list(request, project, view,
 
     patches = context.filters.apply(patches)
     if not editable_order:
-        patches = patches.order_by(order.query())
+        patches = order.apply(patches)
+
+    # we don't need the content or headers for a list; they're text fields
+    # that can potentially contain a lot of data
+    patches = patches.defer('content', 'headers')
+
+    # but we will need to follow the state and submitter relations for
+    # rendering the list template
+    patches = patches.select_related('state', 'submitter')
 
     paginator = Paginator(request, patches)
 
@@ -173,7 +181,7 @@ def patch_to_mbox(patch):
     if len(parts) == 2:
         (body, postscript) = parts
         body = body.strip() + "\n"
-        postscript = postscript.strip() + "\n"
+        postscript = postscript.rstrip()
     else:
         postscript = ''
 
@@ -181,17 +189,14 @@ def patch_to_mbox(patch):
             .exclude(msgid = patch.msgid):
         body += comment.patch_responses()
 
-    if body:
-        body += '\n'
-
     if postscript:
-        body += '---\n' + postscript.strip() + '\n'
+        body += '---\n' + postscript + '\n'
 
     if patch.content:
         body += '\n' + patch.content
 
-    utc_timestamp = (patch.date -
-            datetime.datetime.utcfromtimestamp(0)).total_seconds()
+    delta = patch.date - datetime.datetime.utcfromtimestamp(0)
+    utc_timestamp = delta.seconds + delta.days*24*3600
 
     mail = PatchMbox(body)
     mail['Subject'] = patch.name