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 django.contrib.auth.decorators import login_required
22 from patchwork.requestcontext import PatchworkRequestContext
23 from django.shortcuts import render_to_response, get_object_or_404
24 from django.contrib import auth
25 from django.http import HttpResponse, HttpResponseRedirect
26 from patchwork.models import Project, Patch, Bundle, Person, UserProfile, \
27 UserPersonConfirmation, State
28 from patchwork.forms import MultiplePatchForm, UserProfileForm, \
30 from patchwork.utils import Order, get_patch_ids
31 from patchwork.filters import DelegateFilter
32 from patchwork.paginator import Paginator
33 from patchwork.views import generic_list
34 from django.template.loader import render_to_string
35 from django.template import Context
36 from django.conf import settings
37 from django.core.mail import send_mail
38 import django.core.urlresolvers
42 context = PatchworkRequestContext(request)
44 if request.method == 'POST':
45 form = UserProfileForm(instance = request.user.get_profile(),
50 form = UserProfileForm(instance = request.user.get_profile())
52 context.project = request.user.get_profile().primary_project
53 context['bundles'] = Bundle.objects.filter(owner = request.user)
54 context['profileform'] = form
56 people = Person.objects.filter(user = request.user)
57 context['linked_emails'] = people
58 context['linkform'] = UserPersonLinkForm()
60 return render_to_response('patchwork/profile.html', context)
64 context = PatchworkRequestContext(request)
66 form = UserPersonLinkForm(request.POST)
67 if request.method == 'POST':
68 form = UserPersonLinkForm(request.POST)
70 conf = UserPersonConfirmation(user = request.user,
71 email = form.cleaned_data['email'])
72 context['confirmation'] = conf
75 send_mail('Patchwork email address confirmation',
76 render_to_string('patchwork/user-link.mail',
78 settings.DEFAULT_FROM_EMAIL,
79 [form.cleaned_data['email']])
82 context['confirmation'] = None
83 context['error'] = 'An error occurred during confirmation. ' + \
84 'Please try again later'
85 context['linkform'] = form
87 return render_to_response('patchwork/user-link.html', context)
90 def link_confirm(request, key):
91 context = PatchworkRequestContext(request)
92 confirmation = get_object_or_404(UserPersonConfirmation, key = key)
94 errors = confirmation.confirm()
96 context['errors'] = errors
98 context['person'] = Person.objects.get(email = confirmation.email)
100 return render_to_response('patchwork/user-link-confirm.html', context)
103 def unlink(request, person_id):
104 context = PatchworkRequestContext(request)
105 person = get_object_or_404(Person, id = person_id)
107 if request.method == 'POST':
108 if person.email != request.user.email:
112 url = django.core.urlresolvers.reverse('patchwork.views.user.profile')
113 return HttpResponseRedirect(url)
117 def todo_lists(request):
120 for project in Project.objects.all():
121 patches = request.user.get_profile().todo_patches(project = project)
122 if not patches.count():
125 todo_lists.append({'project': project, 'n_patches': patches.count()})
127 if len(todo_lists) == 1:
128 return todo_list(request, todo_lists[0]['project'].linkname)
130 context = PatchworkRequestContext(request)
131 context['todo_lists'] = todo_lists
132 context.project = request.user.get_profile().primary_project
133 return render_to_response('patchwork/todo-lists.html', context)
136 def todo_list(request, project_id):
137 project = get_object_or_404(Project, linkname = project_id)
138 patches = request.user.get_profile().todo_patches(project = project)
139 filter_settings = [(DelegateFilter,
140 {'delegate': request.user})]
142 context = generic_list(request, project,
143 'patchwork.views.user.todo_list',
144 view_args = {'project_id': project.linkname},
145 filter_settings = filter_settings,
148 context['action_required_states'] = \
149 State.objects.filter(action_required = True).all()
150 return render_to_response('patchwork/todo-list.html', context)