forked from 0x2620/pandora
fixup edit backend
This commit is contained in:
parent
f521b54f5a
commit
f122fb5327
2 changed files with 23 additions and 16 deletions
|
@ -54,7 +54,7 @@ class Edit(models.Model):
|
||||||
|
|
||||||
def add_clip(self, data):
|
def add_clip(self, data):
|
||||||
clip = Clip(edit=self)
|
clip = Clip(edit=self)
|
||||||
if 'annotation' in data:
|
if 'annotation' in data and data['annotation']:
|
||||||
clip.annotation = Annotation.objects.get(public_id=data['annotation'])
|
clip.annotation = Annotation.objects.get(public_id=data['annotation'])
|
||||||
else:
|
else:
|
||||||
clip.item = Item.objects.get(itemId=data['item'])
|
clip.item = Item.objects.get(itemId=data['item'])
|
||||||
|
@ -309,7 +309,7 @@ class Clip(models.Model):
|
||||||
'index': self.index
|
'index': self.index
|
||||||
}
|
}
|
||||||
if self.annotation:
|
if self.annotation:
|
||||||
data['annotation'] = self.annotation.public_id
|
data['item'], data['annotation'] = self.annotation.public_id.split('/')
|
||||||
data['in'] = self.annotation.start
|
data['in'] = self.annotation.start
|
||||||
data['out'] = self.annotation.end
|
data['out'] = self.annotation.end
|
||||||
data['parts'] = self.annotation.item.json['parts']
|
data['parts'] = self.annotation.item.json['parts']
|
||||||
|
|
|
@ -23,36 +23,41 @@ def get_edit_or_404_json(id):
|
||||||
return get_object_or_404_json(models.Edit, user__username=username, name=name)
|
return get_object_or_404_json(models.Edit, user__username=username, name=name)
|
||||||
|
|
||||||
@login_required_json
|
@login_required_json
|
||||||
def addClip(request):
|
def addClips(request):
|
||||||
'''
|
'''
|
||||||
takes {
|
takes {
|
||||||
edit: string,
|
edit: string,
|
||||||
item: string,
|
clips: []
|
||||||
in: float,
|
item: string,
|
||||||
out: float,
|
in: float,
|
||||||
annotation: string
|
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 {
|
returns {
|
||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
response = json_response()
|
response = json_response()
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
edit = get_edit_or_404_json(data['edit'])
|
edit = get_edit_or_404_json(data['edit'])
|
||||||
|
clips = []
|
||||||
if edit.editable(request.user):
|
if edit.editable(request.user):
|
||||||
clip = edit.add_clip(data)
|
for c in data['clips']:
|
||||||
if not clip:
|
clip = edit.add_clip(c)
|
||||||
response = json_response(status=500, text='invalid in/out')
|
if not clip:
|
||||||
else:
|
response = json_response(status=500, text='invalid in/out')
|
||||||
response['data'] = clip.json(request.user)
|
return render_to_json_response(response)
|
||||||
|
else:
|
||||||
|
clips.append(clip.json(request.user))
|
||||||
|
response['data']['clips'] = clips
|
||||||
else:
|
else:
|
||||||
response = json_response(status=403, text='permission denied')
|
response = json_response(status=403, text='permission denied')
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(addClip, cache=False)
|
actions.register(addClips, cache=False)
|
||||||
|
|
||||||
|
|
||||||
@login_required_json
|
@login_required_json
|
||||||
def removeClip(request):
|
def removeClips(request):
|
||||||
'''
|
'''
|
||||||
takes {
|
takes {
|
||||||
edit: string
|
edit: string
|
||||||
|
@ -72,10 +77,11 @@ def removeClip(request):
|
||||||
if edit.editable(request.user):
|
if edit.editable(request.user):
|
||||||
for clip in edit.clips.filter(id__in=ids):
|
for clip in edit.clips.filter(id__in=ids):
|
||||||
clip.delete()
|
clip.delete()
|
||||||
|
response['data'] = edit.json(user=request.user)
|
||||||
else:
|
else:
|
||||||
response = json_response(status=403, text='permission denied')
|
response = json_response(status=403, text='permission denied')
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(removeClip, cache=False)
|
actions.register(removeClips, cache=False)
|
||||||
|
|
||||||
@login_required_json
|
@login_required_json
|
||||||
def editClip(request):
|
def editClip(request):
|
||||||
|
@ -97,6 +103,7 @@ def editClip(request):
|
||||||
if clip.annotation:
|
if clip.annotation:
|
||||||
clip.start = clip.annotation.start
|
clip.start = clip.annotation.start
|
||||||
clip.end = clip.annotation.end
|
clip.end = clip.annotation.end
|
||||||
|
clip.item = clip.annotation.item
|
||||||
clip.annotation = None
|
clip.annotation = None
|
||||||
setattr(clip, {'in': 'start', 'out': 'end'}.get(key), float(data[key]))
|
setattr(clip, {'in': 'start', 'out': 'end'}.get(key), float(data[key]))
|
||||||
if not clip.annotation:
|
if not clip.annotation:
|
||||||
|
|
Loading…
Reference in a new issue