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

📄 courses.py

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

import mx.DateTime as mxdt

CrsNames = ["CrsNum", "CrsTitle", "CrsAuthor", "CrsDescription", "CrsPlaces", "CrsPrice"]
InsNames = ["InsName"]

conn = dbsource().conn
cursor = conn.cursor()
qCrss = CacheQuery("Course", CrsNames, (),
                     conn, ORDER=("CrsNum",), refresh=30)
qIns = CacheQuery("Instructor", InsNames, ("InsNum", ),
                     conn, refresh=30)

class Page(Web.Page):

    def Body(self):
        return """
        <h3>PythonTeach Courses</H3>
        <P>We specialise in one-day training courses covering
        Python-related topics. These courses run as public events,
        and we will also be quite happy to quote you for a
        series of one, two or three courses on-site. This is
        the most effective way to train five or more staff.</P>
        <P>Public courses are presented at hotel venues around
        the United States, and we can offer the same materials
        anywhere in the world with enough advance notice. If
        you would like a quotation for an on-site course, please
        <A HREF="mailto:OnSites@holdenweb.com">email us</A>
        outlining your requirements.</P>
        <P>All our instructors are experienced programmers,
        with plenty of Python experience as well as general
        expertise in problem solving.</P>
        <P>If you are planning a Python project there is no
        better way to improve productivity than by training
        your staff to get the most out of this innovative
        object-oriented scripting language.
        """

    def Title(self):
        return "PythonTeach: Course Information"

    def CourseNav(self):
        links = [
            ("/AllCourses/", "Current Courses"),
            ("/CourseCity/", "Classes by Location"),
            ("/CourseNum/", "Classes by Course")
            ]
        return "\n".join([self.NavLink(p) for p in links])

    def ListCourses(self, r, heading):
        color = 0
        result = ["""
        <h3>%s</h3>
        <P>
        <table cellpadding="2">
        <tr>
        <td>Date</td>
        <td>Class Title and Location</td>
        <td>Price</td>
        <td>&nbsp;</td>
        </tr>
        """ % heading]
        for c in r:
            color = 1-color
            city, locn, date, titl, cnum, plcs, price = c
            cursor.execute("SELECT COUNT(*) FROM Enrollment WHERE ClsNum=?", (cnum, ))
            enrl = cursor.fetchall()[0][0]
            if enrl >= plcs:
                ltxt = "WaitList Me"
                lhrf = "/CourseWaitList/%s/" % cnum
            else:
                ltxt = "Enroll Me"
                lhrf = "/CourseEnroll/%s/" % cnum
            result.append("""
            <tr bgcolor="%s">
            <td valign="top"><b>%s</b></td>
            <td valign="top"><b>%s</b><br><font size="-2">%s</font></td>
            <td valign="top"><b>$%d</b></td>
            <td valign="top"><a href="%s"><b>%s</b></a></td>
            </tr>""" % (
                ("#ccffff", "#33ffff")[color], date.strftime("%b %d"),
                titl, locn, price, lhrf, ltxt))
        result.append("""
        </table>
        </P>""")
        return "\n".join(result)

⌨️ 快捷键说明

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