diff mbox

[04/10] forms: Allow the delegate field to keep its current value

Message ID 1448712886-3221-5-git-send-email-mchehab@osg.samsung.com
State Accepted
Delegated to: Stephen Finucane
Headers show

Commit Message

Mauro Carvalho Chehab Nov. 28, 2015, 12:14 p.m. UTC
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

When a patch is delegated at parse time (either through the
X-Patchwork-Hint mail header or through delegation rules), the delegate
might not be in the list of project maintainers.

Add the current delegate to the list of acceptable values for the
delegate field to allow the current value to be kept when editing the
patch.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 patchwork/forms.py | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

Comments

Stephen Finucane Jan. 6, 2016, 5:13 p.m. UTC | #1
On 28 Nov 10:14, Mauro Carvalho Chehab wrote:
> From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> When a patch is delegated at parse time (either through the
> X-Patchwork-Hint mail header or through delegation rules), the delegate
> might not be in the list of project maintainers.
> 
> Add the current delegate to the list of acceptable values for the
> delegate field to allow the current value to be kept when editing the
> patch.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Stephen Finucane <stephen.finucane@intel.com>
Stephen Finucane Jan. 19, 2016, 9:25 p.m. UTC | #2
On 06 Jan 17:13, Finucane, Stephen wrote:
> On 28 Nov 10:14, Mauro Carvalho Chehab wrote:
> > From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > 
> > When a patch is delegated at parse time (either through the
> > X-Patchwork-Hint mail header or through delegation rules), the delegate
> > might not be in the list of project maintainers.
> > 
> > Add the current delegate to the list of acceptable values for the
> > delegate field to allow the current value to be kept when editing the
> > patch.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> Acked-by: Stephen Finucane <stephen.finucane@intel.com>

Merged.
diff mbox

Patch

diff --git a/patchwork/forms.py b/patchwork/forms.py
index 03279588a1ef..d82a3418fabc 100644
--- a/patchwork/forms.py
+++ b/patchwork/forms.py
@@ -19,6 +19,7 @@ 
 
 
 from django.contrib.auth.models import User
+from django.db.models.query_utils import Q
 from django import forms
 
 from patchwork.models import Patch, State, Bundle, UserProfile
@@ -88,11 +89,14 @@  class DeleteBundleForm(forms.Form):
     bundle_id = forms.IntegerField(widget = forms.HiddenInput)
 
 class DelegateField(forms.ModelChoiceField):
-    def __init__(self, project, *args, **kwargs):
-        queryset = User.objects.filter(profile__in = \
-                UserProfile.objects \
-                        .filter(maintainer_projects = project) \
-                        .values('pk').query)
+    def __init__(self, project, instance = None, *args, **kwargs):
+	q = Q(profile__in = \
+              UserProfile.objects \
+                  .filter(maintainer_projects = project) \
+                  .values('pk').query)
+        if instance and instance.delegate:
+	    q = q | Q(username = instance.delegate)
+        queryset = User.objects.complex_filter(q)
         super(DelegateField, self).__init__(queryset, *args, **kwargs)
 
 
@@ -103,7 +107,7 @@  class PatchForm(forms.ModelForm):
         if not project:
             raise Exception("meep")
         super(PatchForm, self).__init__(instance = instance, *args, **kwargs)
-        self.fields['delegate'] = DelegateField(project, required = False)
+        self.fields['delegate'] = DelegateField(project, instance, required = False)
 
     class Meta:
         model = Patch