From 3b0682d19ff6e24d0fff174fab5ef74a44b874c7 Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Thu, 19 Nov 2009 22:43:21 +0000 Subject: [PATCH] head and body tags of landing page exposed as ElementTree.Elements --- direct/src/http/LandingPage.py | 69 ++++++++++++++++++++------- direct/src/http/LandingPageHTML.py | 76 ++++++++++++++++++++++++++++-- direct/src/http/WebRequest.py | 54 +++++++++------------ 3 files changed, 146 insertions(+), 53 deletions(-) diff --git a/direct/src/http/LandingPage.py b/direct/src/http/LandingPage.py index 2e793e5dd3..47092eb21d 100755 --- a/direct/src/http/LandingPage.py +++ b/direct/src/http/LandingPage.py @@ -13,9 +13,6 @@ class LandingPage: self.headerTemplate = LandingPageHTML.header self.footerTemplate = LandingPageHTML.footer - # allow modifications to the page head tag - self._headET = ET.Element('head') - self.menu = {} self.uriToTitle = {} @@ -51,19 +48,57 @@ class LandingPage: def getMenu(self, activeTab): return LandingPageHTML.getTabs(self.menu,activeTab) - def getHeader(self, activeTab = "Main"): - headContent = '' - for child in self._headET.getchildren(): - fileStr = StringIO() - ET.ElementTree(child).write(fileStr) - headContent += fileStr.getvalue() - s = self.headerTemplate % {'titlestring' : LandingPageHTML.title, - 'menustring' : self.getMenu(activeTab), - 'headContent' : headContent,} - return s + def getMenuTags(self, activeTab): + return LandingPageHTML.getTabTags(self.menu, activeTab) - def getHead(self): - return self._headET + def getHeader(self, activeTab = "Main", headTag=None, bodyTag=None): + if headTag is None: + headTag = ET.Element('head') + if bodyTag is None: + bodyTag = ET.Element('body') + + # make sure each component has elements to make formatting consistent + headTag.append(ET.Comment('')) + bodyTag.append(ET.Comment('')) + + fileStr = StringIO() + ET.ElementTree(headTag).write(fileStr) + headTagStr = fileStr.getvalue() + # remove the tag closer + # + headTagStr = headTagStr[:headTagStr.rindex('<')] + + # fill in the prefab body tag content + titleStr = LandingPageHTML.title + landing = ET.Element('body') + LandingPageHTML.addBodyHeaderAndContent(landing, titleStr, self.getMenuTags(activeTab)) + + fileStr = StringIO() + ET.ElementTree(landing).write(fileStr) + landingStr = fileStr.getvalue() + # remove + landingStr = landingStr[landingStr.index('>')+1:] + # remove tag closers + for i in xrange(3): + # + # contents + # + landingStr = landingStr[:landingStr.rindex('<')] + + fileStr = StringIO() + ET.ElementTree(bodyTag).write(fileStr) + bodyTagStr = fileStr.getvalue() + # extract + bodyStr = bodyTagStr[bodyTagStr.index('>')+1:] + bodyTagStr = bodyTagStr[:bodyTagStr.index('>')+1] + + bodyStr = bodyTagStr + '\n' + landingStr + '\n' + bodyStr + + s = self.headerTemplate % {'titlestring': titleStr, + 'headTag' : headTagStr, + 'bodyTag': bodyStr, + } + return s def getFooter(self): return self.footerTemplate % {'contact' : LandingPageHTML.contactInfo} @@ -130,9 +165,9 @@ class LandingPage: def getFavIcon(self): return self.favicon - def skin(self, body, uri): + def skin(self, body, uri, headTag=None, bodyTag=None): title = self.uriToTitle.get(uri,"Services") - return self.getHeader(title) + body + self.getFooter() + return self.getHeader(title, headTag, bodyTag) + body + self.getFooter() def addQuickStat(self,item,value,position): if item in self.quickStats[1]: diff --git a/direct/src/http/LandingPageHTML.py b/direct/src/http/LandingPageHTML.py index 9b8ca4f860..d95a08ab68 100755 --- a/direct/src/http/LandingPageHTML.py +++ b/direct/src/http/LandingPageHTML.py @@ -1,5 +1,7 @@ # -- Text content for the landing page. You should change these for yours! -- +from direct.showbase import ElementTree as ET + title = "Landing Page" defaultTitle = title @@ -258,14 +260,17 @@ stylesheet = ''' header = ''' - +%(headTag)s %(titlestring)s -%(headContent)s - +%(bodyTag)s +''' +# this portion of the body is now added dynamically in order to support changes to the body tag +# attributes +'''