Example #1
0
 def render(self, context):
     try:
         template_name = self.template_name.resolve(context)
         theme = context.get('THEME', get_setting('module', 'theme_editor', 'theme'))
         theme_template = get_theme_template(template_name, theme=theme)
         try:
             t = get_template(theme_template)
         except TemplateDoesNotExist:
             t = get_default_template(template_name)
         return t.render(context)
     except:
         if settings.TEMPLATE_DEBUG:
             raise
         return ''
Example #2
0
 def render(self, context):
     try:
         template_name = self.template_name.resolve(context)
         theme = context.get('THEME',
                             get_setting('module', 'theme_editor', 'theme'))
         theme_template = get_theme_template(template_name, theme=theme)
         try:
             t = get_template(theme_template)
         except TemplateDoesNotExist:
             t = get_default_template(template_name)
         return t.render(context)
     except:
         if settings.TEMPLATE_DEBUG:
             raise
         return ''
Example #3
0
 def render(self, context):
     theme = context.get('THEME', get_setting('module', 'theme_editor', 'theme'))
     theme_template = get_theme_template(self.template_path, theme=theme)
     try:
         try:
             t = get_template(theme_template)
         except TemplateDoesNotExist:
             t = get_default_template(self.template_path)
         self.template = t
     except:
         if settings.TEMPLATE_DEBUG:
             raise
         self.template = None
     if self.template:
         return self.template.render(context)
     else:
         return ''
Example #4
0
 def render(self, context):
     theme = context.get('THEME',
                         get_setting('module', 'theme_editor', 'theme'))
     theme_template = get_theme_template(self.template_path, theme=theme)
     try:
         try:
             t = get_template(theme_template)
         except TemplateDoesNotExist:
             t = get_default_template(self.template_path)
         self.template = t
     except:
         if settings.TEMPLATE_DEBUG:
             raise
         self.template = None
     if self.template:
         return self.template.render(context)
     else:
         return ''
Example #5
0
    def render(self, context):
        context['setting_name'] = unicode(self.template).replace(
            'MODULE_THEME_', '').lower()
        try:
            setting_value = Variable(self.template).resolve(context)
        except VariableDoesNotExist:
            setting_value = None

        if setting_value:
            # First try to render this as a box
            user = AnonymousUser()
            if 'user' in context:
                if isinstance(context['user'], User):
                    user = context['user']
            try:
                # for performance reason, pass AnonymousUser() to reduce the joins of objectpermissions
                # in the meantime, we do want to show public items on homepage
                filters = get_query_filters(AnonymousUser(), 'boxes.view_box')
                box = Box.objects.filter(filters).filter(pk=setting_value)
                context['box'] = box[0]
                template = get_template('theme_includes/box.html')
                return template.render(context)
            except:
                # Otherwise try to render a template
                try:
                    template_name = os.path.join('theme_includes',
                                                 setting_value)
                    theme = context.get(
                        'THEME', get_setting('module', 'theme_editor',
                                             'theme'))
                    theme_template = get_theme_template(template_name,
                                                        theme=theme)
                    try:
                        t = get_template(theme_template)
                    except TemplateDoesNotExist:
                        t = get_default_template(template_name)
                    return t.render(context)
                except:
                    if settings.TEMPLATE_DEBUG:
                        raise
                    return ''
        else:
            return ''
Example #6
0
def render_to_theme(template_name, dictionary={}, context_instance=Context):
    """Loads the given template_name and renders it with the given dictionary as
    context. The template_name may be a string to load a single template using
    get_template, or it may be a tuple to use select_template to find one of
    the templates in the list. Returns a string.
    This shorcut prepends the template_name given with the selected theme's
    directory
    """

    context_instance.update(dictionary)
    toggle = 'TOGGLE_TEMPLATE' in context_instance
    #theme = context_instance['THEME']
    theme = get_setting('module', 'theme_editor', 'theme')
    theme_template = get_theme_template(template_name, theme=theme)
    context_instance["THEME_TEMPLATE"] = template_name
    context_instance["CUSTOM_TEMPLATE"] = False

    if toggle:
        t = get_default_template(template_name)
    else:
        if isinstance(template_name, (list, tuple)):
            try:
                t = select_template(theme_template)
            except TemplateDoesNotExist:
                t = get_default_template(template_name)
                context_instance["CUSTOM_TEMPLATE"] = False
        else:
            try:
                t, origin = get_template(theme_template)
                if origin and re.search("^%s.+" % get_theme_root(),
                                        origin.name):
                    context_instance["CUSTOM_TEMPLATE"] = True

                if 'homepage.html' in template_name:
                    context_instance["CUSTOM_TEMPLATE"] = False

            except TemplateDoesNotExist:
                t = get_default_template(template_name)
                context_instance["CUSTOM_TEMPLATE"] = False

    return strip_content_above_doctype(t.render(context_instance))
