From patchwork Sun Apr 29 13:11:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Wallenstein X-Patchwork-Id: 155737 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 12142B6FF9 for ; Sun, 29 Apr 2012 23:12:00 +1000 (EST) Received: from mailout11.t-online.de (mailout11.t-online.de [194.25.134.85]) by ozlabs.org (Postfix) with ESMTP id AF970B6FDF for ; Sun, 29 Apr 2012 23:11:52 +1000 (EST) Received: from fwd00.aul.t-online.de (fwd00.aul.t-online.de ) by mailout11.t-online.de with smtp id 1SOTuo-00068q-El; Sun, 29 Apr 2012 15:11:50 +0200 Received: from localhost.localdomain (Tnqwe-ZGrhVzFpqO8HLo98WAX8EhzGmNwtWqMbmN8mG6CvpGqeaAtTce4shDdZkZZ4@[109.91.88.236]) by fwd00.t-online.de with esmtp id 1SOTun-26fWuO0; Sun, 29 Apr 2012 15:11:49 +0200 From: Dirk Wallenstein To: patchwork@lists.ozlabs.org Subject: [PATCH 1/2] Use an explicit initial default patch state Date: Sun, 29 Apr 2012 15:11:48 +0200 Message-Id: <1335705109-6584-1-git-send-email-halsmit@t-online.de> X-Mailer: git-send-email 1.7.5.4 X-ID: Tnqwe-ZGrhVzFpqO8HLo98WAX8EhzGmNwtWqMbmN8mG6CvpGqeaAtTce4shDdZkZZ4 X-TOI-MSGID: 489f3fa8-8091-4b9f-8a39-ea7e6930b290 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.14 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-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org This will make editing states through the admin UI less error-prone, and will facilitate parsing patches when relying on a default state, as well as testing. Use the explicit default state when parsing mails. Signed-off-by: Dirk Wallenstein --- I've found this very informative. I somehow missed a way to obtain the default, otherwise. http://djangodays.com/2009/05/11/django-foreign-key-default-value-example/ apps/patchwork/bin/parsemail.py | 5 ++--- apps/patchwork/models.py | 5 ++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/patchwork/bin/parsemail.py b/apps/patchwork/bin/parsemail.py index 52c85fe..f156c42 100755 --- a/apps/patchwork/bin/parsemail.py +++ b/apps/patchwork/bin/parsemail.py @@ -34,10 +34,9 @@ except ImportError: from email.Utils import parsedate_tz, mktime_tz from patchwork.parser import parse_patch -from patchwork.models import Patch, Project, Person, Comment, State +from patchwork.models import Patch, Project, Person, Comment, State, get_default_initial_patch_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 get_default_initial_patch_state() def get_delegate(delegate_email): """ Return the delegate with the given email or None """ diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py index bb8d8e7..09e2c34 100644 --- a/apps/patchwork/models.py +++ b/apps/patchwork/models.py @@ -191,6 +191,9 @@ class PatchMbox(MIMENonMultipart): self.set_payload(_text.encode(self.patch_charset)) encode_7or8bit(self) +def get_default_initial_patch_state(): + return State.objects.get(name="New") + class Patch(models.Model): project = models.ForeignKey(Project) msgid = models.CharField(max_length=255) @@ -198,7 +201,7 @@ class Patch(models.Model): date = models.DateTimeField(default=datetime.datetime.now) submitter = models.ForeignKey(Person) delegate = models.ForeignKey(User, blank = True, null = True) - state = models.ForeignKey(State) + state = models.ForeignKey(State, default=get_default_initial_patch_state) archived = models.BooleanField(default = False) headers = models.TextField(blank = True) content = models.TextField(null = True, blank = True)