Пример #1
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')
Пример #2
0
def _entity_form(mname, refresh=False):
    if mname in _entity_forms_cache and not refresh:
        return _entity_forms_cache[mname]
    else:
        remove_form_from_cache(mname)
        model = get_model_by_name(mname)
        form_items = []
        for fld in model.fields:
            if fld.type == 'select' or fld.type == 'radio' or fld.type == 'checkbox':
                prop_dict = eval(fld.props)
                item = WIDGET_TYPE[fld.type](fld.name, prop_dict['options'], description=fld.title)
            else:
                item = WIDGET_TYPE[fld.type](fld.name, description=fld.title)

            if fld.required:
                item.required = True
                item.validators = (vnotnull,)

            form_items.append(item)

        for rel in model.relations:
            form_items.append(WIDGET_TYPE['integer']('%s_id' % rel.target, description=rel.title))

        form = web.form.Form(*form_items)
        _entity_forms_cache[mname] = form
        return form
Пример #3
0
 def GET(self, mname):
     req = web.ctx.req
     data = web.input()
     cid = data.cid
     model = get_model_by_name(mname)
     entities = get_entities(model, cid)
     req.update({"entities": entities, "cid": cid, "mname": mname, "mtitle": model.title})
     return render.index(**req)
Пример #4
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)
Пример #5
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')
Пример #6
0
def _entity_form(mname, refresh=False):
    if mname in _entity_forms_cache and not refresh:
        return _entity_forms_cache[mname]
    else:
        remove_form_from_cache(mname)
        model = get_model_by_name(mname)
        form_items = []
        for fld in model.fields:
            if fld.required:
                form_items.append(WIDGET_TYPE[fld.type](fld.name, vnotnull, required=True, description=fld.title))
            else:
                form_items.append(WIDGET_TYPE[fld.type](fld.name, description=fld.title))
        for rel in model.relations:
            form_items.append(WIDGET_TYPE['integer']('%s_id' % rel.target, description=rel.title))

        form = web.form.Form(*form_items)
        _entity_forms_cache[mname] = form
        return form