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
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 bundle(request, bundle_id):
105 bundle = get_object_or_404(Bundle, id = bundle_id)
106 filter_settings = [(DelegateFilter, DelegateFilter.AnyDelegate)]
108 if request.method == 'POST' and request.POST.get('form') == 'bundle':
109 action = request.POST.get('action', '').lower()
110 if action == 'delete':
112 return HttpResponseRedirect(
113 django.core.urlresolvers.reverse(
114 'patchwork.views.user.profile')
116 elif action == 'update':
117 form = BundleForm(request.POST, instance = bundle)
121 form = BundleForm(instance = bundle)
123 context = generic_list(request, bundle.project,
124 'patchwork.views.bundle.bundle',
125 view_args = {'bundle_id': bundle_id},
126 filter_settings = filter_settings,
127 patches = bundle.patches.all())
129 context['bundle'] = bundle
130 context['bundleform'] = form
132 return render_to_response('patchwork/bundle.html', context)
135 def mbox(request, bundle_id):
136 bundle = get_object_or_404(Bundle, id = bundle_id)
137 response = HttpResponse(mimetype='text/plain')
138 response.write(bundle.mbox())
141 def public(request, username, bundlename):
142 user = get_object_or_404(User, username = username)
143 bundle = get_object_or_404(Bundle, name = bundlename, public = True)
144 filter_settings = [(DelegateFilter, DelegateFilter.AnyDelegate)]
145 context = generic_list(request, bundle.project,
146 'patchwork.views.bundle.public',
147 view_args = {'username': username, 'bundlename': bundlename},
148 filter_settings = filter_settings,
149 patches = bundle.patches.all())
151 context.update({'bundle': bundle,
153 return render_to_response('patchwork/bundle-public.html', context)