Пример #1
0
    def get_template_path(self, template_path, **kwargs):
        """
        Returns a path (string) to a Mako template, which can either be in
        an override or will just return what is passed in which is expected to be a string
        """

        from microsite_configuration.microsite import get_value as microsite_get_value

        microsite_template_path = microsite_get_value('template_dir', None)
        if not microsite_template_path:
            microsite_template_path = '/'.join([
                settings.MICROSITE_ROOT_DIR,
                microsite_get_value('microsite_config_key', 'default'),
                'templates',
            ])

        relative_path = template_path[1:] if template_path.startswith('/') else template_path
        search_path = os.path.join(microsite_template_path, relative_path)
        if os.path.isfile(search_path):
            path = '/{0}/templates/{1}'.format(
                microsite_get_value('microsite_config_key'),
                relative_path
            )
            return path
        else:
            return template_path
Пример #2
0
    def get_template_path(self, template_path, **kwargs):
        """
        Returns a path (string) to a Mako template, which can either be in
        an override or will just return what is passed in which is expected to be a string
        """

        from microsite_configuration.microsite import get_value as microsite_get_value

        microsite_template_path = microsite_get_value('template_dir', None)
        if not microsite_template_path:
            microsite_template_path = '/'.join([
                settings.MICROSITE_ROOT_DIR,
                microsite_get_value('microsite_config_key', 'default'),
                'templates',
            ])

        relative_path = template_path[1:] if template_path.startswith('/') else template_path
        search_path = os.path.join(microsite_template_path, relative_path)
        if os.path.isfile(search_path):
            path = '/{0}/templates/{1}'.format(
                microsite_get_value('microsite_config_key'),
                relative_path
            )
            return path
        else:
            return template_path
Пример #3
0
    def get_template(self, uri):
        """
        Override of the base class for us to look into the
        database tables for a template definition, if we can't find
        one we'll return None which means "use default means" (aka filesystem)
        """
        cache_key = "template_cache." + fasthash(
            microsite_get_value('site_domain') + '.' + uri)
        template_text = cache.get(cache_key)  # pylint: disable=maybe-no-member

        if not template_text:
            # cache is empty so pull template from DB and fill cache.
            template_obj = MicrositeTemplate.get_template_for_microsite(
                microsite_get_value('site_domain'), uri)

            if not template_obj:
                # We need to set something in the cache to improve performance
                # of the templates stored in the filesystem as well
                cache.set(  # pylint: disable=maybe-no-member
                    cache_key, '##none',
                    settings.MICROSITE_DATABASE_TEMPLATE_CACHE_TTL)
                return None

            template_text = template_obj.template
            cache.set(  # pylint: disable=maybe-no-member
                cache_key, template_text,
                settings.MICROSITE_DATABASE_TEMPLATE_CACHE_TTL)

        if template_text == '##none':
            return None

        return Template(text=template_text)
Пример #4
0
    def get_template(self, uri):
        """
        Override of the base class for us to look into the
        database tables for a template definition, if we can't find
        one we'll return None which means "use default means" (aka filesystem)
        """
        cache_key = "template_cache." + fasthash(microsite_get_value('site_domain') + '.' + uri)
        template_text = cache.get(cache_key)  # pylint: disable=maybe-no-member

        if not template_text:
            # cache is empty so pull template from DB and fill cache.
            template_obj = MicrositeTemplate.get_template_for_microsite(
                microsite_get_value('site_domain'),
                uri
            )

            if not template_obj:
                # We need to set something in the cache to improve performance
                # of the templates stored in the filesystem as well
                cache.set(  # pylint: disable=maybe-no-member
                    cache_key, '##none', settings.MICROSITE_DATABASE_TEMPLATE_CACHE_TTL
                )
                return None

            template_text = template_obj.template
            cache.set(  # pylint: disable=maybe-no-member
                cache_key, template_text, settings.MICROSITE_DATABASE_TEMPLATE_CACHE_TTL
            )

        if template_text == '##none':
            return None

        return Template(
            text=template_text
        )
Пример #5
0
    def get_template_path(self, relative_path, **kwargs):
        """
        Returns a path (string) to a Mako template, which can either be in
        an override or will just return what is passed in which is expected to be a string
        """

        from microsite_configuration.microsite import get_value as microsite_get_value

        microsite_template_path = microsite_get_value("template_dir", None)

        if not microsite_template_path:
            microsite_template_path = "/".join(
                [settings.MICROSITE_ROOT_DIR, microsite_get_value("microsite_config_key", "default"), "templates"]
            )

        search_path = os.path.join(microsite_template_path, relative_path)
        if os.path.isfile(search_path):
            path = "/{0}/templates/{1}".format(microsite_get_value("microsite_config_key"), relative_path)
            return path
        else:
            return relative_path