Example #7
0
    def get_parent(self, context):
        parent = self.parent_name.resolve(context)
        if not parent:
            error_msg = "Invalid template name in 'extends' tag: %r." % parent
            if self.parent_name.filters or\
                    isinstance(self.parent_name.var, Variable):
                error_msg += " Got this from the '%s' variable." %\
                    self.parent_name.token
            raise TemplateSyntaxError(error_msg)
        if hasattr(parent, 'render'):
            return parent # parent is a Template object

        theme = context.get('THEME', get_setting('module', 'theme_editor', 'theme'))
        theme_template = get_theme_template(parent, theme=theme)
        try:
            template = context.template.engine.get_template(theme_template)
        except TemplateDoesNotExist:
            # to be sure that we are not loadnig the active theme's template
            template = context.template.engine.get_template(parent)

        return template
Example #8
0
def render_to_theme(template_name, dictionary={}, context_instance=Context):
    """Loads the given template_name and renders it with the given dictionary as
    context. The template_name may be a string to load a single template using
    get_template, or it may be a tuple to use select_template to find one of
    the templates in the list. Returns a string.
    This shorcut prepends the template_name given with the selected theme's
    directory
    """

    context_instance.update(dictionary)
    toggle = 'TOGGLE_TEMPLATE' in context_instance
    #theme = context_instance['THEME']
    theme = get_setting('module', 'theme_editor', 'theme')
    theme_template = get_theme_template(template_name, theme=theme)
    context_instance["THEME_TEMPLATE"] = template_name
    context_instance["CUSTOM_TEMPLATE"] = False

    if toggle:
        t = get_default_template(template_name)
    else:
        if isinstance(template_name, (list, tuple)):
            try:
                t = select_template(theme_template)
            except TemplateDoesNotExist:
                t = get_default_template(template_name)
                context_instance["CUSTOM_TEMPLATE"] = False
        else:
            try:
                t, origin = get_template(theme_template)
                if origin and re.search("^%s.+" % get_theme_root(), origin.name):
                    context_instance["CUSTOM_TEMPLATE"] = True

                if 'homepage.html' in template_name:
                    context_instance["CUSTOM_TEMPLATE"] = False

            except TemplateDoesNotExist:
                t = get_default_template(template_name)
                context_instance["CUSTOM_TEMPLATE"] = False

    return strip_content_above_doctype(t.render(context_instance))
Example #9
0
    def get_parent(self, context):
        parent = self.parent_name.resolve(context)
        if not parent:
            error_msg = "Invalid template name in 'extends' tag: %r." % parent
            if self.parent_name.filters or\
                    isinstance(self.parent_name.var, Variable):
                error_msg += " Got this from the '%s' variable." %\
                    self.parent_name.token
            raise TemplateSyntaxError(error_msg)
        if hasattr(parent, 'render'):
            return parent  # parent is a Template object

        theme = context.get('THEME',
                            get_setting('module', 'theme_editor', 'theme'))
        theme_template = get_theme_template(parent, theme=theme)
        try:
            template = context.template.engine.get_template(theme_template)
        except TemplateDoesNotExist:
            # to be sure that we are not loadnig the active theme's template
            template = context.template.engine.get_template(parent)

        return template
Example #10
0
    def render(self, context):
        context['setting_name'] = unicode(self.template).replace('MODULE_THEME_', '').lower()
        try:
            setting_value = Variable(self.template).resolve(context)
        except VariableDoesNotExist:
            setting_value = None

        if setting_value:
            # First try to render this as a box
            user = AnonymousUser()
            if 'user' in context:
                if isinstance(context['user'], User):
                    user = context['user']
            try:
                # for performance reason, pass AnonymousUser() to reduce the joins of objectpermissions
                # in the meantime, we do want to show public items on homepage
                filters = get_query_filters(AnonymousUser(), 'boxes.view_box')
                box = Box.objects.filter(filters).filter(pk=setting_value)
                context['box'] = box[0]
                template = get_template('theme_includes/box.html')
                return template.render(context)
            except:
                # Otherwise try to render a template
                try:
                    template_name = os.path.join('theme_includes', setting_value)
                    theme = context.get('THEME', get_setting('module', 'theme_editor', 'theme'))
                    theme_template = get_theme_template(template_name, theme=theme)
                    try:
                        t = get_template(theme_template)
                    except TemplateDoesNotExist:
                        t = get_default_template(template_name)
                    return t.render(context)
                except:
                    if settings.TEMPLATE_DEBUG:
                        raise
                    return ''
        else:
            return ''