Beispiel #1
0
def save_file(id, data):
    if id == -1:
        file = file()
    else:
        file = get_file(id)

    populate(file, data, file)

    if id == -1:
        web.ctx.orm.add(file)
    else:
        web.ctx.orm.flush()
Beispiel #2
0
def save_file(id, data):
    if id == -1:
        file = file()
    else:
        file = get_file(id)

    populate(file, data, file)

    if id == -1:
        web.ctx.orm.add(file)
    else:
        web.ctx.orm.flush()
Beispiel #3
0
def save_category(id, data):
    if id == -1:
        category = Category()
    else:
        category = get_category(id)

    populate(category, data, Category)

    if id == -1:
        web.ctx.orm.add(category)
    else:
        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #4
0
def save_entity(id, data):
    if id == -1:
        entity = Entity()
    else:
        entity = get_entity(id)

    populate(entity, data, Entity)

    if id == -1:
        web.ctx.orm.add(entity)
    else:
        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #5
0
def save_model(id, data):
    if id == -1:
        model = Model()
    else:
        model = get_model(id)

    populate(model, data, Model)

    if id == -1:
        web.ctx.orm.add(model)
    else:
        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #6
0
def save_relation(id, data):
    if id == -1:
        relation = Relation()
    else:
        relation = get_relation(id)

    populate(relation, data, Relation)

    if id == -1:
        web.ctx.orm.add(relation)
    else:
        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #7
0
def save_entity(id, data):
    if id == -1:
        entity = Entity()
    else:
        entity = get_entity(id)

    populate(entity, data, Entity)

    if id == -1:
        web.ctx.orm.add(entity)
    else:
        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #8
0
def save_model(id, data):
    if id == -1:
        model = Model()
    else:
        model = get_model(id)

    populate(model, data, Model)

    if id == -1:
        web.ctx.orm.add(model)
    else:
        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #9
0
def save_relation(id, data):
    if id == -1:
        relation = Relation()
    else:
        relation = get_relation(id)

    populate(relation, data, Relation)

    if id == -1:
        web.ctx.orm.add(relation)
    else:
        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #10
0
def save_category(id, data):
    if id == -1:
        category = Category()
    else:
        category = get_category(id)

    populate(category, data, Category)

    if id == -1:
        web.ctx.orm.add(category)
    else:
        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #11
0
def save_template(id, data):
    if id == -1:
        template = Template()
    else:
        template = get_template(id)

    populate(template, data, Template)

    if id == -1:
        web.ctx.orm.add(template)
    else:
        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #12
0
def save_template(id, data):
    if id == -1:
        template = Template()
    else:
        template = get_template(id)

    populate(template, data, Template)

    if id == -1:
        web.ctx.orm.add(template)
    else:
        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #13
0
def save_group(id, data):
    if id == -1:
        group = Group()
    else:
        group = get_group_byid(id)

    populate(group, data, Group)

    for i in range(len(group.users)-1,-1,-1):
        del group.users[i]
    for uid in data.uids:
        group.users.append(get_user_byid(int(uid)))

    if id == -1:
        web.ctx.orm.add(group)
    else:
        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #14
0
def save_group(id, data):
    if id == -1:
        group = Group()
    else:
        group = get_group_byid(id)

    populate(group, data, Group)

    for i in range(len(group.users) - 1, -1, -1):
        del group.users[i]
    for uid in data.uids:
        group.users.append(get_user_byid(int(uid)))

    if id == -1:
        web.ctx.orm.add(group)
    else:
        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #15
0
def save_user(id, data):
    if id == -1:
        user = User()
        user.set_password(web.config.default_password);
    else:
        user = get_user_byid(id)

    populate(user, data, User)

    if hasattr(data, 'password') and data.password:
        user.set_password(data.password)

    for i in range(len(user.groups)-1,-1,-1):
        del user.groups[i]
    for gid in data.gids:
        user.groups.append(get_group_byid(int(gid)))

    if id == -1:
        web.ctx.orm.add(user)
    else:
        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #16
0
def save_field(id, data):
    if id == -1:
        field = Field()
    else:
        field = get_field(id)

    populate(field, data, Field)
    if hasattr(data, 'type'):
        if data.type == 'text':
            prop_dict = dict(lines=data.lines, editor=data.editor)
            field.props = str(prop_dict)
        elif data.type == 'select' or data.type == 'radio' or data.type == 'checkbox':
            prop_dict = dict(options=data.options)
            if data.type == 'select':
                prop_dict['is_multisel'] = data.is_multisel
            field.props = str(prop_dict)

    if id == -1:
        web.ctx.orm.add(field)
    else:
        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #17
0
def save_field(id, data):
    if id == -1:
        field = Field()
    else:
        field = get_field(id)

    populate(field, data, Field)
    if hasattr(data, 'type'):
        if data.type == 'text':
            prop_dict = dict(lines=data.lines, editor=data.editor)
            field.props = str(prop_dict)
        elif data.type == 'select' or data.type == 'radio' or data.type == 'checkbox':
            prop_dict = dict(options=data.options)
            if data.type == 'select':
                prop_dict['is_multisel'] = data.is_multisel
            field.props = str(prop_dict)

    if id == -1:
        web.ctx.orm.add(field)
    else:
        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #18
0
def save_user(id, data):
    if id == -1:
        user = User()
        user.set_password(web.config.default_password)
    else:
        user = get_user_byid(id)

    populate(user, data, User)

    if hasattr(data, 'password') and data.password:
        user.set_password(data.password)

    for i in range(len(user.groups) - 1, -1, -1):
        del user.groups[i]
    for gid in data.gids:
        user.groups.append(get_group_byid(int(gid)))

    if id == -1:
        web.ctx.orm.add(user)
    else:
        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #19
