From f122fb53270720fb904f0a8347064c183c89cc3a Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 13 Jul 2013 23:00:39 +0000 Subject: [PATCH] fixup edit backend --- pandora/edit/models.py | 4 ++-- pandora/edit/views.py | 35 +++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/pandora/edit/models.py b/pandora/edit/models.py index 9efa82fd8..dcd6d00ec 100644 --- a/pandora/edit/models.py +++ b/pandora/edit/models.py @@ -54,7 +54,7 @@ class Edit(models.Model): def add_clip(self, data): clip = Clip(edit=self) - if 'annotation' in data: + if 'annotation' in data and data['annotation']: clip.annotation = Annotation.objects.get(public_id=data['annotation']) else: clip.item = Item.objects.get(itemId=data['item']) @@ -309,7 +309,7 @@ class Clip(models.Model): 'index': self.index } if self.annotation: - data['annotation'] = self.annotation.public_id + data['item'], data['annotation'] = self.annotation.public_id.split('/') data['in'] = self.annotation.start data['out'] = self.annotation.end data['parts'] = self.annotation.item.json['parts'] diff --git a/pandora/edit/views.py b/pandora/edit/views.py index 91e4f5b49..3dd3558cd 100644 --- a/pandora/edit/views.py +++ b/pandora/edit/views.py @@ -23,36 +23,41 @@ def get_edit_or_404_json(id): return get_object_or_404_json(models.Edit, user__username=username, name=name) @login_required_json -def addClip(request): +def addClips(request): ''' takes { edit: string, - item: string, - in: float, - out: float, - annotation: string + clips: [] + item: string, + in: float, + out: float, + annotation: string } - add clip with item/in/out or annotation to edit with id + add clips with item/in/out or annotation to edit with id returns { } ''' response = json_response() data = json.loads(request.POST['data']) edit = get_edit_or_404_json(data['edit']) + clips = [] if edit.editable(request.user): - clip = edit.add_clip(data) - if not clip: - response = json_response(status=500, text='invalid in/out') - else: - response['data'] = clip.json(request.user) + for c in data['clips']: + clip = edit.add_clip(c) + if not clip: + response = json_response(status=500, text='invalid in/out') + return render_to_json_response(response) + else: + clips.append(clip.json(request.user)) + response['data']['clips'] = clips else: response = json_response(status=403, text='permission denied') return render_to_json_response(response) -actions.register(addClip, cache=False) +actions.register(addClips, cache=False) @login_required_json -def removeClip(request): +def removeClips(request): ''' takes { edit: string @@ -72,10 +77,11 @@ def removeClip(request): if edit.editable(request.user): for clip in edit.clips.filter(id__in=ids): clip.delete() + response['data'] = edit.json(user=request.user) else: response = json_response(status=403, text='permission denied') return render_to_json_response(response) -actions.register(removeClip, cache=False) +actions.register(removeClips, cache=False) @login_required_json def editClip(request): @@ -97,6 +103,7 @@ def editClip(request): if clip.annotation: clip.start = clip.annotation.start clip.end = clip.annotation.end + clip.item = clip.annotation.item clip.annotation = None setattr(clip, {'in': 'start', 'out': 'end'}.get(key), float(data[key])) if not clip.annotation: