Split landing page CSS out into a separate URI for browser caching and prettified some HTML

This commit is contained in:
M. Ian Graham 2008-04-07 22:57:44 +00:00
parent e37eafaac5
commit c486e2b643
3 changed files with 53 additions and 17 deletions

View File

@ -45,6 +45,10 @@ class LandingPage:
uriList.remove("/services")
autoList.append("/services")
if "/default.css" in uriList:
uriList.remove("/default.css")
autoList.append("/default.css")
output += LandingPageHTML.getURITable(title="Application",uriList=uriList,uriToHandler=uriToHandler)
output += LandingPageHTML.getURITable(title="Admin",uriList=autoList,uriToHandler=uriToHandler)
@ -78,6 +82,9 @@ class LandingPage:
def getMainPage(self):
return LandingPageHTML.mainPageBody % {"description" : self.getDescription(),
"quickstats" : self.getQuickStatsTable()}
def getStyleSheet(self):
return LandingPageHTML.stylesheet
def skin(self, body, uri):
title = self.uriToTitle.get(uri,"Services")

View File

@ -9,19 +9,14 @@ defaultDesc = description
contactInfo = "M. Ian Graham - ian.graham@dig.com - 818-623-3219"
# -- Begin fancy layout stuff, change at your own risk --
header = '''
<html><head>
<title>%(titlestring)s</title>
<style>
stylesheet = '''
body
{
margin: 0;
padding: 0;
font-size: 90%%;
font-size: 90%;
font-family: Verdana, sans-serif;
background-color: #fff;
color: #333;
@ -36,7 +31,7 @@ header = '''
h2
{
font-size: 140%%;
font-size: 140%;
color: #666;
background-color: #fff;
width: 22em;
@ -236,7 +231,7 @@ header = '''
display: block;
padding: 0px;
margin: 0px;
width: 100%%;
width: 100%;
text-decoration: none;
color: #333;
}
@ -258,30 +253,46 @@ header = '''
font-weight: bold;
border-bottom: 1px solid #cccccc;
border-top: 1px solid #DFDFDF;
}
</style>
}
\r\n'''
header = '''
<html>
<head>
<title>%(titlestring)s</title>
<link rel="stylesheet" type="text/css" href="/default.css">
</head>
<body>
<!-- HEADER -->
<div id="header">
<h2>%(titlestring)s</h2>
<div id="navcontainer">
<ul id="navlist">
%(menustring)s
</ul>
%(menustring)s</ul>
</div>
</div>
<!-- CONTENT -->
<div id="contents">
<center>
'''
mainPageBody = '''
<P>%(description)s</P>
<P>%(quickstats)s</P>
'''
footer = '''
</center>
</div>
<!-- FOOTER -->
<div id="footer">
Contact: %(contact)s
</div>
@ -297,7 +308,7 @@ def getRowClassString(rowNum):
return " class=\"odd\""
def getURITable(title,uriList,uriToHandler):
output = "<P><table>\n<caption>%s</caption><thead><tr><th scope=col>URI</th><th scope=col>Handler</th></tr></thead>\n\n" % title
output = "\n<P>\n<table>\n<caption>%s</caption><thead><tr><th scope=col>URI</th><th scope=col>Handler</th></tr></thead>\n" % title
output += "<tbody>\n"
rowNum = 0
@ -311,7 +322,7 @@ def getURITable(title,uriList,uriToHandler):
handlerFunc)
rowNum += 1
output += "</tbody></table></P>\n"
output += "</tbody>\n</table>\n</P>\n"
return output
@ -352,7 +363,7 @@ def getTabs(menu,activeTab):
return s
def getQuickStatsTable(quickStats):
output = "<P><table>\n<caption>Quick Stats</caption><thead><tr><th scope=col>Item</th><th scope=col>Value</th></tr></thead>\n\n"
output = "\n<table>\n<caption>Quick Stats</caption>\n<thead><tr><th scope=col>Item</th><th scope=col>Value</th></tr></thead>\n"
output += "<tbody>\n"
rowNum = 0
@ -363,6 +374,6 @@ def getQuickStatsTable(quickStats):
quickStats[1][item])
rowNum += 1
output += "</tbody></table></P>\n"
output += "</tbody>\n</table>\n"
return output

View File

@ -43,6 +43,15 @@ class WebRequest(object):
msg = "HTTP/1.0 200 OK\r\nContent-Type: text/xml\r\n\r\n%s" % body
self.connection.SendThisResponse(msg)
def respondCustom(self,contentType,body):
msg = "HTTP/1.0 200 OK\r\nContent-Type: %s\n" % contentType
if contentType in ["text/css",]:
msg += "Cache-Control: max-age=313977290\nExpires: Tue, 02 May 2017 04:08:44 GMT\n"
msg += "\r\n\r\n%s" % (body)
self.connection.SendThisResponse(msg)
def timeout(self):
resp = "<html><body>Error 504: Request timed out</body></html>\r\n"
self.respondHTTP("504 Gateway Timeout",resp)
@ -215,6 +224,7 @@ class WebRequestDispatcher(object):
self.landingPage = LandingPage()
self.registerGETHandler("/", self._main, returnsResponse = True, autoSkin = True)
self.registerGETHandler("/services", self._services, returnsResponse = True, autoSkin = True)
self.registerGETHandler("/default.css", self._stylesheet)
self.landingPage.addTab("Main", "/")
self.landingPage.addTab("Services", "/services")
else:
@ -228,3 +238,11 @@ class WebRequestDispatcher(object):
def _services(self):
return self.landingPage.getServicesPage(self.uriToHandler)
def _stylesheet(self,**kw):
replyTo = kw.get("replyTo",None)
assert replyTo is not None
body = self.landingPage.getStyleSheet()
replyTo.respondCustom("text/css",body)