Skip to content

Commit 0f7d391

Browse files
committed
forms: update MuliplePatchForm to acocmodate for the new 'interested_users' field
Signed-off-by: andrepapoti <[email protected]>
1 parent 3bdf140 commit 0f7d391

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

patchwork/forms.py

+30
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,17 @@ def __init__(self, project, *args, **kwargs):
198198
self.fields['state'] = OptionalModelChoiceField(
199199
queryset=State.objects.all()
200200
)
201+
self.user = kwargs.get('user')
202+
if self.user:
203+
self.fields['declare_interest'] = OptionalBooleanField(
204+
choices=[
205+
('*', 'no change'),
206+
('True', 'Interested'),
207+
('False', 'Not interested'),
208+
],
209+
coerce=lambda x: x == 'True',
210+
empty_value='*',
211+
)
201212

202213
def save(self, instance, commit=True):
203214
opts = instance.__class__._meta
@@ -219,8 +230,27 @@ def save(self, instance, commit=True):
219230
if field.is_no_change(data[f.name]):
220231
continue
221232

233+
if f.name == 'declare_interest':
234+
if data[f.name]:
235+
self.instance.interested_users.add(self.user)
236+
else:
237+
self.instance.interested_users.remove(self.user)
238+
continue
239+
222240
setattr(instance, f.name, data[f.name])
223241

224242
if commit:
225243
instance.save()
226244
return instance
245+
246+
def declare_interest_only(self):
247+
interest_only = True
248+
field_names = set(self.fields.keys())
249+
field_names.remove({'declare_interest', 'action'})
250+
251+
for field_name in field_names:
252+
data = self.data.get(field_name, '*')
253+
if data != '*':
254+
interest_only = False
255+
256+
return interest_only

patchwork/models.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def save(self, *args, **kwargs):
582582

583583
self.refresh_tag_counts()
584584

585-
def is_editable(self, user):
585+
def is_editable(self, user, declare_interest_only=False):
586586
if not user.is_authenticated:
587587
return False
588588

@@ -593,7 +593,8 @@ def is_editable(self, user):
593593
if self.project.is_editable(user):
594594
self._edited_by = user
595595
return True
596-
return False
596+
597+
return declare_interest_only
597598

598599
@staticmethod
599600
def filter_unique_checks(checks):

patchwork/views/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ def generic_list(
240240
if data and data.get('form', '') == 'patchlistform':
241241
data_tmp = data
242242

243-
properties_form = MultiplePatchForm(project, data=data_tmp)
243+
properties_form = MultiplePatchForm(
244+
project, data=data_tmp, user=request.user
245+
)
244246

245247
if request.method == 'POST' and data.get('form') == 'patchlistform':
246248
action = data.get('action', '').lower()
@@ -340,7 +342,7 @@ def process_multiplepatch_form(request, form, action, patches, context):
340342

341343
changed_patches = 0
342344
for patch in patches:
343-
if not patch.is_editable(request.user):
345+
if not patch.is_editable(request.user, form.declare_interest_only()):
344346
errors.append(
345347
"You don't have permissions to edit patch '%s'" % patch.name
346348
)

0 commit comments

Comments
 (0)