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

📄 dept.py

📁 python web programming 部分
💻 PY
字号:
#
# $Workfile: Dept.py $ $Revision: 6 $
# $Date: 10/07/01 1:37p $ $Author: Sholden $
#
import Web
from Error import Error
from cachequery import CacheQuery
from dtuple import TupleDescriptor, DatabaseTuple
from dbsource import dbsource
import mx.DateTime

DptNames = ["DptCode", "DptName", "DptWelcome", "DptLinks", "DptLnksTxt"]
conn = dbsource().conn
cursor = conn.cursor()
qDept = CacheQuery("department", DptNames, ("DptCode", ),
                     conn,  refresh=30)
qLnks = CacheQuery("links", ("LnkURL", "LnkText"), ("DptCode", ),
                     conn, refresh=30)
TD = TupleDescriptor([[d] for d in DptNames])

class Page(Web.Page):
    """Abstract page implementing departmental look and feel."""

    def __init__(self, *args, **kw):
        Web.Page.__init__(self, *args, **kw)
        try:
            if len(self.path) == 0:
                raise ValueError
            else:
                self.DptCode = self.path[0]
            self.path = self.path[1:]
            self.dpt = qDept(self.DptCode)
            if not self.dpt:
                raise ValueError
            self.dpt = self.dpt[0]
        except ValueError:
            self.DptCode = "Missing"
            self.dpt = DatabaseTuple(TD, ("Missing", "Missing Department", "Welcome", "", ""))
        now = mx.DateTime.today()
        stmt = """SELECT DptCode, newsitem.NwsNum, NwsHead FROM newsitem, deptnews
                    WHERE DptCode=?
                    AND deptnews.NwsNum=newsitem.NwsNum
                    AND ? BETWEEN NewsItem.NwsStart AND NewsItem.NwsEnd"""
        cursor.execute(stmt, (self.dpt.DptCode, now))
        self.Nws = cursor.fetchall()
        self.lnk = qLnks((self.dpt.DptCode, ))
        stmt = """SELECT QodHook, QodQuestion, QodAlist, QodAnswer
                    FROM Qod WHERE ? BETWEEN QodDate AND QodDate+1
                    AND DptCode = ?
                    AND QodShow"""
        cursor.execute(stmt, (now, self.dpt.DptCode))
        self.qod = cursor.fetchall()
        if self.qod:
            self.qod = self.qod[0]
        # There *SHOULD* be at most one ... but we use the first to be safe!


    def Title(self):
        """Title is department name."""
        return self.dpt.DptName

    def DeptHeader(self):
        """Page starts with the department name."""
        if self.DptCode:
            text = self.dpt.DptName
        else:
            text = "No Department Name"
        return """<H2>%s</FONT></H2>""" % text

    def DeptNav(self):
        """Generate navigation bar for any department page."""
        result = []
        if self.DptCode:
            result.append("""<BR><A HREF="/DeptHome/%s/">Department Home</A><BR><BR>""" %
                     self.dpt.DptCode)
            if len(self.Nws):
                result.append("""<A HREF="/DeptNews/%s/">News</A><BR><BR>""" % self.dpt.DptCode)
            if self.dpt.DptLnksTxt:
                result.append("%s<BR><BR>" % self.dpt.DptLnksTxt)
            if len(self.lnk):
                result.append("""<A HREF="/DeptLinks/%s/">More Links</A><BR><BR>""" % self.dpt.DptCode)
            if len(self.qod):
                # Departmental question of the day
                result.append("""<B>Today's question:</B><BR>
                <A HREF="/DeptQod/%s/">%s ...</A><BR><BR>""" % (self.dpt.DptCode, self.qod[0]))
        return "\n".join(result)

⌨️ 快捷键说明

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