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):
51 for patch_id in get_patch_ids(request.POST):
53 patch = Patch.objects.get(id = patch_id)
54 except Patch.DoesNotExist:
58 (errors, form) = set_patches(request.user, project, action, \
59 request.POST, ps, context)
61 context['errors'] = errors
63 if not (request.user.is_authenticated() and \
64 project in request.user.get_profile().maintainer_projects.all()):
67 for (filterclass, setting) in filter_settings:
68 if isinstance(setting, dict):
69 context.filters.set_status(filterclass, **setting)
70 elif isinstance(setting, list):
71 context.filters.set_status(filterclass, *setting)
73 context.filters.set_status(filterclass, setting)
76 patches = Patch.objects.filter(project=project)
78 patches = context.filters.apply(patches)
79 if not editable_order:
80 patches = patches.order_by(order.query())
82 paginator = Paginator(request, patches)
85 'page': paginator.current_page,