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
20 from django.template import RequestContext
21 from django.utils.html import escape
22 from patchwork.filters import Filters
23 from patchwork.models import Bundle, Project
27 if not user.is_authenticated():
29 return {'bundles': Bundle.objects.filter(owner = user)}
31 def _params_as_qs(params):
32 return '&'.join([ '%s=%s' % (escape(k), escape(v)) for k, v in params ])
34 def _params_as_hidden_fields(params):
35 return '\n'.join([ '<input type="hidden" name="%s" value="%s"/>' % \
36 (escape(k), escape(v)) for k, v in params ])
38 class PatchworkRequestContext(RequestContext):
39 def __init__(self, request, project = None,
40 dict = None, processors = None,
41 list_view = None, list_view_params = {}):
42 self._project = project
43 self.filters = Filters(request)
44 if processors is None:
46 processors.append(bundle)
47 super(PatchworkRequestContext, self). \
48 __init__(request, dict, processors);
50 self.update({'filters': self.filters})
52 params = self.filters.params()
53 for param in ['order', 'page']:
54 value = request.REQUEST.get(param, None)
56 params.append((param, value))
60 'view_params': list_view_params,
64 self.projects = Project.objects.all()
67 'project': self.project,
68 'other_projects': len(self.projects) > 1
71 def _set_project(self, project):
72 self._project = project
73 self.filters.set_project(project)
74 self.update({'project': self._project})
76 def _get_project(self):
79 project = property(_get_project, _set_project)
81 def add_message(self, message):
82 self['messages'].append(message)