]> git.ozlabs.org Git - patchwork/blob - apps/patchwork/views/base.py
e30fc6ee9dc81ee3a2655163421ee5741c6b6063
[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
22 from patchwork.filters import Filters
23 from patchwork.forms import LoginForm, PatchForm
24 from django.shortcuts import render_to_response, get_object_or_404
25 from django.http import HttpResponse, HttpResponseRedirect, Http404
26 from django.db import transaction
27 from django.contrib.auth.models import User
28 from django.contrib.auth.decorators import login_required
29 from patchwork.requestcontext import PatchworkRequestContext
30 from django.core import serializers, urlresolvers
31 from django.template.loader import render_to_string
32 from django.conf import settings
33
34 def projects(request):
35     context = PatchworkRequestContext(request)
36     projects = Project.objects.all()
37
38     if projects.count() == 1:
39         return HttpResponseRedirect(
40                 urlresolvers.reverse('patchwork.views.patch.list',
41                     kwargs = {'project_id': projects[0].linkname}))
42
43     context['projects'] = projects
44     return render_to_response('patchwork/projects.html', context)
45
46 def project(request, project_id):
47     context = PatchworkRequestContext(request)
48     project = get_object_or_404(Project, linkname = project_id)
49     context.project = project
50
51     context['maintainers'] = User.objects.filter( \
52             userprofile__maintainer_projects = project)
53     context['n_patches'] = Patch.objects.filter(project = project,
54             archived = False).count()
55     context['n_archived_patches'] = Patch.objects.filter(project = project,
56             archived = True).count()
57
58     return render_to_response('patchwork/project.html', context)
59
60 def pwclientrc(request, project_id):
61     project = get_object_or_404(Project, linkname = project_id)
62     context = PatchworkRequestContext(request)
63     context.project = project
64     response = HttpResponse(mimetype = "text/plain")
65     response['Content-Disposition'] = 'attachment; filename=.pwclientrc'
66     response.write(render_to_string('patchwork/pwclientrc', context))
67     return response
68
69 def pwclient(request):
70     context = PatchworkRequestContext(request)
71     response = HttpResponse(mimetype = "text/x-python")
72     response['Content-Disposition'] = 'attachment; filename=pwclient'
73     response.write(render_to_string('patchwork/pwclient', context))
74     return response
75
76 def submitter_complete(request):
77     search = request.GET.get('q', '')
78     response = HttpResponse(mimetype = "text/plain")
79     if len(search) > 3:
80         queryset = Person.objects.filter(name__icontains = search)
81         json_serializer = serializers.get_serializer("json")()
82         json_serializer.serialize(queryset, ensure_ascii=False, stream=response)
83     return response
84
85 help_pages = {'':           'index.html',
86               'about/':     'about.html',
87              }
88
89 if settings.ENABLE_XMLRPC:
90     help_pages['pwclient/'] = 'pwclient.html'
91
92 def help(request, path):
93     context = PatchworkRequestContext(request)
94     if help_pages.has_key(path):
95         return render_to_response('patchwork/help/' + help_pages[path], context)
96     raise Http404
97