from patchwork.requestcontext import PatchworkRequestContext
from django.http import HttpResponse, HttpResponseRedirect
import django.core.urlresolvers
-from patchwork.models import Patch, Bundle, Project
+from patchwork.models import Patch, Bundle, BundlePatch, Project
from patchwork.utils import get_patch_ids
from patchwork.forms import BundleForm, DeleteBundleForm
from patchwork.views import generic_list
from patchwork.filters import DelegateFilter
-from patchwork.paginator import Paginator
@login_required
def setbundle(request):
patch_id = request.POST.get('patch_id', None)
if patch_id:
patch = get_object_or_404(Patch, id = patch_id)
- bundle.patches.add(patch)
+ try:
+ bundle.append_patch(patch)
+ except Exception:
+ pass
bundle.save()
elif action == 'add':
bundle = get_object_or_404(Bundle,
for id in patch_ids:
try:
patch = Patch.objects.get(id = id)
- bundle.patches.add(patch)
- except ex:
+ bundle.append_patch(patch)
+ except:
pass
bundle.save()
if request.method == 'POST':
form_name = request.POST.get('form_name', '')
- if form_name == DeleteBundleForm.name:
- form = DeleteBundleForm(request.POST)
- if form.is_valid():
- bundle = get_object_or_404(Bundle,
- id = form.cleaned_data['bundle_id'])
- bundle.delete()
+ if form_name == DeleteBundleForm.name:
+ form = DeleteBundleForm(request.POST)
+ if form.is_valid():
+ bundle = get_object_or_404(Bundle,
+ id = form.cleaned_data['bundle_id'])
+ bundle.delete()
bundles = Bundle.objects.filter(owner = request.user)
for bundle in bundles:
bundle.delete_form = DeleteBundleForm(auto_id = False,
- initial = {'bundle_id': bundle.id})
+ initial = {'bundle_id': bundle.id})
context['bundles'] = bundles
else:
form = BundleForm(instance = bundle)
+ if request.method == 'POST' and request.POST.get('form') == 'reorderform':
+ order = get_object_or_404(BundlePatch, bundle = bundle,
+ patch__id = request.POST.get('order_start')).order
+
+ for patch_id in request.POST.getlist('neworder'):
+ bundlepatch = get_object_or_404(BundlePatch,
+ bundle = bundle, patch__id = patch_id)
+ bundlepatch.order = order
+ bundlepatch.save()
+ order += 1
+
context = generic_list(request, bundle.project,
'patchwork.views.bundle.bundle',
view_args = {'bundle_id': bundle_id},
filter_settings = filter_settings,
- patches = bundle.patches.all())
+ patches = bundle.ordered_patches(),
+ editable_order = True)
context['bundle'] = bundle
context['bundleform'] = form
bundle = get_object_or_404(Bundle, id = bundle_id)
response = HttpResponse(mimetype='text/plain')
response['Content-Disposition'] = 'attachment; filename=bundle-%d.mbox' % \
- bundle.id
+ bundle.id
response.write(bundle.mbox())
return response
def public(request, username, bundlename):
user = get_object_or_404(User, username = username)
- bundle = get_object_or_404(Bundle, name = bundlename, public = True)
+ bundle = get_object_or_404(Bundle, name = bundlename, owner = user,
+ public = True)
filter_settings = [(DelegateFilter, DelegateFilter.AnyDelegate)]
context = generic_list(request, bundle.project,
'patchwork.views.bundle.public',
filter_settings = filter_settings,
patches = bundle.patches.all())
- context.update({'bundle': bundle,
- 'user': user});
+ context['bundle'] = bundle
+
return render_to_response('patchwork/bundle-public.html', context)