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, UserPersonConfirmation, \
27 from patchwork.forms import UserProfileForm, UserPersonLinkForm
28 from patchwork.filters import DelegateFilter
29 from patchwork.views import generic_list
30 from django.template.loader import render_to_string
31 from django.conf import settings
32 from django.core.mail import send_mail
33 import django.core.urlresolvers
37 context = PatchworkRequestContext(request)
39 if request.method == 'POST':
40 form = UserProfileForm(instance = request.user.get_profile(),
45 form = UserProfileForm(instance = request.user.get_profile())
47 context.project = request.user.get_profile().primary_project
48 context['bundles'] = Bundle.objects.filter(owner = request.user)
49 context['profileform'] = form
51 people = Person.objects.filter(user = request.user)
52 context['linked_emails'] = people
53 context['linkform'] = UserPersonLinkForm()
55 return render_to_response('patchwork/profile.html', context)
59 context = PatchworkRequestContext(request)
61 if request.method == 'POST':
62 form = UserPersonLinkForm(request.POST)
64 conf = UserPersonConfirmation(user = request.user,
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, key):
87 context = PatchworkRequestContext(request)
88 confirmation = get_object_or_404(UserPersonConfirmation, key = key)
90 errors = confirmation.confirm()
92 context['errors'] = errors
94 context['person'] = Person.objects.get(email = confirmation.email)
96 return render_to_response('patchwork/user-link-confirm.html', context)
99 def unlink(request, person_id):
100 context = PatchworkRequestContext(request)
101 person = get_object_or_404(Person, id = person_id)
103 if request.method == 'POST':
104 if person.email != request.user.email:
108 url = django.core.urlresolvers.reverse('patchwork.views.user.profile')
109 return HttpResponseRedirect(url)
113 def todo_lists(request):
116 for project in Project.objects.all():
117 patches = request.user.get_profile().todo_patches(project = project)
118 if not patches.count():
121 todo_lists.append({'project': project, 'n_patches': patches.count()})
123 if len(todo_lists) == 1:
124 return todo_list(request, todo_lists[0]['project'].linkname)
126 context = PatchworkRequestContext(request)
127 context['todo_lists'] = todo_lists
128 context.project = request.user.get_profile().primary_project
129 return render_to_response('patchwork/todo-lists.html', context)
132 def todo_list(request, project_id):
133 project = get_object_or_404(Project, linkname = project_id)
134 patches = request.user.get_profile().todo_patches(project = project)
135 filter_settings = [(DelegateFilter,
136 {'delegate': request.user})]
138 context = generic_list(request, project,
139 'patchwork.views.user.todo_list',
140 view_args = {'project_id': project.linkname},
141 filter_settings = filter_settings,
144 context['action_required_states'] = \
145 State.objects.filter(action_required = True).all()
146 return render_to_response('patchwork/todo-list.html', context)