Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    def POST(self, mname):
        base_form = base_entity_form()
        form = entity_form(mname)
        model = get_model_by_name(mname)
        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': mname,
                '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.user_id = web.ctx.session._userid
        form_data = form.d
        new_entity(model, base_form_data, form_data)
        raise web.seeother('/entity/index')
Exemplo n.º 3
0
 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')
Exemplo n.º 4
0
 def GET(self):
     categories = category_tree()
     req = web.ctx.req
     req.update({
         'categories': categories,
         })
     return render.category_index(**req)
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 def GET(self):
     form = category_form()
     categories = category_tree()
     parent_id = web.input(parent_id=None).parent_id
     form.parent_id.set_value(parent_id)
     req = web.ctx.req
     req.update({
         'form': form,
         'categories': categories,
         })
     return render.category_edit(**req)
Exemplo n.º 7
0
 def POST(self):
     form = category_form()
     if not form.validates():
         categories = category_tree()
         req = web.ctx.req
         req.update({
             'form': form,
             'categories': categories,
             })
         return render.category_edit(**req)
     new_category(form.d)
     raise web.seeother('/category/index')
Exemplo n.º 8
0
 def GET(self, mname):
     model = get_model_by_name(mname)
     base_form = base_entity_form()
     form = entity_form(mname)
     categories = category_tree()
     req = web.ctx.req
     req.update({
         'base_form': base_form,
         'form': form,
         'mname': mname,
         'mtitle': model.title,
         'model': model,
         'categories': categories,
         })
     return render.entity_edit(**req)
Exemplo n.º 9
0
    def POST(self, mname):
        data = web.input(cids=[])
        base_form = base_entity_form()
        form = entity_form(mname)
        model = get_model_by_name(mname)
        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': mname,
                '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.user_id = web.ctx.session._userid
        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)))

        new_entity(model, base_form_data, form_data)
        raise web.seeother('/entity/index')
Exemplo n.º 10
0
 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)