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.models import Bundle, Project, BundlePatch
22 from django.shortcuts import get_object_or_404
24 def get_patch_ids(d, prefix = 'patch_id'):
27 for (k, v) in d.items():
43 'state': 'state__ordering',
44 'submitter': 'submitter__name',
45 'delegate': 'delegate__username',
47 default_order = ('date', True)
49 def __init__(self, str = None, editable = False):
51 self.editable = editable
56 if str is None or str == '':
57 (self.order, self.reversed) = self.default_order
65 if str not in self.order_map.keys():
66 (self.order, self.reversed) = self.default_order
70 self.reversed = reversed
81 def reversed_name(self):
85 return '-' + self.order
88 q = self.order_map[self.order]
93 bundle_actions = ['create', 'add', 'remove']
94 def set_bundle(user, project, action, data, patches, context):
97 if action == 'create':
98 bundle_name = data['bundle_name'].strip()
100 return ['No bundle name was specified']
102 bundle = Bundle(owner = user, project = project,
105 context.add_message("Bundle %s created" % bundle.name)
108 bundle = get_object_or_404(Bundle, id = data['bundle_id'])
110 elif action =='remove':
111 bundle = get_object_or_404(Bundle, id = data['removed_bundle_id'])
114 return ['no such bundle']
116 for patch in patches:
117 if action == 'create' or action == 'add':
118 bundlepatch_count = BundlePatch.objects.filter(bundle = bundle,
119 patch = patch).count()
120 if bundlepatch_count == 0:
121 bundle.append_patch(patch)
122 context.add_message("Patch '%s' added to bundle %s" % \
123 (patch.name, bundle.name))
125 context.add_message("Patch '%s' already in bundle %s" % \
126 (patch.name, bundle.name))
128 elif action == 'remove':
130 bp = BundlePatch.objects.get(bundle = bundle, patch = patch)
132 context.add_message("Patch '%s' removed from bundle %s\n" % \
133 (patch.name, bundle.name))