コード例 #1
0
    def render(self, context):
        from widgets.utils import options_to_query_string
        resolved = dict((opt.name, opt.resolve_value(context, value))
                        for opt, value in self.values)
        options = process_values(resolved, self.widget.options)

        as_name = self.as_name
        if as_name:
            as_name = self.as_name.resolve(context)
        return self.widget._render_wrapper(
            options=options,
            context=context,
            uid=as_name,
            raw_options=resolved,
            query_string=options_to_query_string(
                self.widget.__class__,
                options))
コード例 #2
0
ファイル: base.py プロジェクト: stringfellow/Django-Gidgits
    def _render_wrapper(self, options, context, **kwargs):
        '''
        Internal render method. Push new scope and add widget-specific
        context.

        '''
        saved_context_dicts = copy(context.dicts)
        context.push()

        # default uid can be overridden in kwargs
        context['uid'] = self.generate_uid(options)
        context['classname'] = self.__class__.__name__
        context['options'] = options
        context['qualified_classname'] = self.qualified_classname()
        if 'widget_debug' in context and context['widget_debug']:
            import inspect
            from widgets.utils import (
                options_to_tag_string, options_to_query_string)
            context['css'] = self.media._css
            context['js'] = self.media._js
            context['query_string'] = options_to_query_string(
                self.__class__,
                options)
            context['tag_string'] = options_to_tag_string(
                self.__class__,
                options)
            context['widget_file'] = inspect.getsourcefile(self.__class__)
        context.update(kwargs)
        rendered_widget = self.render(options, context)

        # Pop back context scope to state before widget render.  We can't rely
        # on a single 'Context.pop' because 'Context.update' also pushes a new
        # scope.
        context.dicts = saved_context_dicts

        return mark_safe(rendered_widget)