summaryrefslogtreecommitdiff
path: root/patchwork/forms.py
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2015-11-28 10:14:40 -0200
committerStephen Finucane <stephen.finucane@intel.com>2016-01-19 21:22:25 +0000
commit19eb5767be899af0fe333233b9cceb5f94fcad2a (patch)
treecbadcec18e81a8e82b858d355cca5f3e9ae280ab /patchwork/forms.py
parentd6c25e3af355fe5c88efc97230fc2179536b0210 (diff)
downloadpatchwork-19eb5767be899af0fe333233b9cceb5f94fcad2a.tar
patchwork-19eb5767be899af0fe333233b9cceb5f94fcad2a.tar.gz
forms: Allow the delegate field to keep its current value
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>
Diffstat (limited to 'patchwork/forms.py')
-rw-r--r--patchwork/forms.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/patchwork/forms.py b/patchwork/forms.py
index c4eb8c5..217e743 100644
--- a/patchwork/forms.py
+++ b/patchwork/forms.py
@@ -20,6 +20,7 @@
from __future__ import absolute_import
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
@@ -98,10 +99,13 @@ class DeleteBundleForm(forms.Form):
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)
@@ -113,7 +117,8 @@ 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