diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2015-05-24 16:57:33 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2015-05-27 10:26:41 +0800 |
commit | ad2762cf775a8dde508de47164d6429f3fd724f1 (patch) | |
tree | e63015a468cfe32c961908f0338d423227799815 /patchwork/requestcontext.py | |
parent | f09e982f58384946111d4157fd2b7c2b31b78612 (diff) | |
download | patchwork-ad2762cf775a8dde508de47164d6429f3fd724f1.tar.bz2 patchwork-ad2762cf775a8dde508de47164d6429f3fd724f1.tar.xz |
Move to a more recent django project structure
This change updates patchwor to the newer project struture: we've moved
the actual application out of the apps/ directory, and the
patchwork-specific templates to under the patchwork application.
This gives us the manage.py script in the top-level now.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'patchwork/requestcontext.py')
-rw-r--r-- | patchwork/requestcontext.py | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/patchwork/requestcontext.py b/patchwork/requestcontext.py new file mode 100644 index 0000000..3b1afaf --- /dev/null +++ b/patchwork/requestcontext.py @@ -0,0 +1,89 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2008 Jeremy Kerr <jk@ozlabs.org> +# +# This file is part of the Patchwork package. +# +# Patchwork is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# Patchwork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Patchwork; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +from django.template import RequestContext +from django.utils.html import escape +from django.contrib.sites.models import Site +from django.conf import settings +from patchwork.filters import Filters +from patchwork.models import Bundle, Project + +def bundle(request): + user = request.user + if not user.is_authenticated(): + return {} + return {'bundles': Bundle.objects.filter(owner = user)} + +def _params_as_qs(params): + return '&'.join([ '%s=%s' % (escape(k), escape(v)) for k, v in params ]) + +def _params_as_hidden_fields(params): + return '\n'.join([ '<input type="hidden" name="%s" value="%s"/>' % \ + (escape(k), escape(v)) for k, v in params ]) + +class PatchworkRequestContext(RequestContext): + def __init__(self, request, project = None, + dict = None, processors = None, + list_view = None, list_view_params = {}): + self._project = project + self.filters = Filters(request) + if processors is None: + processors = [] + processors.append(bundle) + super(PatchworkRequestContext, self). \ + __init__(request, dict, processors); + + self.update({ + 'filters': self.filters, + 'messages': [], + }) + if list_view: + params = self.filters.params() + for param in ['order', 'page']: + value = request.REQUEST.get(param, None) + if value: + params.append((param, value)) + self.update({ + 'list_view': { + 'view': list_view, + 'view_params': list_view_params, + 'params': params + }}) + + self.projects = Project.objects.all() + + self.update({ + 'project': self.project, + 'site': Site.objects.get_current(), + 'settings': settings, + 'other_projects': len(self.projects) > 1 + }) + + def _set_project(self, project): + self._project = project + self.filters.set_project(project) + self.update({'project': self._project}) + + def _get_project(self): + return self._project + + project = property(_get_project, _set_project) + + def add_message(self, message): + self['messages'].append(message) |