[PATCH] Revert "Allow assigning of any user as delegate"

Stephen Finucane stephen at that.guru
Mon Sep 26 07:37:11 AEST 2016


From: Stephen Finucane <stephenfinucane at hotmail.com>

This reverts commit e0fd7cd91a5fbe0a0077c46bea870ccd09c8920d.

This change does not scale with a larger number of lists, and clearly
needs more work. Revert until such a time as this is carried out.
---
 patchwork/forms.py | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/patchwork/forms.py b/patchwork/forms.py
index 8f73f8b..cd954cd 100644
--- a/patchwork/forms.py
+++ b/patchwork/forms.py
@@ -99,8 +99,13 @@ class DeleteBundleForm(forms.Form):
 
 class DelegateField(forms.ModelChoiceField):
 
-    def __init__(self, *args, **kwargs):
-        queryset = User.objects
+    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)
 
 
@@ -112,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(required=False)
+        self.fields['delegate'] = DelegateField(project, instance,
+                                                required=False)
 
     class Meta:
         model = Patch
@@ -225,7 +231,8 @@ class MultiplePatchForm(forms.Form):
 
     def __init__(self, project, *args, **kwargs):
         super(MultiplePatchForm, self).__init__(*args, **kwargs)
-        self.fields['delegate'] = OptionalDelegateField(required=False)
+        self.fields['delegate'] = OptionalDelegateField(project=project,
+                                                        required=False)
 
     def save(self, instance, commit=True):
         opts = instance.__class__._meta
-- 
2.7.4



More information about the Patchwork mailing list