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 GET(self, id): form = category_form() category = get_category(id) categories = category_tree() form.fill(category) req = web.ctx.req req.update({ 'form': form, 'categories': categories, }) return render.category_edit(**req)