Beispiel #1
0
 def GET(self, mname):
     model = get_model_by_name(mname)
     eform = entity_form()
     form = info_form(mname)
     submodels = model.children
     formset = {}
     if submodels:
         for submodel in submodels:
             forms = [
                 info_form(submodel.name, '0'),
                 info_form(submodel.name, '__prefix__')
             ]
             subform = dict(prefix=submodel.name,
                            title=submodel.title,
                            forms=forms)
             formset.update({submodel.name: subform})
     categories = category_tree()
     req = web.ctx.req
     req.update({
         'eform': eform,
         'form': form,
         'formset': formset,
         'mname': mname,
         'mtitle': model.title,
         'model': model,
         'categories': categories,
     })
     return admin_render.info_edit(**req)
Beispiel #2
0
    def GET(self, mname, id):
        entity = get_entity(id)
        cids = [cate.id for cate in entity.categories]
        model = entity.model
        eform = entity_form()
        eform.cids.set_value(cids)
        form = info_form(model.name)
        info = getattr(entity, model.name)
        eform.fill(entity)
        eform.cids.value = cids
        form.fill(info)

        submodels = model.children
        formset = {}
        if submodels:
            for submodel in submodels:
                subinfos = getattr(info, submodel.name + 's')
                forms = []
                for i, subinfo in enumerate(subinfos):
                    subformobj = info_form(submodel.name, str(i))
                    subformobj.fill(subinfo, '%s-%s' % (submodel.name, str(i)))
                    subformobj.id = subinfo.id
                    forms.append(subformobj)
                forms.append(info_form(submodel.name, '__prefix__'))
                subform = dict(prefix=submodel.name,
                               title=submodel.title,
                               forms=forms)
                formset.update({submodel.name: subform})

        # 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(info, k)))

        categories = category_tree()
        data = web.input()
        req = web.ctx.req
        req.update({
            'eform': eform,
            'form': form,
            'formset': formset,
            'mname': model.name,
            'mtitle': model.title,
            'categories': categories,
        })
        return admin_render.info_edit(**req)
Beispiel #3
0
    def GET(self, mname, id):
        entity = get_entity(id)
        cids = [cate.id for cate in entity.categories]
        model = entity.model
        eform = entity_form()
        eform.cids.set_value(cids)
        form = info_form(model.name)
        info = getattr(entity, model.name)
        eform.fill(entity)
        eform.cids.value = cids
        form.fill(info)

        submodels = model.children
        formset = {}
        if submodels:
            for submodel in submodels:
                subinfos = getattr(info, submodel.name+'s')
                forms = []
                for i, subinfo in enumerate(subinfos):
                    subformobj = info_form(submodel.name, str(i))
                    subformobj.fill(subinfo, '%s-%s' % (submodel.name, str(i)))
                    subformobj.id = subinfo.id
                    forms.append(subformobj)
                forms.append(info_form(submodel.name, '__prefix__'))
                subform = dict(prefix=submodel.name, title=submodel.title, forms=forms)
                formset.update({submodel.name: subform})

        # 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(info, k)))

        categories = category_tree()
        data = web.input()
        req = web.ctx.req
        req.update({
            'eform': eform,
            'form': form,
            'formset': formset,
            'mname': model.name,
            'mtitle': model.title,
            'categories': categories,
        })
        return admin_render.info_edit(**req)
Beispiel #4
0
 def GET(self, mname):
     model = get_model_by_name(mname)
     eform = entity_form()
     form = info_form(mname)
     submodels = model.children
     formset = {}
     if submodels:
         for submodel in submodels:
             forms = [info_form(submodel.name, '0'), info_form(submodel.name, '__prefix__')]
             subform = dict(prefix=submodel.name, title=submodel.title, forms=forms)
             formset.update({submodel.name: subform})
     categories = category_tree()
     req = web.ctx.req
     req.update({
         'eform': eform,
         'form': form,
         'formset': formset,
         'mname': mname,
         'mtitle': model.title,
         'model': model,
         'categories': categories,
         })
     return admin_render.info_edit(**req)
