some annoation api

This commit is contained in:
j 2010-12-28 19:34:28 +05:30
commit da8aa69bf1
2 changed files with 102 additions and 24 deletions

View file

@ -23,6 +23,8 @@ from ox.utils import json
from ox import stripTags
from ox.normalize import canonicalTitle, canonicalName
import utils
class Layer(models.Model):
class Meta:
@ -70,7 +72,7 @@ class Annotation(models.Model):
start = models.FloatField(default=-1)
stop = models.FloatField(default=-1)
type = models.CharField(blank=True, max_length=255)
layer = models.ForeignKey(Layer)
value = models.TextField()
def editable(self, user):
@ -81,6 +83,23 @@ class Annotation(models.Model):
return True
return False
def html(self):
if self.layer.type == 'string':
return utils.html_parser(self.value)
else:
return self.value
def json(self):
return {
'id': self.id,
'user': self.user.username,
'start': self.start,
'stop': self.start,
'value': self.value,
'value_html': self.html(),
'layer': self.layer.name
}
def __unicode__(self):
return "%s/%s-%s" %(self.item, self.start, self.stop)