コード例 #1
0
ファイル: theme_tags.py プロジェクト: siolag161/tendenci
 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 ''
コード例 #2
0
ファイル: theme_tags.py プロジェクト: MariusCC/tendenci
 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 ''
コード例 #3
0
ファイル: theme_tags.py プロジェクト: MariusCC/tendenci
 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 ''
コード例 #4
0
ファイル: theme_tags.py プロジェクト: siolag161/tendenci
 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 ''
コード例 #5
0
ファイル: theme_tags.py プロジェクト: zenny/tendenci
    def render(self, context):
        context['setting_name'] = unicode(self.template_name).replace(
            'MODULE_THEME_', '').lower()
        try:
            setting_value = Variable(self.template_name).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 ''
コード例 #6
0
ファイル: theme_tags.py プロジェクト: MariusCC/tendenci
    def get_parent(self, context):
        if self.parent_name_expr:
            self.parent_name = self.parent_name_expr.resolve(context)
        parent = unicode(self.parent_name)

        if not parent:
            error_msg = "Invalid template name in 'extends' tag: %r." % parent
            if self.parent_name_expr:
                error_msg += " Got this from the '%s' variable." % self.parent_name_expr.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 = get_template(theme_template)
        except TemplateDoesNotExist:
            #to be sure that we not are loading the active theme's template
            template = get_default_template(parent)
        return template
コード例 #7
0
ファイル: theme_tags.py プロジェクト: siolag161/tendenci
    def get_parent(self, context):
        if self.parent_name_expr:
            self.parent_name = self.parent_name_expr.resolve(context)
        parent = unicode(self.parent_name)

        if not parent:
            error_msg = "Invalid template name in 'extends' tag: %r." % parent
            if self.parent_name_expr:
                error_msg += " Got this from the '%s' variable." % self.parent_name_expr.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 = get_template(theme_template)
        except TemplateDoesNotExist:
            #to be sure that we not are loading the active theme's template
            template = get_default_template(parent)
        return template
コード例 #8
0
ファイル: shortcuts.py プロジェクト: zenny/tendenci
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_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))
コード例 #9
0
ファイル: shortcuts.py プロジェクト: MariusCC/tendenci
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_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))
コード例 #10
0
ファイル: theme_tags.py プロジェクト: MariusCC/tendenci
    def render(self, context):
        context['setting_name'] = unicode(self.template_name).replace('MODULE_THEME_', '').lower()
        try:
            setting_value = Variable(self.template_name).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 ''