⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forms.py

📁 python web programming 部分
💻 PY
字号:
class FormsMixin:

    def DropDown(self, tbl, valcol, descol, name="pulldown",
                default="Please make a selection",
                selected=None, ordercol=None, autosubmit=None):

        """Create a dropdown selector from two columns of a database table.

        Note that column aliasing is used to give fixed attribute names to
        the columns retrieved, so this algorithm works with two different
        database columns or the same one for both value and description."""

        td = dtuple.TupleDescriptor([("ValCol",), ("DesCol",)])
        if autosubmit:
            auto = """OnChange="submit(this.parent)"""
        else:
            auto = ""
        result = ["""<SELECT NAME="%s" %s ">""" % (name, auto)]
        result.append(self.Option("", default))
        stmt = "SELECT %s, %s FROM %s" % (valcol, descol, tbl)
        if ordercol:
            stmt += " ORDER BY %s" % ordercol
        # print stmt
        self.cursor.execute(stmt)
        rows = self.cursor.fetchall()
        for row in rows:
            row = dtuple.DatabaseTuple(td, row)
            result.append(self.Option(row.ValCol, row.DesCol))
        result.append("</SELECT>\n")
        return "\n".join(result)

    def Option(self, val, dsc):
        return """<OPTION VALUE="%s">%s""" % (val, dsc)


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -