当前位置: 首页>>代码示例>>Python>>正文


Python SQLFORM.vars[v]方法代码示例

本文整理汇总了Python中gluon.SQLFORM.vars[v]方法的典型用法代码示例。如果您正苦于以下问题:Python SQLFORM.vars[v]方法的具体用法?Python SQLFORM.vars[v]怎么用?Python SQLFORM.vars[v]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gluon.SQLFORM的用法示例。


在下文中一共展示了SQLFORM.vars[v]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dupform

# 需要导入模块: from gluon import SQLFORM [as 别名]
# 或者: from gluon.SQLFORM import vars[v] [as 别名]
    def dupform(self, rargs=None, rvars=None, copylabel=None,
                deletable=True, showid=True, dbio=True, formstyle='ul'):
        """
        """
        db = current.db
        rjs = ''
        flash = ''
        duplink = ''
        tablename = rargs[0]
        rowid = rargs[1]
        orderby = rvars['orderby'] or 'id'
        restrictor = rvars['restrictor'] or None
        collation = rvars['collation'] or None
        postprocess = rvars['postprocess'] or None
        copylabel = copylabel if copylabel else 'Make a copy of this record'
        dbio = False if 'dbio' in list(rvars.keys()) and rvars['dbio'] == 'False' else True

        # create a link for adding a new row to the table
        duplink = A(copylabel,
                    _href=URL('plugin_listandedit',
                                'dupAndEdit.load',
                                args=[tablename, rowid],
                                vars=rvars),
                    _class='plugin_listandedit_duplicate',
                    cid='viewpane')

        formname = '{}/{}/dup'.format(tablename, rowid)

        src = db(db[tablename].id == rowid).select().first()
        form = SQLFORM(db[tablename],
                       separator='',
                       deletable=deletable,
                       showid=showid,
                       formstyle=formstyle)

        for v in db[tablename].fields:
            # on opening populate duplicate values
            form.vars[v] = src[v] if v != 'id' and v in src else None
            # FIXME: ajaxselect field values have to be added manually
            if db[tablename].fields[1] in list(rvars.keys()):  # on submit add ajaxselect values
                extras = [f for f in db[tablename].fields
                        if f not in list(form.vars.keys())]
                for e in extras:
                    form.vars[e] = rvars[e] if e in list(rvars.keys()) else ''
        del form.vars['id']
        # print 'form vars ========================================='
        # pprint(form.vars)

        if form.process(formname=formname, dbio=dbio).accepted:
            db.commit()
            #print 'accepted form ================================='
            the_url = URL('plugin_listandedit', 'itemlist.load',
                          args=[tablename], vars={'orderby': orderby,
                                                  'restrictor': restrictor,
                                                  'collation': collation,
                                                  'postprocess': postprocess})
            rjs = "web2py_component('{}', 'listpane');".format(the_url)
            if dbio:
                flash = 'New record successfully created.'
        elif form.errors:
            print('listandedit form errors:', [e for e in form.errors])
            print('listandedit form vars:', form.vars)
            flash = 'Sorry, there was an error processing '\
                            'the form. The new record has not been created.'
        else:
            pass

        return form, duplink, flash, rjs
开发者ID:monotasker,项目名称:plugin_listandedit,代码行数:70,代码来源:plugin_listandedit.py


注:本文中的gluon.SQLFORM.vars[v]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。