web/ldt/ldt_utils/models.py
author wakimd
Sun, 14 Nov 2010 20:25:22 +0100
changeset 1 3a30d255c235
child 9 22ab430e9b64
permissions -rw-r--r--
First version of API with tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     1
from django.conf import settings
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     2
from django.db import models
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     3
from django.utils.translation import ugettext_lazy as _
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     4
from ldt.core.models import Document, Owner
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     5
from django.contrib.auth.models import User
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     6
import tagging.fields
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     7
from utils import generate_uuid
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     8
import lxml.etree
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     9
import os.path
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    10
import uuid
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    11
import lucene
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    12
from ldt.ldt_utils import STORE, ANALYZER
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    13
#from django.core.management.validation import max_length
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    14
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    15
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    16
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    17
class Annotation(models.Model):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    18
    id = models.CharField(max_length=1024, primary_key=True, unique=True, default=generate_uuid, verbose_name=_('annotation.id'))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    19
    uri = models.CharField(max_length=1024, verbose_name=_('annotation.uri'))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    20
    tags = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('annotation.tags'))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    21
    title = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('annotation.title'))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    22
    description = models.TextField(null=True, blank=True, verbose_name=_('annotation.description'))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    23
    text = models.TextField(null=True, blank=True, verbose_name=_('annotation.text'))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    24
    color = models.CharField(max_length=1024, verbose_name=_('annotation.color'))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    25
    creator = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('creator.title'))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    26
    contributor = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('contributor.title'))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    27
    creation_date = models.DateTimeField(auto_now_add=True, verbose_name=_('annotation.creation_date'))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    28
    update_date = models.DateTimeField(auto_now=True, verbose_name=_('annotation.update_date'))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    29
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    30
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    31
    def __unicode__(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    32
        return unicode(self.id) + u": " + unicode(self.title)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    33
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    34
    @staticmethod
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    35
    def create_annotation(id, uri=None, tags=None, title=None, description=None, text=None, color=None, creator=None, contributor=None, creation_date=None, update_date=None):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    36
        annotation = Annotation(id=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)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    37
        annotation.save()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    38
        
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    39
        return annotation
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    40
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    41
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    42
#class Author(models.Model):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    43
#
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    44
#    handle = models.CharField(max_length=512, unique=True, blank=True, null=True)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    45
#    email = models.EmailField(unique=False, blank=True, null=True)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    46
#    firstname = models.CharField(max_length=512, blank=True, null=True)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    47
#    lastname = models.CharField(max_length=512, blank=True, null=True)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    48
#    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    49
#    def __unicode__(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    50
#        return unicode(self.id) + " - " + self.handle + ", " + self.email + ", " + self.firstname + " " + self.lastname
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    51