X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=apps%2Fpatchwork%2Futils.py;h=fa26aef7e674d8be9ee299e0556cdc93c4ca1e0a;hb=7d9334e879857f8a380bc9509b6cbf9972cecc25;hp=76679c39e30fb0d09a6bb22d0440dd40348605da;hpb=05d26756d7e7f254d5631a0649aeac5fd3a58ca8;p=patchwork diff --git a/apps/patchwork/utils.py b/apps/patchwork/utils.py index 76679c3..fa26aef 100644 --- a/apps/patchwork/utils.py +++ b/apps/patchwork/utils.py @@ -19,7 +19,7 @@ from patchwork.forms import MultiplePatchForm -from patchwork.models import Bundle, Project, State, UserProfile +from patchwork.models import Bundle, Project, BundlePatch, State, UserProfile from django.conf import settings from django.shortcuts import render_to_response, get_object_or_404 @@ -43,15 +43,20 @@ class Order(object): 'date': 'date', 'name': 'name', 'state': 'state__ordering', - 'submitter': 'submitter__name' + 'submitter': 'submitter__name', + 'delegate': 'delegate__username', } - default_order = 'date' + default_order = ('date', True) - def __init__(self, str = None): + def __init__(self, str = None, editable = False): self.reversed = False + self.editable = editable + + if self.editable: + return if str is None or str == '': - self.order = self.default_order + (self.order, self.reversed) = self.default_order return reversed = False @@ -60,7 +65,7 @@ class Order(object): reversed = True if str not in self.order_map.keys(): - self.order = self.default_order + (self.order, self.reversed) = self.default_order return self.order = str @@ -92,38 +97,44 @@ def set_bundle(user, project, action, data, patches, context): # set up the bundle bundle = None if action == 'create': + bundle_name = data['bundle_name'].strip() + if not bundle_name: + return ['No bundle name was specified'] + bundle = Bundle(owner = user, project = project, - name = data['bundle_name']) + name = bundle_name) bundle.save() - str = 'added to new bundle "%s"' % bundle.name - auth_required = False + context.add_message("Bundle %s created" % bundle.name) elif action =='add': bundle = get_object_or_404(Bundle, id = data['bundle_id']) - str = 'added to bundle "%s"' % bundle.name - auth_required = False elif action =='remove': bundle = get_object_or_404(Bundle, id = data['removed_bundle_id']) - str = 'removed from bundle "%s"' % bundle.name - auth_required = False if not bundle: return ['no such bundle'] for patch in patches: if action == 'create' or action == 'add': - bundle.patches.add(patch) + bundlepatch_count = BundlePatch.objects.filter(bundle = bundle, + patch = patch).count() + if bundlepatch_count == 0: + bundle.append_patch(patch) + context.add_message("Patch '%s' added to bundle %s" % \ + (patch.name, bundle.name)) + else: + context.add_message("Patch '%s' already in bundle %s" % \ + (patch.name, bundle.name)) elif action == 'remove': - bundle.patches.remove(patch) - - if len(patches) > 0: - if len(patches) == 1: - str = 'patch ' + str - else: - str = 'patches ' + str - context.add_message(str) + try: + bp = BundlePatch.objects.get(bundle = bundle, patch = patch) + bp.delete() + context.add_message("Patch '%s' removed from bundle %s\n" % \ + (patch.name, bundle.name)) + except Exception: + pass bundle.save() @@ -142,8 +153,6 @@ def set_patches(user, project, action, data, patches, context): str = '' - print "action: ", action - # this may be a bundle action, which doesn't modify a patch. in this # case, don't require a valid form, or patch editing permissions if action in bundle_actions: @@ -174,7 +183,7 @@ def set_patches(user, project, action, data, patches, context): str = 'archived' elif action == 'unarchive': - patch.archived = True + patch.archived = False patch.save() str = 'un-archived'