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,
28 editable_order = False):
30 context = PatchworkRequestContext(request,
32 list_view_params = view_args)
34 context.project = project
35 order = Order(request.REQUEST.get('order'), editable = editable_order)
37 form = MultiplePatchForm(project)
39 if request.method == 'POST' and \
40 request.POST.get('form') == 'patchlistform':
41 action = request.POST.get('action', None)
43 action = action.lower()
45 # special case: the user may have hit enter in the 'create bundle'
46 # text field, so if non-empty, assume the create action:
47 if request.POST.get('bundle_name', False):
50 ps = Patch.objects.filter(id__in = get_patch_ids(request.POST))
52 (errors, form) = set_patches(request.user, project, action, \
53 request.POST, ps, context)
55 context['errors'] = errors
57 if not (request.user.is_authenticated() and \
58 project in request.user.get_profile().maintainer_projects.all()):
61 for (filterclass, setting) in filter_settings:
62 if isinstance(setting, dict):
63 context.filters.set_status(filterclass, **setting)
64 elif isinstance(setting, list):
65 context.filters.set_status(filterclass, *setting)
67 context.filters.set_status(filterclass, setting)
70 patches = Patch.objects.filter(project=project)
72 patches = context.filters.apply(patches)
73 if not editable_order:
74 patches = patches.order_by(order.query())
76 paginator = Paginator(request, patches)
79 'page': paginator.current_page,