web/ldt/text/models.py
author ymh <ymh.work@gmail.com>
Wed, 17 Nov 2010 10:28:55 +0100
changeset 15 37e051f2264d
parent 9 22ab430e9b64
child 17 683ce4109c28
permissions -rw-r--r--
csrf protection unplug
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     1
from django.conf import settings
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     2
from django.db import models
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     3
from django.utils.translation import ugettext_lazy as _
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     4
from ldt.core.models import Document, Owner
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     5
from django.contrib.auth.models import User
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     6
import tagging.fields
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     7
from utils import generate_uuid
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     8
import os.path
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     9
import uuid
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    10
#from django.core.management.validation import max_length
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    11
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    12
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    13
class Annotation(models.Model):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    14
    external_id = models.CharField(max_length=1024, null=False, unique=True, default=generate_uuid, verbose_name=_('annotation.external_id'))
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    15
    uri = models.CharField(max_length=1024, verbose_name=_('annotation.uri'))
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    16
    tags = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('annotation.tags'))
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    17
    title = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('annotation.title'))
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    18
    description = models.TextField(null=True, blank=True, verbose_name=_('annotation.description'))
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    19
    text = models.TextField(null=True, blank=True, verbose_name=_('annotation.text'))
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    20
    color = models.CharField(max_length=1024, verbose_name=_('annotation.color'))
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    21
    creator = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('creator.title'))
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    22
    contributor = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('contributor.title'))
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    23
    creation_date = models.DateTimeField(auto_now_add=True, verbose_name=_('annotation.creation_date'))
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    24
    update_date = models.DateTimeField(auto_now=True, verbose_name=_('annotation.update_date'))
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    25
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    26
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    27
    def __unicode__(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    28
        return unicode(self.external_id) + u": " + unicode(self.title)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    29
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    30
    @staticmethod
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    31
    def create_annotation(external_id, uri=None, tags=None, title=None, description=None, text=None, color=None, creator=None, contributor=None, creation_date=None, update_date=None):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    32
        annotation = Annotation(external_id=external_id, uri=uri, tags=tags, title=title, description=description, text=text, color=color, creator=creator, contributor=contributor, creation_date=creation_date, update_date=update_date)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    33
        annotation.save()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    34
        
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    35
        return annotation
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    36
    
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    37