]> git.ozlabs.org Git - patchwork/blob - apps/patchwork/views/__init__.py
Bundle reordering support
[patchwork] / apps / patchwork / views / __init__.py
1 # Patchwork - automated patch tracking system
2 # Copyright (C) 2008 Jeremy Kerr <jk@ozlabs.org>
3 #
4 # This file is part of the Patchwork package.
5 #
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.
10 #
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.
15 #
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
19
20
21 from base import *
22 from patchwork.utils import Order, get_patch_ids, set_patches
23 from patchwork.paginator import Paginator
24 from patchwork.forms import MultiplePatchForm
25
26 def generic_list(request, project, view,
27         view_args = {}, filter_settings = [], patches = None,
28         editable_order = False):
29
30     context = PatchworkRequestContext(request,
31             list_view = view,
32             list_view_params = view_args)
33
34     context.project = project
35     order = Order(request.REQUEST.get('order'), editable = editable_order)
36
37     form = MultiplePatchForm(project)
38
39     if request.method == 'POST' and \
40                        request.POST.get('form') == 'patchlistform':
41         action = request.POST.get('action', None)
42         if action:
43             action = action.lower()
44
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):
48             action = 'create'
49
50         ps = []
51         for patch_id in get_patch_ids(request.POST):
52             try:
53                 patch = Patch.objects.get(id = patch_id)
54             except Patch.DoesNotExist:
55                 pass
56             ps.append(patch)
57
58         (errors, form) = set_patches(request.user, project, action, \
59                 request.POST, ps, context)
60         if errors:
61             context['errors'] = errors
62
63     if not (request.user.is_authenticated() and \
64             project in request.user.get_profile().maintainer_projects.all()):
65         form = None
66
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)
72         else:
73             context.filters.set_status(filterclass, setting)
74
75     if patches is None:
76         patches = Patch.objects.filter(project=project)
77
78     patches = context.filters.apply(patches)
79     if not editable_order:
80         patches = patches.order_by(order.query())
81
82     paginator = Paginator(request, patches)
83
84     context.update({
85             'page':             paginator.current_page,
86             'patchform':        form,
87             'project':          project,
88             'order':            order,
89             })
90
91     return context
92