def render( self, request, template, language=None, properties=None, storable=NOTHING, templateType=None, **options ): """Renders a given page `template`, merging the giving `properties` in the template environment, and optionally serializing the given `storable` so that it becomes available as JSON""" properties = properties or {} template = template.split("#")[0].split("?")[0] user = self.getUser(request) language = language or guessLanguage(request) if not (storable is NOTHING): options["target"] = "web" if not storable: return request.notFound() else: storable = None path = request.path() path = path[len(self.DEFAULTS["base"]):] if path.startswith(language): path = path[len(language):] context = dict( path = path, title = template, language = language, isConnected = user and "true" or "false", user = asPrimitive(user, target="template"), object = asPrimitive(storable, **options), cachebuster = time.time(), currentUrl = request.path() ) context = self.merge(context, properties) if self.app().config("devmode") or template not in self._templates: tmpl = self.loadTemplate(template, type=templateType) self._templates[template] = tmpl else: tmpl = self._templates[template] page = self._applyTemplate(tmpl, context, language) response = request.respond(page) return response
# ----------------------------------------------------------------------------- # Creation : 17-Dec-2012 # Last mod : 21-Apr-2017 # ----------------------------------------------------------------------------- import os, time, sys, datetime, glob from retro import Dispatcher, Application, Component, on, expose, run, asJSON, asPrimitive, escapeHTML, STANDALONE, WSGI, NOTHING from retro.contrib.localfiles import LibraryServer from retro.contrib.i18n import Translations, localize, guessLanguage, DEFAULT_LANGUAGE, setLocales from retro.contrib.hash import crypt_decrypt from retro.contrib.cache import FileCache, SignatureCache, NoCache, MemoryCache try: import templating templating.FORMATTERS["json"] = lambda v,o,t:asJSON(v) templating.FORMATTERS["primitive"] = lambda v,o,t:asPrimitive(v) templating.FORMATTERS["escapeHTML"] = lambda v,o,t:escapeHTML(v) except ImportError as e: pass templating = None try: import paml.engine as paml_engine except ImportError as e: paml_engine = None try: import wwwclient except ImportError as e: pass