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 django.contrib.sites.models import Site
23 from django.conf import settings
24 from patchwork.filters import Filters
25 from patchwork.models import Bundle, Project
29 if not user.is_authenticated():
31 return {'bundles': Bundle.objects.filter(owner = user)}
33 def _params_as_qs(params):
34 return '&'.join([ '%s=%s' % (escape(k), escape(v)) for k, v in params ])
36 def _params_as_hidden_fields(params):
37 return '\n'.join([ '<input type="hidden" name="%s" value="%s"/>' % \
38 (escape(k), escape(v)) for k, v in params ])
40 class PatchworkRequestContext(RequestContext):
41 def __init__(self, request, project = None,
42 dict = None, processors = None,
43 list_view = None, list_view_params = {}):
44 self._project = project
45 self.filters = Filters(request)
46 if processors is None:
48 processors.append(bundle)
49 super(PatchworkRequestContext, self). \
50 __init__(request, dict, processors);
52 self.update({'filters': self.filters})
54 params = self.filters.params()
55 for param in ['order', 'page']:
56 value = request.REQUEST.get(param, None)
58 params.append((param, value))
62 'view_params': list_view_params,
66 self.projects = Project.objects.all()
69 'project': self.project,
70 'site': Site.objects.get_current(),
72 'other_projects': len(self.projects) > 1
75 def _set_project(self, project):
76 self._project = project
77 self.filters.set_project(project)
78 self.update({'project': self._project})
80 def _get_project(self):
83 project = property(_get_project, _set_project)
85 def add_message(self, message):
86 self['messages'].append(message)