示例#1
0
文件: entity.py 项目: leoomo/pycms
 def POST(self, id):
     base_entity = get_base_entity(id)
     model = base_entity.model
     base_form = base_entity_form()
     form = entity_form(model.name)
     data = web.input()
     bv = base_form.validates()
     v = form.validates()
     if not bv or not v:
         categories = category_tree()
         data = web.input(cids=[])
         base_form.cids.set_value(data.cids)
         req = web.ctx.req
         req.update({
             'base_form': base_form,
             'form': form,
             'mname': model.name,
             'mtitle': model.title,
             'categories': categories,
         })
         return render.entity_edit(**req)
     data = web.input(cids=[])
     base_form_data = base_form.d
     base_form_data.cids = data.cids
     base_form_data.updated_time = datetime.now()
     form_data = form.d
     save_entity(model, int(id), base_form_data, form_data)
     raise web.seeother('/entity/index')
示例#2
0
文件: dbutil.py 项目: F9O/govsite
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()
示例#3
0
文件: entity.py 项目: F9O/govsite
    def GET(self, id):
        base_entity = get_base_entity(id)
        cids = [cate.id for cate in base_entity.categories]
        model = base_entity.model
        base_form = base_entity_form()
        base_form.cids.set_value(cids)
        form = entity_form(model.name)
        entity = getattr(base_entity, model.name)
        base_form.fill(base_entity)
        base_form.cids.value = cids
        form.fill(entity)
        # populate multi value field
        pd = []
        for item in form.inputs:
            if isinstance(item, MyCheckboxGroup):
                pd.append(item.name)
        for k in pd:
            getattr(form, k).set_value(eval(getattr(entity, k)))

        categories = category_tree()
        data = web.input()
        req = web.ctx.req
        req.update({
            'base_form': base_form,
            'form': form,
            'mname': model.name,
            'mtitle': model.title,
            'categories': categories,
        })
        return render.entity_edit(**req)
示例#4
0
文件: entity.py 项目: leoomo/pycms
 def GET(self, mname, id):
     base_entity = get_base_entity(id)
     model = base_entity.model
     entity = getattr(base_entity, model.name)
     category_ancestors = get_entitys_category_ancestors(base_entity)
     req = web.ctx.req
     req.update({"base_entity": base_entity, "entity": entity, "category_ancestors": category_ancestors})
     template = model.template.display_file
     return render.render(template, **req)
示例#5
0
文件: entity.py 项目: leoomo/pycms
 def GET(self, id):
     base_entity = get_base_entity(id)
     model = base_entity.model
     entity = getattr(base_entity, model.name)
     if entity is not None:
         web.ctx.orm.delete(entity)
     if base_entity is not None:
         web.ctx.orm.delete(base_entity)
     raise web.seeother('/entity/index')
示例#6
0
文件: entity.py 项目: F9O/govsite
    def POST(self, id):
        base_entity = get_base_entity(id)
        model = base_entity.model
        base_form = base_entity_form()
        form = entity_form(model.name)
        data = web.input(cids=[])
        bv = base_form.validates()
        v = form.validates()
        if not bv or not v:
            categories = category_tree()
            base_form.cids.set_value(data.cids)
            # populate multi value field
            pd = {}
            for item in form.inputs:
                if isinstance(item, MyCheckboxGroup):
                    pd[item.name] = []
            pdata = web.input(**pd)
            for k in pd.keys():
                getattr(form, k).set_value(getattr(pdata, k))

            req = web.ctx.req
            req.update({
                'base_form': base_form,
                'form': form,
                'mname': model.name,
                'mtitle': model.title,
                'categories': categories,
            })
            return render.entity_edit(**req)
        base_form_data = base_form.d
        base_form_data.cids = data.cids
        base_form_data.updated_time = datetime.now()
        form_data = form.d
        # populate multi value field
        pd = {}
        for item in form.inputs:
            if isinstance(item, MyCheckboxGroup):
                pd[item.name] = []
        pdata = web.input(**pd)
        for k in pd.keys():
            setattr(form_data, k, str(getattr(pdata, k)))

        save_entity(model, int(id), base_form_data, form_data)
        raise web.seeother('/entity/index')
示例#7
0
文件: entity.py 项目: leoomo/pycms
 def GET(self, id):
     base_entity = get_base_entity(id)
     cids = [cate.id for cate in base_entity.categories]
     model = base_entity.model
     base_form = base_entity_form()
     base_form.cids.set_value(cids)
     form = entity_form(model.name)
     entity = getattr(base_entity, model.name)
     base_form.fill(base_entity)
     base_form.cids.value = cids
     form.fill(entity)
     categories = category_tree()
     data = web.input()
     req = web.ctx.req
     req.update({
         'base_form': base_form,
         'form': form,
         'mname': model.name,
         'mtitle': model.title,
         'categories': categories,
     })
     return render.entity_edit(**req)