Gitlab CSE Unil

annotations.py 1.15 KB
Newer Older
Julien Furrer's avatar
Julien Furrer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# coding=utf-8
from __future__ import unicode_literals
# import json
from django.db import models
from django.utils.translation import ugettext as _
from django.conf import settings
from annotables import AnObj


class Annotation(models.Model):
    """
    """
    # TODO: add description for model Annotation

    owner = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_("owner"))
    annotable = models.ForeignKey(AnObj, verbose_name=_("annotable"), related_name='annotations')
    item = models.TextField(verbose_name=_("Paper.js item"))
    order = models.IntegerField(verbose_name=_("order"), default=0)

    comment = models.CharField(max_length=512, verbose_name=_("comment"), blank=True, default="")

    creation_date = models.DateTimeField(auto_now_add=True)
    modification_date = models.DateTimeField(auto_now=True)

    class Meta:
        app_label = "adim"
        ordering = ('owner__id', '-order', 'modification_date')

    # def save(self, *args, **kwargs):
    #     try:
    #         item = json.loads(self.item)
    #     except (TypeError, ValueError):
    #         item = None
    #
    #     super(Annotation, self).save(*args, **kwargs)