def params(self): campaign = self.request.ctx.campaign site = self.request.ctx.site if not "cart" in self.session: self.session["cart"] = Cart(site) cart = self.session["cart"] events = Appointment.find_public(self.enterprise_id) return { "site": site, #'base' : '%s/%s/' % (self.request.host_url.replace('http', 'https') if util.is_production() else self.request.host_url , site.namespace), "base": "%s/%s/" % (self.request.host_url, site.namespace), "user": self.request.ctx.user, "product": None, "products_related": None, "category": None, "cart": cart, "events": events, "seo_title": site.seo_title, "seo_keywords": site.seo_keywords, "seo_description": site.seo_description, "campaign": campaign, "categories": SmartCatalog.category_list(campaign), "customer": load_customer(self.request, True), # this way customer is always there, just may be empty "matchdict": self.request.matchdict, "back_link": self.session.get("back_link"), "specials": self.specials_product_list(self.request.GET.get("specials_category_id"), 0, 4), "recent_products": self.session["recent_products"] if "recent_products" in self.session else {}, }
def dynamic_url_lookup(request): """ KB: [2012-09-12]: This will render dynamic content. http://stackoverflow.com/questions/6321625/pyramid-is-it-possible-to-render-my-mako-template-as-a-string-within-my-view-c /fud/a/b --> /${site.namespace}/fud.mako request.GET['param0'] = 'a' request.GET['param1'] = 'b' /derf-fud/a/b --> /${site.namespace}/derf/fud.mako <-- note the dash in the first part request.GET['param0'] = 'a' request.GET['param1'] = 'b' / ("") --> /${site.namespace}/index.mako """ try: parts = request.path.split('/') mako_path_parts = parts[1].split('-') filepath = None if len(mako_path_parts) == 1: # this is single path rooted in the namespace filepath = '/%s' % (mako_path_parts[0] if mako_path_parts[0] != '' else 'index') elif len(mako_path_parts) > 1: # this is a file in a subdir of the namespace filepath = "/".join(mako_path_parts) matchdict = {} if len(parts) > 2: for i, param in enumerate(parts[2:]): matchdict['param%s' % i] = param path = "/%s/%s.mako" % (request.ctx.site.namespace, filepath) return Response(render(path, {'site' : request.ctx.site, 'user' : request.ctx.user, 'campaign' : request.ctx.campaign, 'customer' : load_customer(request), 'matchdict' : matchdict}, request)) except TopLevelLookupException as exc: log.error(exc) return HTTPNotFound() except Exception as exc: # KB: [2013-03-01]: This usually happens when googlebot calls /login and it routes to a login.mako page that tries to render # without its required context. Catch the barf and just route back to root. return HTTPFound('/')