web/ldt/text/utils.py
author ymh <ymh.work@gmail.com>
Mon, 13 Dec 2010 23:55:19 +0100
changeset 22 83b28fc0d731
parent 9 22ab430e9b64
child 24 9e19b7ae3780
permissions -rw-r--r--
improve on ldt test framework start migration for text test
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22
83b28fc0d731 improve on ldt test framework
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
     1
from django.conf import settings
83b28fc0d731 improve on ldt test framework
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
     2
import base64
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     3
import django.core.urlresolvers
22
83b28fc0d731 improve on ldt test framework
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
     4
import lxml.etree
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     5
import urllib
22
83b28fc0d731 improve on ldt test framework
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
     6
import uuid
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     7
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     8
__BOOLEAN_DICT = {
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     9
    'false':False,
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    10
    'true':True,
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    11
    '0':False,
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    12
    '1':True,
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    13
    't': True,
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    14
    'f':False
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    15
}
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    16
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    17
def boolean_convert(bool):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    18
    if bool is None:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    19
        return False
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    20
    if bool is True or bool is False:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    21
        return bool
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    22
    key = str(bool).lower()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    23
    return __BOOLEAN_DICT.get(key, False)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    24
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    25
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    26
def generate_uuid():
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    27
    return unicode(uuid.uuid1())
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    28
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    29
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    30
def normalize_tags(list):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    31
    nlist=[]
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    32
    for tag in list:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    33
        tag = tag.lower()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    34
        nlist.append(tag)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    35
    taglist = dict().fromkeys(nlist).keys()    
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    36
    
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    37
    return taglist
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    38