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

📄 frmpage.py

📁 python web programming 部分
💻 PY
字号:
from dtuple import TupleDescriptor, DatabaseTuple
import pyforms
import pySQL
import stdpage

#
# Form for Standard Page Update
#
def FormStdPage(form, req, CR):
    result = [ """
    <h4>Edit or Show Any Standard Page</h4>
    <table cellpadding="2">

    """]

    try:
        KeyVal = form["Key"].value
    except KeyError:
        KeyVal = None
    if KeyVal == None:    # Bare call to page gets list of pages
        Stmt = "SELECT Name, LinkText, Num from StdPage WHERE PageSet = 'Std' ORDER BY Num"
        CR.execute(Stmt)
        records = CR.fetchall()
        dt = TupleDescriptor((['Name'],['LinkText'],['Num']))
        for r in records:
            RS = DatabaseTuple(dt, r)
            result.append('<tr><td>%s</td><td>%s</td><td>%d</td><td><a href="?page=FormStdPage&Key=%s">Edit</a></td><td><a href="?page=StdPage&Name=%s">Show</a></td></tr>\r\n' \
                            % (RS.LinkText, RS.Name, RS.Num, RS.Name, RS.Name))
        result.append("""
        </table>
        <BR><a href="?page=FormStdPage&Key=*CREATE*">***CREATE NEW RECORD***</a><BR>\r\n""")
    else:
        if KeyVal == "*CREATE*":
            RS = None
        else:
            Stmt = "SELECT Name, PageSet, Num, LinkText, Template, Content FROM StdPage WHERE name=?"
            CR.execute(Stmt, (KeyVal, ))
            record = CR.fetchone()
            dt = TupleDescriptor((['Name'],['PageSet'],['Num'],['LinkText'],['Template'],['Content']))
            RS = DatabaseTuple(dt, record)
        Flist = (
            # Note options MUST now be a string, not None
            ["Comment1", "Web Page Details", "REM", "+2", ""],
            ["Name", "Page Name", "KSA", 20, "R"],
            ["PageSet", "Page Set Name", "T", 20, "R"],
            ["Num", "Page Number", "N", 5, ""],
            ["LinkText", "Link Text", "T", 30, ""],
            ["Template", "Template Name", "T", 30, ""],
            ["Content", "Page Content", "M", (10, 60), "R"]
        )
        result.append(pyforms.FormBuild(Flist, "StdPage", "name", str(KeyVal), RS))
    return "".join(result)

#
# New Standard Page
#
def NewStdPage(form, req, CR, db):
    try:
        Flist = eval(form["#Flist#"].value)
        KeyVal = form["#KeyVals#"].value
    except KeyError:
        return "<H4>Could not access #Flist# or #KeyVals#</H4>"
    if KeyVal != "*CREATE*":
        return """<H4>ERROR: New Called with Key Value!</h4>"""
    else:
        Stmt = pySQL.SQLInsert(form, "StdPage", Flist, "" ,"", "")
    result = ["<BR>SQL IS: %s" % (Stmt, )]
    try:
        CR.execute(Stmt)
        db.commit()
    except:
        db.rollback()
        return stdpage.PageBody("Database Operation Error",
                        stdpage.LHNav(KeyVal, CR),
                        "Sorry, unable to create this page using: "+ Stmt)
    result.append("""
    <h2>StdPage %s Created</h2>
    <BR>
    <A HREF="?page=%s">Back to Page List</A>
    """ % (form["Name"].value, "FormStdPage"))
    return "".join(result)

#
# Update Standard Page
#
def UpdateStdPage(form, req, CR, db):
    Operation = str(form["Submit"].value)
    Flist = eval(str(form["#Flist#"].value))
    KeyVal = str(form["#KeyVals#"].value)
    if Operation == "Update":
        Stmt = pySQL.SQLUpdate(form, "StdPage", (("Name","S"),), (KeyVal,), Flist, "")
        which = "StdPage&Name=" + KeyVal
        pp = "Updated Page"
    elif Operation == "Delete":
        Stmt = pySQL.SQLDelete("StdPage", (("Name","S"),), (KeyVal,))
        which = "default"
        pp = "Home Page"
    try:
        CR.execute(Stmt)
        db.commit()
    except:
        db.rollback()
        return stdpage.PageBody("Database Operation Error",
                        stdpage.LHNav(KeyVal, CR),
                        "Sorry, unable to update this page's details")
    return stdpage.PageBody("%s Completed" % (Operation, ),
                        stdpage.LHNav(KeyVal, CR),
                        """
    <h2>Page %s&nbsp;%sd</h2>
    <!-- <BR>SQL IS: %s<BR> -->
    <BR>
    <A HREF="?page=%s">Show %s Page</A>
    """ % (KeyVal, Operation, Stmt, which, pp),
                        None)


⌨️ 快捷键说明

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