瀏覽代碼

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

M. Ian Graham 17 年之前
父節點
當前提交
c486e2b643
共有 3 個文件被更改,包括 53 次插入17 次删除
  1. 7 0
      direct/src/http/LandingPage.py
  2. 28 17
      direct/src/http/LandingPageHTML.py
  3. 18 0
      direct/src/http/WebRequest.py

+ 7 - 0
direct/src/http/LandingPage.py

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

+ 28 - 17
direct/src/http/LandingPageHTML.py

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

+ 18 - 0
direct/src/http/WebRequest.py

@@ -43,6 +43,15 @@ class WebRequest(object):
         msg = "HTTP/1.0 200 OK\r\nContent-Type: text/xml\r\n\r\n%s" % body
         msg = "HTTP/1.0 200 OK\r\nContent-Type: text/xml\r\n\r\n%s" % body
         self.connection.SendThisResponse(msg)
         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):
     def timeout(self):
         resp = "<html><body>Error 504: Request timed out</body></html>\r\n"
         resp = "<html><body>Error 504: Request timed out</body></html>\r\n"
         self.respondHTTP("504 Gateway Timeout",resp)
         self.respondHTTP("504 Gateway Timeout",resp)
@@ -215,6 +224,7 @@ class WebRequestDispatcher(object):
                 self.landingPage = LandingPage()
                 self.landingPage = LandingPage()
                 self.registerGETHandler("/", self._main, returnsResponse = True, autoSkin = True)
                 self.registerGETHandler("/", self._main, returnsResponse = True, autoSkin = True)
                 self.registerGETHandler("/services", self._services, 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("Main", "/")
                 self.landingPage.addTab("Services", "/services")
                 self.landingPage.addTab("Services", "/services")
         else:
         else:
@@ -228,3 +238,11 @@ class WebRequestDispatcher(object):
 
 
     def _services(self):
     def _services(self):
         return self.landingPage.getServicesPage(self.uriToHandler)
         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)
+
+