X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=apps%2Fpatchwork%2Futils.py;h=e41ffb629635f73559fe410b7e18440fa0a878bd;hb=c2c6a408c7764fa29389ce160f52776c9308d50a;hp=5bd6925b6bf0065ee2beaf30b60f354c2d4de5c0;hpb=6ce62d26739ebf0dd81ecff5284adf3fbe2aed23;p=patchwork diff --git a/apps/patchwork/utils.py b/apps/patchwork/utils.py index 5bd6925..e41ffb6 100644 --- a/apps/patchwork/utils.py +++ b/apps/patchwork/utils.py @@ -18,10 +18,8 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -from patchwork.forms import MultiplePatchForm -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 +from patchwork.models import Bundle, Project, BundlePatch +from django.shortcuts import get_object_or_404 def get_patch_ids(d, prefix = 'patch_id'): ids = [] @@ -97,8 +95,12 @@ 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() context.add_message("Bundle %s created" % bundle.name) @@ -113,13 +115,15 @@ def set_bundle(user, project, action, data, patches, context): for patch in patches: if action == 'create' or action == 'add': - try: + 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)) - except Exception, ex: - context.add_message("Couldn't add patch '%s' to bundle: %s" % \ - (patch.name, ex.message)) + else: + context.add_message("Patch '%s' already in bundle %s" % \ + (patch.name, bundle.name)) elif action == 'remove': try: @@ -133,69 +137,3 @@ def set_bundle(user, project, action, data, patches, context): bundle.save() return [] - - -def set_patches(user, project, action, data, patches, context): - errors = [] - form = MultiplePatchForm(project = project, data = data) - - try: - project = Project.objects.get(id = data['project']) - except: - errors = ['No such project'] - return (errors, form) - - str = '' - - # 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: - errors = set_bundle(user, project, action, data, patches, context) - return (errors, form) - - if not form.is_valid(): - errors = ['The submitted form data was invalid'] - return (errors, form) - - for patch in patches: - if not patch.is_editable(user): - errors.append('You don\'t have permissions to edit the ' + \ - 'patch "%s"' \ - % patch.name) - continue - - if action == 'update': - form.save(patch) - str = 'updated' - - elif action == 'ack': - pass - - elif action == 'archive': - patch.archived = True - patch.save() - str = 'archived' - - elif action == 'unarchive': - patch.archived = True - patch.save() - str = 'un-archived' - - elif action == 'delete': - patch.delete() - str = 'un-archived' - - - if len(patches) > 0: - if len(patches) == 1: - str = 'patch ' + str - else: - str = 'patches ' + str - context.add_message(str) - - return (errors, form) - -def userprofile_register_callback(user): - profile = UserProfile(user = user) - profile.save() -