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
20 from django.contrib.auth.decorators import login_required
21 from django.contrib.auth.models import User
22 from django.shortcuts import render_to_response, get_object_or_404
23 from patchwork.requestcontext import PatchworkRequestContext
24 from django.http import HttpResponse, HttpResponseRedirect
25 import django.core.urlresolvers
26 from patchwork.models import Patch, Bundle, Project
27 from patchwork.utils import get_patch_ids
28 from patchwork.forms import BundleForm, DeleteBundleForm
29 from patchwork.views import generic_list
30 from patchwork.filters import DelegateFilter
31 from patchwork.paginator import Paginator
34 def setbundle(request):
35 context = PatchworkRequestContext(request)
39 if request.method == 'POST':
40 action = request.POST.get('action', None)
43 elif action == 'create':
44 project = get_object_or_404(Project,
45 id = request.POST.get('project'))
46 bundle = Bundle(owner = request.user, project = project,
47 name = request.POST['name'])
49 patch_id = request.POST.get('patch_id', None)
51 patch = get_object_or_404(Patch, id = patch_id)
52 bundle.patches.add(patch)
55 bundle = get_object_or_404(Bundle,
56 owner = request.user, id = request.POST['id'])
59 patch_id = request.get('patch_id', None)
63 patch_ids = get_patch_ids(request.POST)
67 patch = Patch.objects.get(id = id)
68 bundle.patches.add(patch)
73 elif action == 'delete':
75 bundle = Bundle.objects.get(owner = request.user,
76 id = request.POST['id'])
84 bundle = get_object_or_404(Bundle, owner = request.user,
85 id = request.POST['bundle_id'])
87 if 'error' in context:
91 return HttpResponseRedirect(
92 django.core.urlresolvers.reverse(
93 'patchwork.views.bundle.bundle',
94 kwargs = {'bundle_id': bundle.id}
98 return HttpResponseRedirect(
99 django.core.urlresolvers.reverse(
100 'patchwork.views.bundle.list')
104 def bundles(request):
105 context = PatchworkRequestContext(request)
107 if request.method == 'POST':
108 form_name = request.POST.get('form_name', '')
110 if form_name == DeleteBundleForm.name:
111 form = DeleteBundleForm(request.POST)
113 bundle = get_object_or_404(Bundle,
114 id = form.cleaned_data['bundle_id'])
117 bundles = Bundle.objects.filter(owner = request.user)
118 for bundle in bundles:
119 bundle.delete_form = DeleteBundleForm(auto_id = False,
120 initial = {'bundle_id': bundle.id})
122 context['bundles'] = bundles
124 return render_to_response('patchwork/bundles.html', context)
127 def bundle(request, bundle_id):
128 bundle = get_object_or_404(Bundle, id = bundle_id)
129 filter_settings = [(DelegateFilter, DelegateFilter.AnyDelegate)]
131 if request.method == 'POST' and request.POST.get('form') == 'bundle':
132 action = request.POST.get('action', '').lower()
133 if action == 'delete':
135 return HttpResponseRedirect(
136 django.core.urlresolvers.reverse(
137 'patchwork.views.user.profile')
139 elif action == 'update':
140 form = BundleForm(request.POST, instance = bundle)
144 form = BundleForm(instance = bundle)
146 context = generic_list(request, bundle.project,
147 'patchwork.views.bundle.bundle',
148 view_args = {'bundle_id': bundle_id},
149 filter_settings = filter_settings,
150 patches = bundle.patches.all())
152 context['bundle'] = bundle
153 context['bundleform'] = form
155 return render_to_response('patchwork/bundle.html', context)
158 def mbox(request, bundle_id):
159 bundle = get_object_or_404(Bundle, id = bundle_id)
160 response = HttpResponse(mimetype='text/plain')
161 response['Content-Disposition'] = 'attachment; filename=bundle-%d.mbox' % \
163 response.write(bundle.mbox())
166 def public(request, username, bundlename):
167 user = get_object_or_404(User, username = username)
168 bundle = get_object_or_404(Bundle, name = bundlename, public = True)
169 filter_settings = [(DelegateFilter, DelegateFilter.AnyDelegate)]
170 context = generic_list(request, bundle.project,
171 'patchwork.views.bundle.public',
172 view_args = {'username': username, 'bundlename': bundlename},
173 filter_settings = filter_settings,
174 patches = bundle.patches.all())
176 context['bundle'] = bundle
178 return render_to_response('patchwork/bundle-public.html', context)