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, BundlePatch, 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
33 def setbundle(request):
34 context = PatchworkRequestContext(request)
38 if request.method == 'POST':
39 action = request.POST.get('action', None)
42 elif action == 'create':
43 project = get_object_or_404(Project,
44 id = request.POST.get('project'))
45 bundle = Bundle(owner = request.user, project = project,
46 name = request.POST['name'])
48 patch_id = request.POST.get('patch_id', None)
50 patch = get_object_or_404(Patch, id = patch_id)
52 bundle.append_patch(patch)
57 bundle = get_object_or_404(Bundle,
58 owner = request.user, id = request.POST['id'])
61 patch_id = request.get('patch_id', None)
65 patch_ids = get_patch_ids(request.POST)
69 patch = Patch.objects.get(id = id)
70 bundle.append_patch(patch)
75 elif action == 'delete':
77 bundle = Bundle.objects.get(owner = request.user,
78 id = request.POST['id'])
86 bundle = get_object_or_404(Bundle, owner = request.user,
87 id = request.POST['bundle_id'])
89 if 'error' in context:
93 return HttpResponseRedirect(
94 django.core.urlresolvers.reverse(
95 'patchwork.views.bundle.bundle',
96 kwargs = {'bundle_id': bundle.id}
100 return HttpResponseRedirect(
101 django.core.urlresolvers.reverse(
102 'patchwork.views.bundle.list')
106 def bundles(request):
107 context = PatchworkRequestContext(request)
109 if request.method == 'POST':
110 form_name = request.POST.get('form_name', '')
112 if form_name == DeleteBundleForm.name:
113 form = DeleteBundleForm(request.POST)
115 bundle = get_object_or_404(Bundle,
116 id = form.cleaned_data['bundle_id'])
119 bundles = Bundle.objects.filter(owner = request.user)
120 for bundle in bundles:
121 bundle.delete_form = DeleteBundleForm(auto_id = False,
122 initial = {'bundle_id': bundle.id})
124 context['bundles'] = bundles
126 return render_to_response('patchwork/bundles.html', context)
129 def bundle(request, bundle_id):
130 bundle = get_object_or_404(Bundle, id = bundle_id)
131 filter_settings = [(DelegateFilter, DelegateFilter.AnyDelegate)]
133 if request.method == 'POST' and request.POST.get('form') == 'bundle':
134 action = request.POST.get('action', '').lower()
135 if action == 'delete':
137 return HttpResponseRedirect(
138 django.core.urlresolvers.reverse(
139 'patchwork.views.user.profile')
141 elif action == 'update':
142 form = BundleForm(request.POST, instance = bundle)
146 form = BundleForm(instance = bundle)
148 if request.method == 'POST' and request.POST.get('form') == 'reorderform':
149 order = get_object_or_404(BundlePatch, bundle = bundle,
150 patch__id = request.POST.get('order_start')).order
152 for patch_id in request.POST.getlist('neworder'):
153 bundlepatch = get_object_or_404(BundlePatch,
154 bundle = bundle, patch__id = patch_id)
155 bundlepatch.order = order
159 context = generic_list(request, bundle.project,
160 'patchwork.views.bundle.bundle',
161 view_args = {'bundle_id': bundle_id},
162 filter_settings = filter_settings,
163 patches = bundle.ordered_patches(),
164 editable_order = True)
166 context['bundle'] = bundle
167 context['bundleform'] = form
169 return render_to_response('patchwork/bundle.html', context)
172 def mbox(request, bundle_id):
173 bundle = get_object_or_404(Bundle, id = bundle_id)
174 response = HttpResponse(mimetype='text/plain')
175 response['Content-Disposition'] = 'attachment; filename=bundle-%d.mbox' % \
177 response.write(bundle.mbox())
180 def public(request, username, bundlename):
181 user = get_object_or_404(User, username = username)
182 bundle = get_object_or_404(Bundle, name = bundlename, owner = user,
184 filter_settings = [(DelegateFilter, DelegateFilter.AnyDelegate)]
185 context = generic_list(request, bundle.project,
186 'patchwork.views.bundle.public',
187 view_args = {'username': username, 'bundlename': bundlename},
188 filter_settings = filter_settings,
189 patches = bundle.patches.all())
191 context['bundle'] = bundle
193 return render_to_response('patchwork/bundle-public.html', context)