]> git.ozlabs.org Git - patchwork/blob - apps/patchwork/views/__init__.py
Inital commit
[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
29     context = PatchworkRequestContext(request,
30             list_view = view,
31             list_view_params = view_args)
32
33     context.project = project
34     order = Order(request.REQUEST.get('order'))
35
36     form = MultiplePatchForm(project)
37
38     if request.method == 'POST' and \
39                        request.POST.get('form') == 'patchlistform':
40         action = request.POST.get('action', None)
41         if action:
42             action = action.lower()
43
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):
47             action = 'create'
48
49         ps = []
50         for patch_id in get_patch_ids(request.POST):
51             try:
52                 patch = Patch.objects.get(id = patch_id)
53             except Patch.DoesNotExist:
54                 pass
55             ps.append(patch)
56
57         (errors, form) = set_patches(request.user, action, request.POST, \
58                 ps, context)
59         if errors:
60             context['errors'] = errors
61
62     if not (request.user.is_authenticated() and \
63             project in request.user.get_profile().maintainer_projects.all()):
64         form = None
65
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)
71         else:
72             context.filters.set_status(filterclass, setting)
73
74     if not patches:
75         patches = Patch.objects.filter(project=project)
76
77     patches = context.filters.apply(patches)
78     patches = patches.order_by(order.query())
79
80     paginator = Paginator(request, patches)
81
82     context.update({
83             'page':             paginator.current_page,
84             'patchform':        form,
85             'project':          project,
86             'order':            order,
87             })
88
89     return context
90