web/ldt/text/utils.py
changeset 9 22ab430e9b64
child 21 1a061f244254
child 22 83b28fc0d731
equal deleted inserted replaced
8:5bb249eefdd1 9:22ab430e9b64
       
     1 import uuid
       
     2 import django.core.urlresolvers
       
     3 from django.conf import settings
       
     4 from ldt.text.models import *
       
     5 import urllib
       
     6 import datetime
       
     7 import lxml.etree
       
     8 import base64
       
     9 
       
    10 __BOOLEAN_DICT = {
       
    11     'false':False,
       
    12     'true':True,
       
    13     '0':False,
       
    14     '1':True,
       
    15     't': True,
       
    16     'f':False
       
    17 }
       
    18 
       
    19 def boolean_convert(bool):
       
    20     if bool is None:
       
    21         return False
       
    22     if bool is True or bool is False:
       
    23         return bool
       
    24     key = str(bool).lower()
       
    25     return __BOOLEAN_DICT.get(key, False)
       
    26 
       
    27 
       
    28 def generate_uuid():
       
    29     return unicode(uuid.uuid1())
       
    30 
       
    31 
       
    32 def normalize_tags(list):
       
    33     nlist=[]
       
    34     for tag in list:
       
    35         tag = tag.lower()
       
    36         nlist.append(tag)
       
    37     taglist = dict().fromkeys(nlist).keys()    
       
    38     
       
    39     return taglist
       
    40 
       
    41 
       
    42 def create_empty_annotation():
       
    43     iri = lxml.etree.Element('iri')
       
    44     doc = lxml.etree.ElementTree(iri)
       
    45     
       
    46     textannotation = lxml.etree.SubElement(iri, 'text-annotation')
       
    47     id = lxml.etree.SubElement(textannotation,'id')
       
    48     uri = lxml.etree.SubElement(textannotation,'uri')
       
    49     tags = lxml.etree.SubElement(textannotation,'tags')
       
    50     
       
    51     content = lxml.etree.SubElement(textannotation,'content')
       
    52     color = lxml.etree.SubElement(content,'color')
       
    53     description = lxml.etree.SubElement(content,'description')
       
    54     title = lxml.etree.SubElement(content,'title')
       
    55     text = lxml.etree.SubElement(content,'text')
       
    56     
       
    57     meta = lxml.etree.SubElement(textannotation,'meta')
       
    58     contributor = lxml.etree.SubElement(meta, "contributor")
       
    59     creator = lxml.etree.SubElement(meta, "creator")
       
    60     creationdate = lxml.etree.SubElement(meta, "created")
       
    61     updatedate = lxml.etree.SubElement(meta, "modified")
       
    62 
       
    63     return doc
       
    64