1 # Patchwork - automated patch tracking system
2 # Copyright (C) 2008 Jeremy Kerr <jk@ozlabs.org>
4 # This file is part of the Patchwork package.
6 # Patchwork is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # Patchwork is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Patchwork; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 from patchwork.forms import MultiplePatchForm
22 from patchwork.models import Bundle, Project, State
23 from django.conf import settings
24 from django.shortcuts import render_to_response, get_object_or_404
26 def get_patch_ids(d, prefix = 'patch_id'):
29 for (k, v) in d.items():
45 'state': 'state__ordering',
46 'submitter': 'submitter__name'
48 default_order = 'date'
50 def __init__(self, str = None):
53 if str is None or str == '':
54 self.order = self.default_order
62 if str not in self.order_map.keys():
63 self.order = self.default_order
67 self.reversed = reversed
78 def reversed_name(self):
82 return '-' + self.order
85 q = self.order_map[self.order]
90 bundle_actions = ['create', 'add', 'remove']
91 def set_bundle(user, action, data, patches, context):
94 if action == 'create':
95 bundle = Bundle(owner = user, project = project,
96 name = data['bundle_name'])
98 str = 'added to new bundle "%s"' % bundle.name
102 bundle = get_object_or_404(Bundle, id = data['bundle_id'])
103 str = 'added to bundle "%s"' % bundle.name
104 auth_required = False
106 elif action =='remove':
107 bundle = get_object_or_404(Bundle, id = data['removed_bundle_id'])
108 str = 'removed from bundle "%s"' % bundle.name
109 auth_required = False
112 return ['no such bundle']
114 for patch in patches:
115 if action == 'create' or action == 'add':
116 bundle.patches.add(patch)
118 elif action == 'remove':
119 bundle.patches.remove(patch)
122 if len(patches) == 1:
125 str = 'patches ' + str
126 context.add_message(str)
133 def set_patches(user, action, data, patches, context):
135 form = MultiplePatchForm(data = data)
138 project = Project.objects.get(id = data['project'])
140 errors = ['No such project']
141 return (errors, form)
145 print "action: ", action
147 # this may be a bundle action, which doesn't modify a patch. in this
148 # case, don't require a valid form, or patch editing permissions
149 if action in bundle_actions:
150 errors = set_bundle(user, action, data, patches, context)
151 return (errors, form)
153 if not form.is_valid():
154 errors = ['The submitted form data was invalid']
155 return (errors, form)
157 for patch in patches:
158 if not patch.is_editable(user):
159 errors.append('You don\'t have permissions to edit the ' + \
164 if action == 'update':
168 elif action == 'ack':
171 elif action == 'archive':
172 patch.archived = True
176 elif action == 'unarchive':
177 patch.archived = True
181 elif action == 'delete':
187 if len(patches) == 1:
190 str = 'patches ' + str
191 context.add_message(str)
193 return (errors, form)