Beispiel #5
0
    def POST(self, mname, id):
        entity = get_entity(id)
        model = entity.model
        eform = entity_form()
        form = info_form(model.name)
        data = web.input(cids=[])
        bv = eform.validates()
        v = form.validates()
        is_unique_slug = not get_other_entities(int(id), eform.slug.get_value())

        #if web.config.dev_debug:
        #    import pdb
        #    pdb.set_trace()

        submodels = model.children
        sfvs = []
        formset = {}
        if submodels:
            for submodel in submodels:
                forms_total = int(getattr(data, submodel.name+'-TOTAL_FORMS'))
                forms = []
                for i in range(forms_total):
                    subformobj = info_form(submodel.name, str(i))
                    sfv = subformobj.validates()
                    sfvs.append(sfv)
                    idkey = '%s-%d-%s' % (submodel.name, i, 'id')
                    subformobj.id = int(getattr(data, idkey)) if hasattr(data, idkey) else None
                    subformobj.will_delete = hasattr(data, '%s-%d-%s' % (submodel.name, i, 'DELETE'))
                    forms.append(subformobj)
                forms.append(info_form(submodel.name, '__prefix__'))
                subform = dict(prefix=submodel.name, title=submodel.title, forms=forms)
                formset.update({submodel.name: subform})

        sfsv = reduce(bool.__and__, sfvs) if sfvs else True

        if not bv or not v or not sfsv or not is_unique_slug:
            if not is_unique_slug:
                eform.slug.note = u"%s已存在,请重新指定。" % (eform.slug.get_value())
            categories = category_tree()
            eform.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({
                'eform': eform,
                'form': form,
                'formset': formset,
                'mname': model.name,
                'mtitle': model.title,
                'categories': categories,
            })
            return admin_render.info_edit(**req)
        eform_data = eform.d
        eform_data.cids = data.cids
        eform_data.updated_time = datetime.now()
        form_data = form.d
        sforms_data = {}
        if formset:
            for sform_name, subform in formset.items():
                formsnum = len(subform['forms'])
                for i, subformobj in enumerate(subform['forms']):
                    if i < formsnum-1:
                        sfdata = subformobj.d
                        sfdata.id = subformobj.id
                        sfdata.will_delete = subformobj.will_delete
                        sforms_data.setdefault(sform_name, []).append(sfdata)

        # 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_info(model, int(id), eform_data, form_data, sforms_data)
        raise web.seeother('/%s/list' % model.name)
