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.http import HttpResponseRedirect
25 from patchwork.models import Project, Bundle, Person, EmailConfirmation, State
26 from patchwork.forms import UserProfileForm, UserPersonLinkForm
27 from patchwork.filters import DelegateFilter
28 from patchwork.views import generic_list
29 from django.template.loader import render_to_string
30 from django.conf import settings
31 from django.core.mail import send_mail
32 import django.core.urlresolvers
36 context = PatchworkRequestContext(request)
38 if request.method == 'POST':
39 form = UserProfileForm(instance = request.user.get_profile(),
44 form = UserProfileForm(instance = request.user.get_profile())
46 context.project = request.user.get_profile().primary_project
47 context['bundles'] = Bundle.objects.filter(owner = request.user)
48 context['profileform'] = form
50 people = Person.objects.filter(user = request.user)
51 context['linked_emails'] = people
52 context['linkform'] = UserPersonLinkForm()
54 return render_to_response('patchwork/profile.html', context)
58 context = PatchworkRequestContext(request)
60 if request.method == 'POST':
61 form = UserPersonLinkForm(request.POST)
63 conf = EmailConfirmation(type = 'userperson',
65 email = form.cleaned_data['email'])
67 context['confirmation'] = conf
70 send_mail('Patchwork email address confirmation',
71 render_to_string('patchwork/user-link.mail',
73 settings.DEFAULT_FROM_EMAIL,
74 [form.cleaned_data['email']])
76 context['confirmation'] = None
77 context['error'] = 'An error occurred during confirmation. ' + \
78 'Please try again later'
80 form = UserPersonLinkForm()
81 context['linkform'] = form
83 return render_to_response('patchwork/user-link.html', context)
86 def link_confirm(request, conf):
87 context = PatchworkRequestContext(request)
90 person = Person.objects.get(email__iexact = conf.email)
91 except Person.DoesNotExist:
92 person = Person(email = conf.email)
94 person.link_to_user(conf.user)
98 context['person'] = person
100 return render_to_response('patchwork/user-link-confirm.html', context)
103 def unlink(request, person_id):
104 person = get_object_or_404(Person, id = person_id)
106 if request.method == 'POST':
107 if person.email != request.user.email:
111 url = django.core.urlresolvers.reverse('patchwork.views.user.profile')
112 return HttpResponseRedirect(url)
116 def todo_lists(request):
119 for project in Project.objects.all():
120 patches = request.user.get_profile().todo_patches(project = project)
121 if not patches.count():
124 todo_lists.append({'project': project, 'n_patches': patches.count()})
126 if len(todo_lists) == 1:
127 return todo_list(request, todo_lists[0]['project'].linkname)
129 context = PatchworkRequestContext(request)
130 context['todo_lists'] = todo_lists
131 context.project = request.user.get_profile().primary_project
132 return render_to_response('patchwork/todo-lists.html', context)
135 def todo_list(request, project_id):
136 project = get_object_or_404(Project, linkname = project_id)
137 patches = request.user.get_profile().todo_patches(project = project)
138 filter_settings = [(DelegateFilter,
139 {'delegate': request.user})]
141 context = generic_list(request, project,
142 'patchwork.views.user.todo_list',
143 view_args = {'project_id': project.linkname},
144 filter_settings = filter_settings,
147 context['action_required_states'] = \
148 State.objects.filter(action_required = True).all()
149 return render_to_response('patchwork/todo-list.html', context)