-
-
-def set_patches(user, project, action, data, patches, context):
- errors = []
- form = MultiplePatchForm(project = project, data = data)
-
- try:
- project = Project.objects.get(id = data['project'])
- except:
- errors = ['No such project']
- return (errors, form)
-
- str = ''
-
- print "action: ", action
-
- # this may be a bundle action, which doesn't modify a patch. in this
- # case, don't require a valid form, or patch editing permissions
- if action in bundle_actions:
- errors = set_bundle(user, action, data, patches, context)
- return (errors, form)
-
- if not form.is_valid():
- errors = ['The submitted form data was invalid']
- return (errors, form)
-
- for patch in patches:
- if not patch.is_editable(user):
- errors.append('You don\'t have permissions to edit the ' + \
- 'patch "%s"' \
- % patch.name)
- continue
-
- if action == 'update':
- form.save(patch)
- str = 'updated'
-
- elif action == 'ack':
- pass
-
- elif action == 'archive':
- patch.archived = True
- patch.save()
- str = 'archived'
-
- elif action == 'unarchive':
- patch.archived = True
- patch.save()
- str = 'un-archived'
-
- elif action == 'delete':
- patch.delete()
- str = 'un-archived'
-
-
- if len(patches) > 0:
- if len(patches) == 1:
- str = 'patch ' + str
- else:
- str = 'patches ' + str
- context.add_message(str)
-
- return (errors, form)