Beispiel #6
0
    def POST(self, mname):
        data = web.input(cids=[])
        eform = entity_form()
        form = info_form(mname)
        model = get_model_by_name(mname)

        bv = eform.validates()
        v = form.validates()
        is_unique_slug = get_entity_by_slug(eform.slug.get_value()) is None

        submodels = model.children
        sfvs = []
        formset = {}
        if submodels:
            for submodel in submodels:
                forms_total = int(getattr(data, submodel.name+'-TOTAL_FORMS'))
                forms = []
                for i in range(forms_total):
                    subformobj = info_form(submodel.name, str(i))
                    sfv = subformobj.validates()
                    sfvs.append(sfv)
                    forms.append(subformobj)
                forms.append(info_form(submodel.name, '__prefix__'))
                subform = dict(prefix=submodel.name, title=submodel.title, forms=forms)
                formset.update({submodel.name: subform})

        sfsv = reduce(bool.__and__, sfvs) if sfvs else True

        if not bv or not v or not sfsv or not is_unique_slug:
            if not is_unique_slug:
                eform.slug.note = u"%s已存在,请重新指定。" % (eform.slug.get_value())
            categories = category_tree()
            eform.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({
                'eform': eform,
                'form': form,
                'formset': formset,
                'mname': mname,
                'mtitle': model.title,
                'categories': categories,
            })
            return admin_render.info_edit(**req)

        eform_data = eform.d
        eform_data.cids = data.cids
        eform_data.user_id = web.ctx.session._userid
        form_data = form.d

        sforms_data = {}
        if formset:
            for sform_name, subform in formset.items():
                formsnum = len(subform['forms'])
                for i, subformobj in enumerate(subform['forms']):
                    if i < formsnum-1:
                        sforms_data.setdefault(sform_name, []).append(subformobj.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_info(model, eform_data, form_data, sforms_data)
        raise web.seeother('/%s/list' % model.name)
Beispiel #7
0
    def POST(self, mname, id):
        entity = get_entity(id)
        model = entity.model
        eform = entity_form()
        form = info_form(model.name)
        data = web.input(cids=[])
        bv = eform.validates()
        v = form.validates()
        is_unique_slug = not get_other_entities(int(id),
                                                eform.slug.get_value())

        #if web.config.dev_debug:
        #    import pdb
        #    pdb.set_trace()

        submodels = model.children
        sfvs = []
        formset = {}
        if submodels:
            for submodel in submodels:
                forms_total = int(getattr(data,
                                          submodel.name + '-TOTAL_FORMS'))
                forms = []
                for i in range(forms_total):
                    subformobj = info_form(submodel.name, str(i))
                    sfv = subformobj.validates()
                    sfvs.append(sfv)
                    idkey = '%s-%d-%s' % (submodel.name, i, 'id')
                    subformobj.id = int(getattr(data, idkey)) if hasattr(
                        data, idkey) else None
                    subformobj.will_delete = hasattr(
                        data, '%s-%d-%s' % (submodel.name, i, 'DELETE'))
                    forms.append(subformobj)
                forms.append(info_form(submodel.name, '__prefix__'))
                subform = dict(prefix=submodel.name,
                               title=submodel.title,
                               forms=forms)
                formset.update({submodel.name: subform})

        sfsv = reduce(bool.__and__, sfvs) if sfvs else True

        if not bv or not v or not sfsv or not is_unique_slug:
            if not is_unique_slug:
                eform.slug.note = u"%s已存在,请重新指定。" % (eform.slug.get_value())
            categories = category_tree()
            eform.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({
                'eform': eform,
                'form': form,
                'formset': formset,
                'mname': model.name,
                'mtitle': model.title,
                'categories': categories,
            })
            return admin_render.info_edit(**req)
        eform_data = eform.d
        eform_data.cids = data.cids
        eform_data.updated_time = datetime.now()
        form_data = form.d
        sforms_data = {}
        if formset:
            for sform_name, subform in formset.items():
                formsnum = len(subform['forms'])
                for i, subformobj in enumerate(subform['forms']):
                    if i < formsnum - 1:
                        sfdata = subformobj.d
                        sfdata.id = subformobj.id
                        sfdata.will_delete = subformobj.will_delete
                        sforms_data.setdefault(sform_name, []).append(sfdata)

        # 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_info(model, int(id), eform_data, form_data, sforms_data)
        raise web.seeother('/%s/list' % model.name)
Beispiel #8
0
    def POST(self, mname):
        data = web.input(cids=[])
        eform = entity_form()
        form = info_form(mname)
        model = get_model_by_name(mname)

        bv = eform.validates()
        v = form.validates()
        is_unique_slug = get_entity_by_slug(eform.slug.get_value()) is None

        submodels = model.children
        sfvs = []
        formset = {}
        if submodels:
            for submodel in submodels:
                forms_total = int(getattr(data,
                                          submodel.name + '-TOTAL_FORMS'))
                forms = []
                for i in range(forms_total):
                    subformobj = info_form(submodel.name, str(i))
                    sfv = subformobj.validates()
                    sfvs.append(sfv)
                    forms.append(subformobj)
                forms.append(info_form(submodel.name, '__prefix__'))
                subform = dict(prefix=submodel.name,
                               title=submodel.title,
                               forms=forms)
                formset.update({submodel.name: subform})

        sfsv = reduce(bool.__and__, sfvs) if sfvs else True

        if not bv or not v or not sfsv or not is_unique_slug:
            if not is_unique_slug:
                eform.slug.note = u"%s已存在,请重新指定。" % (eform.slug.get_value())
            categories = category_tree()
            eform.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({
                'eform': eform,
                'form': form,
                'formset': formset,
                'mname': mname,
                'mtitle': model.title,
                'categories': categories,
            })
            return admin_render.info_edit(**req)

        eform_data = eform.d
        eform_data.cids = data.cids
        eform_data.user_id = web.ctx.session._userid
        form_data = form.d

        sforms_data = {}
        if formset:
            for sform_name, subform in formset.items():
                formsnum = len(subform['forms'])
                for i, subformobj in enumerate(subform['forms']):
                    if i < formsnum - 1:
                        sforms_data.setdefault(sform_name,
                                               []).append(subformobj.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_info(model, eform_data, form_data, sforms_data)
        raise web.seeother('/%s/list' % model.name)