def load_template_source(template_name, template_dirs=None, template_loader=default_template_loader): """If an Experiment exists for this template use template_loader to load it.""" request = get_current_request() test_template_name = request.ab.run(template_name) global template_source_loaders if template_source_loaders is None: log.debug('Populating template loaders') loaders = [] for path in settings.TEMPLATE_LOADERS: i = path.rfind('.') module, attr = path[:i], path[i+1:] try: log.debug('Loading from: %s' % module) mod = import_module(module) except ImportError, e: raise ImproperlyConfigured, 'Error importing template source loader %s: "%s"' % (module, e) try: log.debug('Looking for loader: %s' % attr) func = getattr(mod, attr) except AttributeError: raise ImproperlyConfigured, 'Module "%s" does not define a "%s" callable template source loader' % (module, attr) if not func.is_usable: import warnings warnings.warn("Your TEMPLATE_LOADERS setting includes %r, but your Python installation doesn't support that type of template loading. Consider removing that line from TEMPLATE_LOADERS." % path) else: log.debug('Appending loader: %s' % path) loaders.append(func) template_source_loaders = tuple(loaders)
def load_template_source(template_name, template_dirs=None, template_loader=default_template_loader): """If an Experiment exists for this template use template_loader to load it.""" request = get_current_request() test_template_name = request.ab.run(template_name) return template_loader(test_template_name, template_dirs=template_dirs)
def load_template_source(self, template_name, template_dirs=None): request = get_current_request() test_template_name = template_name if request and not request.user_agent.is_bot: if 'exp' in request.GET: # If exp is provided, the experiment is not activated but the specific temnpalte is loaded test_template_name = request.ab.get_by_idx(template_name, int(request.GET['exp'])) else: test_template_name = request.ab.run(template_name) return super(ABLoader, self).load_template_source(test_template_name, template_dirs=template_dirs)
def load_template_source(template_name, template_dirs=None, template_loader=default_template_loader): """If an Experiment exists for this template use template_loader to load it.""" # CW AMEND Nov 2011 - this way relies on a 'request' object but sometimes # like running cron jobs, there is no request object. So now we check if # there is a request object first, and if not, it passes the normal template loader. try: request = get_current_request() test_template_name = request.ab.run(template_name) return template_loader(test_template_name, template_dirs=template_dirs) except: return template_loader(template_name, template_dirs=template_dirs)
def load_template_source(self, template_name, template_dirs=None): request = get_current_request() test_template_name = template_name if request and not request.user_agent.is_bot: if 'exp' in request.GET: # If exp is provided, the experiment is not activated but the specific temnpalte is loaded test_template_name = request.ab.get_by_idx( template_name, int(request.GET['exp'])) else: test_template_name = request.ab.run(template_name) return super(ABLoader, self).load_template_source(test_template_name, template_dirs=template_dirs)