def publish(self, page): pageType = page.getOption('weblogPageType') weblog = self.manager.getWeblog(page) if (pageType == 'day'): self.log.debug("Getting template for day page.") template = self.templateConfig.getTemplate( page.getOption('weblog-day-template', 'template.html')) self.log.debug("Found weblog day template name of: " + str(template)) elif (pageType == 'index'): self.log.debug("Getting template for index page.") template = self.templateConfig.getTemplate( page.getOption('weblog-index-template', 'template.html')) self.log.debug("Found weblog index template name of: " + str(template)) elif (pageType == 'syndication'): self.log.debug("Getting templates for syndication pages.") weblogSyndicationTemplates = page.getListOption( 'weblog-syndication-template') if (weblogSyndicationTemplates is None or len(weblogSyndicationTemplates) == 0): msg = "Syndication attempted, but no templates are defined!" self.log.error(msg) raise SitePublisher.PublisherException(msg) msg = "Syndication attempted, but no template defined!" for templateName in weblogSyndicationTemplates: context = simpleTALES.Context(allowPythonPath=1) template = self.templateConfig.getTemplate(templateName) # Get the page context for this content map = self.getPageContext(page, template) context.addGlobal('page', map) macros = page.getMacros() # Determine the destination for this page relativeDestPath = map['destinationPath'] self.pagePublisher.expandTemplate(template, context, relativeDestPath, macros) weblog.notePagePublished(page.getOption('pageName')) elif (pageType == 'month'): self.log.debug("Getting template for monthly archive page.") template = self.templateConfig.getTemplate( page.getOption('weblog-month-template', 'template.html')) if (pageType != 'syndication'): self.log.debug("Building non-syndication page.") context = simpleTALES.Context(allowPythonPath=1) # Get the page context for this content self.log.debug("Getting page context.") map = self.getPageContext(page, template) self.log.debug("Adding 'page' object to SimpleTALES.Context") context.addGlobal('page', map) macros = page.getMacros() # Determine the destination for this page relativeDestPath = map['destinationPath'] self.log.debug("Expanding template.") self.pagePublisher.expandTemplate(template, context, relativeDestPath, macros) weblog.notePagePublished(page.getOption('pageName'))
def setUp(self): self.context = simpleTALES.Context() self.recorder = CallRecorder() self.context.addGlobal('top', 'Hello from the top') self.context.addGlobal('alt', 'Wobble the way') self.context.addGlobal('holder', {'recorder': self.recorder.simpleFunction})
def getpage(self, fields): """fields - dict of HTTP pears. Returns formatted page string, according to fields['job']""" job = fields.get('job') or 'view' # Creat the context that is used by the template context = simpleTALES.Context(allowPythonPath=1) context.addGlobal( "cfg", { 'version': Config.get('version'), 'link': Config.get('link'), 'logo': Config.get('logo'), 'css': Config.get('css') }) # Add objects into the template context context = getattr(self, "_context_" + job)(context, fields) # Open the template file templateFile = open( os.path.join(Config.get('zpt_path'), "".join([job, ".zpt"])), 'r') # Compile a template template = simpleTAL.compileHTMLTemplate(templateFile, self.encoding) # Close the template file templateFile.close() # Create fake file that lets print file as a string fastFile = simpleTALUtils.FastStringOutput() # Expand the template as HTML using this context template.expand(context, fastFile, self.encoding) return fastFile.getvalue() #yo people! it's ZPT content"
def initializeFreeMarkerContext(self, config,__flowObj,__policyList): # Create the context that is used by the template context = simpleTALES.Context() time_stamp = calendar.timegm(time.gmtime()) context.addGlobal ("basePath", __flowObj.__getattribute__("basePath")) context.addGlobal ("proxyRevision", "13") context.__setattr__("proxyName",__flowObj.__getattribute__("title")) context.addGlobal("proxyName",__flowObj.__getattribute__("title")) print("Value-->",config['DEFAULT']['CREATED_BY']) context.addGlobal("createdBy",config['DEFAULT']['CREATED_BY']) context.addGlobal("encodingStyle",config['DEFAULT']['ENCODING'] ) context.addGlobal("standAlone",config['DEFAULT']['STANDALONE'] ) context.addGlobal("majorVersion",config['DEFAULT']['CONFIGURATION_VERSION_MAJOR'] ) context.addGlobal("minorVersion",config['DEFAULT']['CONFIGURATION_VERSION_MINOR'] ) context.addGlobal("Description",config['DEFAULT']['DESCRIPTION'] ) context.addGlobal("CreatedAt",time_stamp ) context.addGlobal("LastModifiedAt",time_stamp ) proxyServerName = __flowObj.__getattribute__("title")+"-server" context.addGlobal("proxyServerName", proxyServerName) # Get List of conditional Flows _flowString = self.prepareFlowDetails(__flowObj) context.addGlobal("details",_flowString) # Get List of Policies and Hash self.policies = __policyList context.addGlobal("policies",self.policies) return context
def setUp(self): self.context = simpleTALES.Context() self.context.addGlobal('test', 'testing') self.context.addGlobal('link', 'www.owlfish.com') self.context.addGlobal('bob', 'bob') self.context.addGlobal('disabled', 'disabled') self.context.addGlobal('notdisabled', 'notdisabled')
def _render_pt(self, request, template): """Render a page template. We pass in request so that we can put it in state.py's namespace. """ # Start building context and hand off to local hook. # ================================================== context = simpleTALES.Context() context.addGlobal("frame", self.frame()) state_path = os.path.join(self.__, 'state.py') if os.path.isfile(state_path): execfile(state_path, { 'request':request , 'context':context }) # Expand and return the template. # =============================== out = simpleTALUtils.FastStringOutput() template.expand( context , out , docType = self.DOC_TYPE # this doesn't appear to work with PyXML , suppressXMLDeclaration = True ) return out.getvalue()
def setUp(self): self.context = simpleTALES.Context(allowPythonPath=1) self.context.addGlobal('test', '< testing > experimenting & twice as useful') self.context.addGlobal('one', [1]) self.context.addGlobal('two', ["one", "two"]) self.context.addGlobal('three', [1, "Two", 3])
def setUp(self): self.context = simpleTALES.Context() self.context.addGlobal('test', 'testing') self.context.addGlobal('link', 'www.owlfish.com') self.context.addGlobal('needsQuoting', """Does "this" work?""") self.context.addGlobal('number', '5') self.context.addGlobal('uniQuote', 'Does "this" work?')
def setUp (self): self.context = simpleTALES.Context() self.context.addGlobal ('colours', {'blue': 'The sea is blue', 'red': 'The ball is red', 'green': 'The grass is green'}) self.context.addGlobal ('aList', ['blue', 'green']) self.context.addGlobal ('goodColour', 'goodColourPath') self.context.addGlobal ('goodColourPath', 'Black is good') self.context.addGlobal ('noSuchColour', 'pink')
def setUp (self): self.context = simpleTALES.Context() self.context.addGlobal ('test', 'Testing this and that') self.context.addGlobal ('HighBC', 'This cost nothing, yep �') self.context.addGlobal ('one', [1]) self.context.addGlobal ('two', ["one", "two"]) self.context.addGlobal ('three', [1,"Two",3])
def expand(self, **info): context = simpleTALES.Context(allowPythonPath=1) for k, v in info.iteritems(): context.addGlobal(k, v) s = StringIO.StringIO() self.template.expandInline(context, s) return s.getvalue()
def setUp(self): self.context = simpleTALES.Context() self.context.addGlobal('test', 'testing') self.context.addGlobal('link', 'www.owlfish.com') self.context.addGlobal('needsQuoting', """Does "this" work?""") self.context.addGlobal('number', 5) self.context.addGlobal('uniQuote', 'Does "this" work?') self.context.addGlobal('anotherdefault', {'inhere': simpleTALES.DEFAULTVALUE})
def render(): ctxt = simpleTALES.Context(allowPythonPath=1) ctxt.addGlobal('base', base) ctxt.addGlobal('title', 'Just a test') ctxt.addGlobal('user', 'joe') ctxt.addGlobal('items', ['Number %d' % num for num in range(1, 15)]) buf = StringIO() template.expand(ctxt, buf) return buf.getvalue()
def render(): ctxt = simpleTALES.Context(allowPythonPath=1) ctxt.addGlobal("base", base) ctxt.addGlobal("title", "Just a test") ctxt.addGlobal("user", "joe") ctxt.addGlobal("items", ["Number %d" % num for num in range(1, 15)]) buf = StringIO() template.expand(ctxt, buf) return buf.getvalue()
def setUp(self): self.context = simpleTALES.Context() self.context.addGlobal('top', 'Hello from the top') self.context.addGlobal('alt', 'Wobble the way') self.context.addGlobal('holder', { 'helloFunc': simpleFunction, 'falseFunc': simpleFalseFunc }) self.context.addGlobal('version', 3.1) self.context.addGlobal('uniString', "Hello")
def setUp (self): self.context = simpleTALES.Context() self.context.addGlobal ('test', 'Testing this and that') self.context.addGlobal ('HighBC', 'This cost nothing, yep �') self.context.addGlobal ('one', [1]) self.context.addGlobal ('two', ["one", "two"]) self.context.addGlobal ('three', [1,"Two",3]) self.context.addGlobal ('badascii', 'This costs nothing, yep �) if (not oldPython): self.context.addGlobal ('inheritance', UnicodeSubclass('\u2018subclass\u2019'))
def setUp(self): self.context = simpleTALES.Context() self.context.addGlobal('test', 'testing') self.context.addGlobal('zeroCont', IterContainer(0)) self.context.addGlobal('oneCont', IterContainer(1)) self.context.addGlobal('twoCont', IterContainer(2)) self.context.addGlobal('zeroAct', ActualIter(0)) self.context.addGlobal('oneAct', ActualIter(1)) self.context.addGlobal('twoAct', ActualIter(2))
def do_error(self, errorstr): from simpletal import simpleTAL, simpleTALES import sys context = simpleTALES.Context( ) templateFile = open ("%s/WebRoot/error.html"%(self.config['general.webroot']) , 'r') template = simpleTAL.compileHTMLTemplate (templateFile) templateFile.close() context.addGlobal ("error", errorstr) template.expand (context, sys.stdout) sys.exit()
def setUp(self): self.context = simpleTALES.Context() entry = """<insertedData>Some structure: <b tal:content="weblog/subject"></b></insertedData>""" weblog = {'subject': 'Test subject', 'entry': entry} self.context.addGlobal('test', 'testing') self.context.addGlobal('one', [1]) self.context.addGlobal('two', ["one", "two"]) self.context.addGlobal('three', [1, "Two", 3]) self.context.addGlobal('weblog', weblog)
def render(self, *args, **kwargs): from simpletal import simpleTALES for dictarg in args: kwargs.update(dictarg) context = simpleTALES.Context() for k, v in self.defaults.items(): context.addGlobal(k, v) for k, v in kwargs.items(): context.addGlobal(k, v) output = StringIO() self.tpl.expand(context, output) return output.getvalue()
def expand_template_with_jurisdictions(templatefilename, juridict): # Create the context that is used by the template context = simpleTALES.Context() context.addGlobal("jurisdictions", juridict) templateFile = open('template.html') template = simpleTAL.compileXMLTemplate(templateFile) templateFile.close() output_buffer = StringIO.StringIO() template.expand(context, output_buffer, 'utf-8') return output_buffer.getvalue()
def render_form(self, rows=1): context = simpleTALES.Context(allowPythonPath=True) context.addGlobal("title", "JYY Survival Kit Order Form") context.addGlobal("root", '/') context.addGlobal("rows", rows) context.addGlobal("release_dates", ReleaseDate.all().order('date')) context.addGlobal("exchange_types", ExchangeType.all().order('type')) context.addGlobal("instructions", Instruction.all().order('topic')) return self.render_html("tutor.pt", self.macros_from("master.pt", context))
def setUp (self): self.context = simpleTALES.Context() self.context.addGlobal ('test', 'testing') self.context.addGlobal ('one', [1]) self.context.addGlobal ('two', ["one", "two"]) self.context.addGlobal ('three', [1,"Two",3]) self.context.addGlobal ('bigList', list(range(1,100))) self.context.addGlobal ('fourList', ["zero", "one", "two", "three"]) self.context.addGlobal ('nested', [{'title': 'Image 1', 'catList': [1,2,3]} ,{'title': 'Image 2', 'catList': [5,2,3]} ,{'title': 'Image 3', 'catList': [8,9,1]} ])
def render_form(self, collection=None): context = simpleTALES.Context(allowPythonPath=True) context.addGlobal("title", "Manage Survival KIT Orders") context.addGlobal("root", '/manage/') context.addGlobal("orders", Order.uncollected()) context.addGlobal("download", collection) context.addGlobal("collections", Collection.all().order('created')) context.addGlobal("release_dates", ReleaseDate.all().order('date')) context.addGlobal("exchange_types", ExchangeType.all().order('type')) context.addGlobal("instructions", Instruction.all().order('topic')) return self.render_html("secretary.pt", self.macros_from("master.pt", context))
def publish (self, page): template = self.templateConfig.getTemplate (page.getOption ('template', 'template.html')) context = simpleTALES.Context(allowPythonPath=1) # Get the page context for this content map = self.getPageContext (page, template) context.addGlobal ('page', map) # Determine the destination for this page relativeDestPath = map ['destinationPath'] macros = page.getMacros() self.pagePublisher.expandTemplate (template, context, relativeDestPath, macros)
def render(self, *args, **kwargs): from simpletal import simpleTALES from StringIO import StringIO for dictarg in args: kwargs.update(dictarg) # TODO: maybe reuse a context instead of always creating one context = simpleTALES.Context() for k, v in self.defaults.items(): context.addGlobal(k, v) for k, v in kwargs.items(): context.addGlobal(k, v) output = StringIO() self.tpl.expand(context, output) return output.getvalue()
def expandTemplate (self, templateName, outputName, additionalContext = None, sorter=None): context = simpleTALES.Context() context.addGlobal (self.name, self.contextFactory.getContextMap (sorter)) if (additionalContext is not None): context.addGlobal (additionalContext[0], additionalContext[1]) if (self.template is None): templateFile = open (templateName, 'r') self.template = simpleTAL.compileHTMLTemplate (templateFile) templateFile.close() outputFile = open (outputName, 'w') self.template.expand (context, outputFile) outputFile.close()
def setUp(self): self.context = simpleTALES.Context() self.context.addGlobal('top', 'Hello from the top') self.context.addGlobal('alt', 'Wobble the way') self.context.addGlobal('theMap', { 'top': 'Hello', 'onelevel': { 'top': 'Bye' } }) self.context.addGlobal('funcMap', { 'simple': simpleFunction, 'nested': nestedFunction }) self.context.addGlobal('topFunc', simpleFunction)
def write(self, wfile): context = simpleTALES.Context(allowPythonPath=self.allowpythonpath) context.addGlobal("selector", self.getselector()) context.addGlobal("handler", self) context.addGlobal("entry", self.getentry()) context.addGlobal("talbasename", self.talbasename) context.addGlobal("allowpythonpath", self.allowpythonpath) context.addGlobal("protocol", self.protocol) context.addGlobal("root", TALLoader(self.vfs, "/")) context.addGlobal("rroot", RecursiveTALLoader(self.vfs, "/")) dirname = os.path.dirname(self.getselector()) context.addGlobal("dir", TALLoader(self.vfs, dirname)) context.addGlobal("rdir", RecursiveTALLoader(self.vfs, dirname)) # SimpleTAL doesn't support reading from binary files with self.vfs.open(self.getselector(), "r", errors="replace") as rfile: template = simpleTAL.compileHTMLTemplate(rfile) template.expand(context, wfile)
def write(self, wfile): rfile = self.vfs.open(self.getselector()) context = simpleTALES.Context(allowPythonPath=self.allowpythonpath) context.addGlobal("selector", self.getselector()) context.addGlobal('handler', self) context.addGlobal('entry', self.getentry()) context.addGlobal('talbasename', self.talbasename) context.addGlobal('allowpythonpath', self.allowpythonpath) context.addGlobal('protocol', self.protocol) context.addGlobal('root', TALLoader(self.vfs, '/')) context.addGlobal('rroot', RecursiveTALLoader(self.vfs, '/')) dirname = os.path.dirname(self.getselector()) context.addGlobal('dir', TALLoader(self.vfs, dirname)) context.addGlobal('rdir', RecursiveTALLoader(self.vfs, dirname)) template = simpleTAL.compileHTMLTemplate(rfile) rfile.close() template.expand(context, wfile)