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
21 from patchwork.models import Patch, Project, Person, EmailConfirmation
22 from django.shortcuts import render_to_response, get_object_or_404
23 from django.http import HttpResponse, HttpResponseRedirect, Http404
24 from patchwork.requestcontext import PatchworkRequestContext
25 from django.core import serializers, urlresolvers
26 from django.template.loader import render_to_string
27 from django.conf import settings
28 from django.db.models import Q
30 def projects(request):
31 context = PatchworkRequestContext(request)
32 projects = Project.objects.all()
34 if projects.count() == 1:
35 return HttpResponseRedirect(
36 urlresolvers.reverse('patchwork.views.patch.list',
37 kwargs = {'project_id': projects[0].linkname}))
39 context['projects'] = projects
40 return render_to_response('patchwork/projects.html', context)
42 def pwclientrc(request, project_id):
43 project = get_object_or_404(Project, linkname = project_id)
44 context = PatchworkRequestContext(request)
45 context.project = project
46 if settings.FORCE_HTTPS_LINKS or request.is_secure():
47 context['scheme'] = 'https'
49 context['scheme'] = 'http'
50 response = HttpResponse(content_type = "text/plain")
51 response['Content-Disposition'] = 'attachment; filename=.pwclientrc'
52 response.write(render_to_string('patchwork/pwclientrc', context))
55 def pwclient(request):
56 context = PatchworkRequestContext(request)
57 response = HttpResponse(content_type = "text/x-python")
58 response['Content-Disposition'] = 'attachment; filename=pwclient'
59 response.write(render_to_string('patchwork/pwclient', context))
62 def confirm(request, key):
63 import patchwork.views.user, patchwork.views.mail
65 'userperson': patchwork.views.user.link_confirm,
66 'registration': patchwork.views.user.register_confirm,
67 'optout': patchwork.views.mail.optout_confirm,
68 'optin': patchwork.views.mail.optin_confirm,
71 conf = get_object_or_404(EmailConfirmation, key = key)
72 if conf.type not in views:
75 if conf.active and conf.is_valid():
76 return views[conf.type](request, conf)
78 context = PatchworkRequestContext(request)
79 context['conf'] = conf
81 context['error'] = 'inactive'
82 elif not conf.is_valid():
83 context['error'] = 'expired'
85 return render_to_response('patchwork/confirm-error.html', context)
87 def submitter_complete(request):
88 search = request.GET.get('q', '')
89 limit = request.GET.get('l', None)
90 response = HttpResponse(content_type = "text/plain")
95 queryset = Person.objects.filter(Q(name__icontains = search) |
96 Q(email__icontains = search))
103 if limit is not None and limit > 0:
104 queryset = queryset[:limit]
106 json_serializer = serializers.get_serializer("json")()
107 json_serializer.serialize(queryset, ensure_ascii=False, stream=response)
110 help_pages = {'': 'index.html',
111 'about/': 'about.html',
114 if settings.ENABLE_XMLRPC:
115 help_pages['pwclient/'] = 'pwclient.html'
117 def help(request, path):
118 context = PatchworkRequestContext(request)
119 if path in help_pages:
120 return render_to_response('patchwork/help/' + help_pages[path], context)