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 if request.method == 'POST':
67 form = UserPersonLinkForm(request.POST)
69 conf = UserPersonConfirmation(user = request.user,
70 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']])
81 context['confirmation'] = None
82 context['error'] = 'An error occurred during confirmation. ' + \
83 'Please try again later'
85 form = UserPersonLinkForm()
86 context['linkform'] = form
88 return render_to_response('patchwork/user-link.html', context)
91 def link_confirm(request, key):
92 context = PatchworkRequestContext(request)
93 confirmation = get_object_or_404(UserPersonConfirmation, key = key)
95 errors = confirmation.confirm()
97 context['errors'] = errors
99 context['person'] = Person.objects.get(email = confirmation.email)
101 return render_to_response('patchwork/user-link-confirm.html', context)
104 def unlink(request, person_id):
105 context = PatchworkRequestContext(request)
106 person = get_object_or_404(Person, id = person_id)
108 if request.method == 'POST':
109 if person.email != request.user.email:
113 url = django.core.urlresolvers.reverse('patchwork.views.user.profile')
114 return HttpResponseRedirect(url)
118 def todo_lists(request):
121 for project in Project.objects.all():
122 patches = request.user.get_profile().todo_patches(project = project)
123 if not patches.count():
126 todo_lists.append({'project': project, 'n_patches': patches.count()})
128 if len(todo_lists) == 1:
129 return todo_list(request, todo_lists[0]['project'].linkname)
131 context = PatchworkRequestContext(request)
132 context['todo_lists'] = todo_lists
133 context.project = request.user.get_profile().primary_project
134 return render_to_response('patchwork/todo-lists.html', context)
137 def todo_list(request, project_id):
138 project = get_object_or_404(Project, linkname = project_id)
139 patches = request.user.get_profile().todo_patches(project = project)
140 filter_settings = [(DelegateFilter,
141 {'delegate': request.user})]
143 context = generic_list(request, project,
144 'patchwork.views.user.todo_list',
145 view_args = {'project_id': project.linkname},
146 filter_settings = filter_settings,
149 context['action_required_states'] = \
150 State.objects.filter(action_required = True).all()
151 return render_to_response('patchwork/todo-list.html', context)