From 132cbe30ac9d45149063e2fdf418aaaef44797cd Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 9 Feb 2011 14:28:52 +0000 Subject: [PATCH] annotations --- pandora/annotation/models.py | 1 - pandora/annotation/views.py | 27 ++++++++++++++++----------- pandora/archive/models.py | 5 ++++- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index 2083af09..27544676 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -87,7 +87,6 @@ class Annotation(models.Model): 'in': self.start, 'out': self.end, 'value': self.value, - 'value_html': self.html(), 'created': self.created.strftime('%Y-%m-%dT%H:%M:%SZ'), 'modified': self.modified.strftime('%Y-%m-%dT%H:%M:%SZ') } diff --git a/pandora/annotation/views.py b/pandora/annotation/views.py index f1f48510..c87af88e 100644 --- a/pandora/annotation/views.py +++ b/pandora/annotation/views.py @@ -7,6 +7,8 @@ from ox.django.decorators import login_required_json from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, json_response import models +from item.models import Item + from api.actions import actions @@ -38,8 +40,8 @@ def addAnnotation(request): param data { item: itemId, layer: layerId, - start: float, - end: float, + in: float, + out: float, value: string } return {'status': {'code': int, 'text': string}, @@ -49,19 +51,19 @@ def addAnnotation(request): } ''' data = json.loads(request.POST['data']) - for key in ('item', 'layer', 'start', 'end', 'value'): + for key in ('item', 'layer', 'in', 'out', 'value'): if key not in data: return render_to_json_response(json_response(status=400, text='invalid data')) - item = get_object_or_404_json(models.Item, itemId=data['item']) - layer = get_object_or_404_json(models.Layer, layerId=data['layer']) + item = get_object_or_404_json(Item, itemId=data['item']) + layer = get_object_or_404_json(models.Layer, name=data['layer']) annotation = models.Annotation( item=item, layer=layer, user=request.user, - start=float(data['start']), end=float(data['end']), + start=float(data['in']), end=float(data['out']), value=data['value']) annotation.save() response = json_response() @@ -94,8 +96,8 @@ def editAnnotation(request): ''' param data { id:, - start: float, - end: float, + in: float, + out: float, value: string, } return {'status': {'code': int, 'text': string}, @@ -105,9 +107,12 @@ def editAnnotation(request): ''' response = json_response({}) data = json.loads(request.POST['data']) - layer = get_object_or_404_json(models.Layer, pk=data['id']) - if layer.editable(request.user): - response = json_response(status=501, text='not implemented') + a = get_object_or_404_json(models.Annotation, pk=data['id']) + if a.editable(request.user): + a.value = data['value'] + a.start = data['in'] + a.end = data['out'] + a.save() else: response = json_response(status=403, text='permission denied') return render_to_json_response(response) diff --git a/pandora/archive/models.py b/pandora/archive/models.py index b380079d..6dff8da8 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -206,9 +206,12 @@ class File(models.Model): return srt srts = re.compile('(\d\d:\d\d:\d\d[,.]\d\d\d)\s*-->\s*(\d\d:\d\d:\d\d[,.]\d\d\d)\s*(.+?)\n\n', re.DOTALL) + i = 0 for s in srts.findall(data): - _s = {'in': parseTime(s[0]), 'out': parseTime(s[1]), 'value': s[2].strip()} + _s = {'id': str(i), + 'in': parseTime(s[0]), 'out': parseTime(s[1]), 'value': s[2].strip()} srt.append(_s) + i += 1 return srt def editable(self, user):