Exemplo n.º 1
0
def upgrade_types():
    from infogami.core.db import _create_type, tdbsetup

    tdbsetup()
    type = db.get_type(ctx.site, "type/type")
    types = tdb.Things(parent=ctx.site, type=type)
    types = [
        t for t in types
        if 'properties' not in t.d and 'is_primitive' not in t.d
    ]
    primitives = dict(int='type/int',
                      integer='type/int',
                      string='type/string',
                      text='type/text')

    newtypes = {}
    for t in types:
        properties = []
        backreferences = []
        print(t, t.d, file=web.debug)
        if t.name == 'type/site':
            continue
        for name, value in t.d.items():
            p = web.storage(name=name)
            typename = web.lstrips(value, "thing ")

            if typename.startswith('#'):
                typename, property_name = typename.lstrip('#').split('.')
                p.type = db.get_type(ctx.site, typename)
                p.property_name = property_name
                backreferences.append(p)
                continue

            if typename.endswith('*'):
                typename = typename[:-1]
                p.unique = False
            else:
                p.unique = True
            if typename in primitives:
                typename = primitives[typename]
            p.type = db.get_type(ctx.site, typename)
            properties.append(p)
        _create_type(ctx.site, t.name, properties, backreferences)
Exemplo n.º 2
0
def upgrade_types():
    from infogami.core.db import _create_type, tdbsetup
    
    tdbsetup()
    type = db.get_type(ctx.site, "type/type")
    types = tdb.Things(parent=ctx.site, type=type)
    types = [t for t in types if 'properties' not in t.d and 'is_primitive' not in t.d]
    primitives = dict(int='type/int', integer='type/int', string='type/string', text='type/text')

    newtypes = {}
    for t in types:
        properties = []
        backreferences = []
        print >> web.debug, t, t.d
        if t.name == 'type/site':
            continue
        for name, value in t.d.items():
            p = web.storage(name=name)
            typename = web.lstrips(value, "thing ")

            if typename.startswith('#'):
                typename, property_name = typename.lstrip('#').split('.')
                p.type = db.get_type(ctx.site, typename)
                p.property_name = property_name
                backreferences.append(p)
                continue
                
            if typename.endswith('*'):
                typename = typename[:-1]
                p.unique = False
            else:
                p.unique = True
            if typename in primitives:
                typename = primitives[typename]
            p.type = db.get_type(ctx.site, typename)
            properties.append(p)
        _create_type(ctx.site, t.name, properties, backreferences)
Exemplo n.º 3
0
def create_type(type_name, properties={}):
    def props():
        for pname, ptype_name in properties.items():
            yield dict(name=pname, type=get_type(ptype_name), unique=True)

    return db._create_type(get_site(), type_name, list(props()))
Exemplo n.º 4
0
def create_type(type_name, properties={}):
    def props():
        for pname, ptype_name in properties.items():
            yield dict(name=pname, type=get_type(ptype_name), unique=True)

    return db._create_type(get_site(), type_name, list(props()))