validate in/out values of edit clips

This commit is contained in:
j 2013-07-13 11:53:13 +00:00
parent f94f25d7c7
commit 2473dfd231
2 changed files with 18 additions and 3 deletions

View file

@ -65,6 +65,11 @@ class Edit(models.Model):
clip.index = 0
else:
clip.index +=1
# dont add clip if in/out are invalid
if not clip.annotation:
duration = clip.item.sort.duration
if clip.start >= clip.end or clip.start >= duration or clip.end > duration:
return False
clip.save()
return clip

View file

@ -41,6 +41,9 @@ def addClip(request):
edit = get_edit_or_404_json(data['edit'])
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)
else:
response = json_response(status=403, text='permission denied')
@ -87,6 +90,7 @@ def editClip(request):
response = json_response()
data = json.loads(request.POST['data'])
clip = get_object_or_404_json(models.Clip, pk=ox.fromAZ(data['id']))
valid = False
if clip.edit.editable(request.user):
for key in ('in', 'out'):
if key in data:
@ -95,6 +99,12 @@ def editClip(request):
clip.end = clip.annotation.end
clip.annotation = None
setattr(clip, {'in': 'start', 'out': 'end'}.get(key), float(data[key]))
if not clip.annotation:
duration = clip.item.sort.duration
if clip.start >= clip.end or clip.start >= duration or clip.end > duration:
response = json_response(status=500, text='invalid in/out')
valid = False
if valid:
clip.save()
response['data'] = clip.json(user=request.user)
else: