]> git.ozlabs.org Git - patchwork/blobdiff - patchwork/bin/parsemail.py
login: Focus the username field on load
[patchwork] / patchwork / bin / parsemail.py
index 97189a3089d5b7de573f2725ee81a0f2af801755..e66b55715d8f011d44ef47de640a6d2464cc0b6f 100755 (executable)
@@ -26,13 +26,8 @@ import time
 import operator
 import codecs
 from email import message_from_file
-try:
-    from email.header import Header, decode_header
-    from email.utils import parsedate_tz, mktime_tz
-except ImportError:
-    # Python 2.4 compatibility
-    from email.Header import Header, decode_header
-    from email.Utils import parsedate_tz, mktime_tz
+from email.header import Header, decode_header
+from email.utils import parsedate_tz, mktime_tz
 
 from patchwork.parser import parse_patch
 from patchwork.models import Patch, Project, Person, Comment, State, \
@@ -220,15 +215,20 @@ def find_content(project, mail):
                     date = mail_date(mail), headers = mail_headers(mail))
 
     if commentbuf:
+        # If this is a new patch, we defer setting comment.patch until
+        # patch has been saved by the caller
         if patch:
-            cpatch = patch
+            comment = Comment(date = mail_date(mail),
+                    content = clean_content(commentbuf),
+                    headers = mail_headers(mail))
+
         else:
             cpatch = find_patch_for_comment(project, mail)
             if not cpatch:
                 return (None, None)
-        comment = Comment(patch = cpatch, date = mail_date(mail),
-                content = clean_content(commentbuf),
-                headers = mail_headers(mail))
+            comment = Comment(patch = cpatch, date = mail_date(mail),
+                    content = clean_content(commentbuf),
+                    headers = mail_headers(mail))
 
     return (patch, comment)
 
@@ -389,8 +389,7 @@ def parse_mail(mail):
     if comment:
         if save_required:
             author.save()
-        # looks like the original constructor for Comment takes the pk
-        # when the Comment is created. reset it here.
+        # we defer this assignment until we know that we have a saved patch
         if patch:
             comment.patch = patch
         comment.submitter = author