def save_entity(model, id, base_data, data): model_cls = build_model(model) if id == -1: base_entity = Entity() entity = model_cls() else: base_entity = get_base_entity(id) entity = getattr(base_entity, model.name) populate(base_entity, base_data, Entity) populate(entity, data, model_cls) for i in range(len(base_entity.categories)-1,-1,-1): del base_entity.categories[i] for cid in base_data.cids: if cid: base_entity.categories.append(get_category(int(cid))) if id == -1: base_entity.model = model entity.entity = base_entity web.ctx.orm.add(base_entity) web.ctx.orm.add(entity) else: web.ctx.orm.flush()
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()
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()
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()
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()
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()
def save_field(id, data): if id == -1: field = Field() else: field = get_field(id) populate(field, data, Field) if id == -1: web.ctx.orm.add(field) else: web.ctx.orm.flush()
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()
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()
def save_user(id, data): if id == -1: user = User() user.set_password(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()