]> git.ozlabs.org Git - patchwork/blob - apps/patchwork/views/base.py
Use generic email confirmation object
[patchwork] / apps / patchwork / views / base.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 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
29 def projects(request):
30     context = PatchworkRequestContext(request)
31     projects = Project.objects.all()
32
33     if projects.count() == 1:
34         return HttpResponseRedirect(
35                 urlresolvers.reverse('patchwork.views.patch.list',
36                     kwargs = {'project_id': projects[0].linkname}))
37
38     context['projects'] = projects
39     return render_to_response('patchwork/projects.html', context)
40
41 def pwclientrc(request, project_id):
42     project = get_object_or_404(Project, linkname = project_id)
43     context = PatchworkRequestContext(request)
44     context.project = project
45     if request.is_secure():
46         context['scheme'] = 'https'
47     else:
48         context['scheme'] = 'http'
49     response = HttpResponse(mimetype = "text/plain")
50     response['Content-Disposition'] = 'attachment; filename=.pwclientrc'
51     response.write(render_to_string('patchwork/pwclientrc', context))
52     return response
53
54 def pwclient(request):
55     context = PatchworkRequestContext(request)
56     response = HttpResponse(mimetype = "text/x-python")
57     response['Content-Disposition'] = 'attachment; filename=pwclient'
58     response.write(render_to_string('patchwork/pwclient', context))
59     return response
60
61 def confirm(request, key):
62     import patchwork.views.user
63     views = {
64         'userperson': patchwork.views.user.link_confirm,
65     }
66
67     conf = get_object_or_404(EmailConfirmation, key = key)
68     if conf.type not in views:
69         raise Http404
70
71     if conf.active and conf.is_valid():
72         return views[conf.type](request, conf)
73
74     context = PatchworkRequestContext(request)
75     context['conf'] = conf
76     if not conf.active:
77         context['error'] = 'inactive'
78     elif not conf.is_valid():
79         context['error'] = 'expired'
80
81     return render_to_response('patchwork/confirm-error.html', context)
82
83 def submitter_complete(request):
84     search = request.GET.get('q', '')
85     response = HttpResponse(mimetype = "text/plain")
86     if len(search) > 3:
87         queryset = Person.objects.filter(name__icontains = search)
88         json_serializer = serializers.get_serializer("json")()
89         json_serializer.serialize(queryset, ensure_ascii=False, stream=response)
90     return response
91
92 help_pages = {'':           'index.html',
93               'about/':     'about.html',
94              }
95
96 if settings.ENABLE_XMLRPC:
97     help_pages['pwclient/'] = 'pwclient.html'
98
99 def help(request, path):
100     context = PatchworkRequestContext(request)
101     if path in help_pages:
102         return render_to_response('patchwork/help/' + help_pages[path], context)
103     raise Http404
104