Inital commit
[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, RegistrationRequest
22 from patchwork.filters import Filters
23 from patchwork.forms import RegisterForm, LoginForm, PatchForm
24 from django.shortcuts import render_to_response, get_object_or_404
25 from django.http import HttpResponse, HttpResponseRedirect
26 from django.db import transaction
27 from django.contrib.auth.models import User
28 from django.contrib.auth.decorators import login_required
29 import django.core.urlresolvers
30 from patchwork.requestcontext import PatchworkRequestContext
31 from django.core import serializers
32
33 def projects(request):
34     context = PatchworkRequestContext(request)
35     projects = Project.objects.all()
36
37     if projects.count() == 1:
38         return HttpResponseRedirect(
39                 django.core.urlresolvers.reverse('patchwork.views.patch.list',
40                     kwargs = {'project_id': projects[0].linkname}))
41
42     context['projects'] = projects
43     return render_to_response('patchwork/projects.html', context)
44
45 def project(request, project_id):
46     context = PatchworkRequestContext(request)
47     project = get_object_or_404(Project, linkname = project_id)
48     context.project = project
49
50     context['maintainers'] = User.objects.filter( \
51             userprofile__maintainer_projects = project)
52     context['n_patches'] = Patch.objects.filter(project = project,
53             archived = False).count()
54     context['n_archived_patches'] = Patch.objects.filter(project = project,
55             archived = True).count()
56
57     return render_to_response('patchwork/project.html', context)
58
59 def submitter_complete(request):
60     search = request.GET.get('q', '')
61     response = HttpResponse(mimetype = "text/plain")
62     if len(search) > 3:
63         queryset = Person.objects.filter(name__icontains = search)
64         json_serializer = serializers.get_serializer("json")()
65         json_serializer.serialize(queryset, ensure_ascii=False, stream=response)
66     return response