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
22 from patchwork.utils import Order, get_patch_ids, set_patches
23 from patchwork.paginator import Paginator
24 from patchwork.forms import MultiplePatchForm
26 def generic_list(request, project, view,
27 view_args = {}, filter_settings = [], patches = None):
29 context = PatchworkRequestContext(request,
31 list_view_params = view_args)
33 context.project = project
34 order = Order(request.REQUEST.get('order'))
36 form = MultiplePatchForm(project)
38 if request.method == 'POST' and \
39 request.POST.get('form') == 'patchlistform':
40 action = request.POST.get('action', None)
42 action = action.lower()
44 # special case: the user may have hit enter in the 'create bundle'
45 # text field, so if non-empty, assume the create action:
46 if request.POST.get('bundle_name', False):
50 for patch_id in get_patch_ids(request.POST):
52 patch = Patch.objects.get(id = patch_id)
53 except Patch.DoesNotExist:
57 (errors, form) = set_patches(request.user, project, action, \
58 request.POST, ps, context)
60 context['errors'] = errors
62 if not (request.user.is_authenticated() and \
63 project in request.user.get_profile().maintainer_projects.all()):
66 for (filterclass, setting) in filter_settings:
67 if isinstance(setting, dict):
68 context.filters.set_status(filterclass, **setting)
69 elif isinstance(setting, list):
70 context.filters.set_status(filterclass, *setting)
72 context.filters.set_status(filterclass, setting)
75 patches = Patch.objects.filter(project=project)
77 patches = context.filters.apply(patches)
78 patches = patches.order_by(order.query())
80 paginator = Paginator(request, patches)
83 'page': paginator.current_page,