Patchwork parser: Use initial patch state encoded in the model

login
register
mail settings
Submitter Dirk Wallenstein
Date April 26, 2012, 3:03 p.m.
Message ID <20120426150321.GA15111@bottich>
Download mbox | patch
Permalink /patch/155290/
State Superseded
Headers show

Comments

Dirk Wallenstein - April 26, 2012, 3:03 p.m.
Signed-off-by: Dirk Wallenstein <halsmit@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(-)
Dirk Wallenstein - April 29, 2012, 12:50 p.m.
On Thu, Apr 26, 2012 at 05:03:21PM +0200, Dirk Wallenstein wrote:
> Signed-off-by: Dirk Wallenstein <halsmit@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(-)

I think I have found a better solution.  Will send a new series.

Patch

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: