[PATCH] parser: Use initial patch state encoded in the model

Dirk Wallenstein halsmit at t-online.de
Fri Apr 27 01:03:21 EST 2012


Signed-off-by: Dirk Wallenstein <halsmit at t-online.de>
---
(untested, need a bit to get back into it.  I cannot assign None to
select the default state, can I?)

 apps/patchwork/bin/parsemail.py |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/apps/patchwork/bin/parsemail.py b/apps/patchwork/bin/parsemail.py
index 52c85fe..2512055 100755
--- a/apps/patchwork/bin/parsemail.py
+++ b/apps/patchwork/bin/parsemail.py
@@ -37,7 +37,6 @@ from patchwork.parser import parse_patch
 from patchwork.models import Patch, Project, Person, Comment, State
 from django.contrib.auth.models import User
 
-default_patch_state = 'New'
 list_id_headers = ['List-ID', 'X-Mailing-List', 'X-list']
 
 whitespace_re = re.compile('\s+')
@@ -349,7 +348,7 @@ def get_state(state_name):
             return State.objects.get(name__iexact=state_name)
         except State.DoesNotExist:
             pass
-    return State.objects.get(name=default_patch_state)
+    return None
 
 def get_delegate(delegate_email):
     """ Return the delegate with the given email or None """
@@ -395,9 +394,13 @@ def parse_mail(mail):
         patch.submitter = author
         patch.msgid = msgid
         patch.project = project
-        patch.state = get_state(mail.get('X-Patchwork-State', '').strip())
         patch.delegate = get_delegate(
                 mail.get('X-Patchwork-Delegate', '').strip())
+        initial_patch_state = get_state(
+                mail.get('X-Patchwork-State', '').strip())
+        if not initial_patch_state is None:
+            patch.state = initial_patch_state
+
         try:
             patch.save()
         except Exception, ex:
-- 
1.7.5.4



More information about the Patchwork mailing list