0
def save_info(model, id, base_data, data, sforms_data):
    model_cls = build_model(model)
    submodels = model.children
    submodel_cls_d = {}
    if submodels:
        for submodel in submodels:
            submodel_cls = build_model(submodel)
            submodel_cls_d[submodel.name] = submodel_cls

    subinfo_d = {}
    if id == -1:
        entity = Entity()
        info = model_cls()
        if submodel_cls_d:
            for smodel_name, submodel_cls in submodel_cls_d.items():
                if smodel_name in sforms_data:
                    subinfo_d[smodel_name] = [
                        submodel_cls()
                        for i in range(len(sforms_data[smodel_name]))
                    ]

    else:
        entity = get_entity(id)
        info = getattr(entity, model.name)
        if submodel_cls_d:
            for smodel_name, submodel_cls in submodel_cls_d.items():
                persist_infos = getattr(info, smodel_name + 's')
                if smodel_name in sforms_data:
                    subinfo_d[smodel_name] = persist_infos
                    for i in range(
                            len(sforms_data[smodel_name]) -
                            len(persist_infos)):
                        subinfo_d[smodel_name].append(submodel_cls())

    populate(entity, base_data, Entity)
    populate(info, data, model_cls)
    if subinfo_d:
        for smodel_name, subinfos in subinfo_d.items():
            for i, subinfo in enumerate(subinfos):
                sform_data = sforms_data[smodel_name][
                    i] if smodel_name in sforms_data else None
                if sform_data:
                    populate(subinfo, sform_data, submodel_cls_d[smodel_name],
                             '%s-%s' % (smodel_name, str(i)))
                    if subinfo.id is not None:
                        subinfo.will_delete = sform_data.will_delete

    for i in range(len(entity.categories) - 1, -1, -1):
        del entity.categories[i]
    for cid in base_data.cids:
        if cid:
            entity.categories.append(get_category(int(cid)))

    if id == -1:
        entity.model = model
        info.entity = entity
        if subinfo_d:
            for smodel_name, subinfos in subinfo_d.items():
                for subinfo in subinfos:
                    getattr(info, smodel_name + 's').append(subinfo)
                    web.ctx.orm.add(subinfo)

        web.ctx.orm.add(entity)
        web.ctx.orm.add(info)
    else:
        if subinfo_d:
            for smodel_name, subinfos in subinfo_d.items():
                for subinfo in subinfos:
                    if subinfo.id is None:
                        getattr(info, smodel_name + 's').append(subinfo)
                        web.ctx.orm.add(subinfo)
                    elif subinfo.will_delete:
                        persist_infos = getattr(info, smodel_name + 's')
                        persist_infos.remove(subinfo)
                        web.ctx.orm.delete(subinfo)

        web.ctx.orm.flush()
    web.ctx.orm.commit()
Beispiel #20
0
def save_info(model, id, base_data, data, sforms_data):
    model_cls = build_model(model)
    submodels = model.children
    submodel_cls_d = {}
    if submodels:
        for submodel in submodels:
            submodel_cls = build_model(submodel)
            submodel_cls_d[submodel.name] = submodel_cls

    subinfo_d = {}
    if id == -1:
        entity = Entity()
        info = model_cls()
        if submodel_cls_d:
            for smodel_name, submodel_cls in submodel_cls_d.items():
                if smodel_name in sforms_data:
                    subinfo_d[smodel_name] = [submodel_cls() for i in range(len(sforms_data[smodel_name]))]

    else:
        entity = get_entity(id)
        info = getattr(entity, model.name)
        if submodel_cls_d:
            for smodel_name, submodel_cls in submodel_cls_d.items():
                persist_infos = getattr(info, smodel_name+'s')
                if smodel_name in sforms_data:
                    subinfo_d[smodel_name] = persist_infos
                    for i in range(len(sforms_data[smodel_name])-len(persist_infos)):
                        subinfo_d[smodel_name].append(submodel_cls())

    populate(entity, base_data, Entity)
    populate(info, data, model_cls)
    if subinfo_d:
        for smodel_name, subinfos in subinfo_d.items():
            for i, subinfo in enumerate(subinfos):
                sform_data = sforms_data[smodel_name][i] if smodel_name in sforms_data else None
                if sform_data:
                    populate(subinfo, sform_data, submodel_cls_d[smodel_name], '%s-%s' % (smodel_name, str(i)))
                    if subinfo.id is not None:
                        subinfo.will_delete = sform_data.will_delete

    for i in range(len(entity.categories)-1,-1,-1):
        del entity.categories[i]
    for cid in base_data.cids:
        if cid:
            entity.categories.append(get_category(int(cid)))

    if id == -1:
        entity.model = model
        info.entity = entity
        if subinfo_d:
            for smodel_name, subinfos in subinfo_d.items():
                for subinfo in subinfos:
                    getattr(info, smodel_name+'s').append(subinfo)
                    web.ctx.orm.add(subinfo)

        web.ctx.orm.add(entity)
        web.ctx.orm.add(info)
    else:
        if subinfo_d:
            for smodel_name, subinfos in subinfo_d.items():
                for subinfo in subinfos:
                    if subinfo.id is None:
                        getattr(info, smodel_name+'s').append(subinfo)
                        web.ctx.orm.add(subinfo)
                    elif subinfo.will_delete:
                        persist_infos = getattr(info, smodel_name+'s')
                        persist_infos.remove(subinfo)
                        web.ctx.orm.delete(subinfo)

        web.ctx.orm.flush()
    web.ctx.orm.commit()