예제 #1
0
    def render(self, name, value, attrs=None, choices=()):
        """
        Renders this widget. HTML and JS code blocks all are rendered by this.

        :return: The rendered markup.
        :rtype: :py:obj:`unicode`
        """
        if logger.isEnabledFor(logging.DEBUG):
            t1 = util.timer_start('Select2Mixin.render')

        args = [name, value, attrs]
        if choices:
            args.append(choices)

        s = unicode(super(Select2Mixin, self).render(*args))  # Thanks to @ouhouhsami Issue#1
        if RENDER_SELECT2_STATICS:
            s += self.media.render()
        final_attrs = self.build_attrs(attrs)
        id_ = final_attrs.get('id', None)
        s += self.render_js_code(id_, name, value, attrs, choices)

        if logger.isEnabledFor(logging.DEBUG):
            util.timer_end(t1)
            logger.debug("Generated widget code:-\n%s", s)

        return mark_safe(s)
예제 #2
0
파일: widgets.py 프로젝트: axeliodiaz/Umail
    def render(self, name, value, attrs=None, choices=()):
        """
        Renders this widget. Html and JS code blocks all are rendered by this.

        :return: The rendered markup.
        :rtype: :py:obj:`unicode`
        """
        if logger.isEnabledFor(logging.DEBUG):
            t1 = util.timer_start('Select2Mixin.render')

        args = [name, value, attrs]
        if choices:
            args.append(choices)

        s = unicode(super(Select2Mixin, self).render(*args))  # Thanks to @ouhouhsami Issue#1
        if RENDER_SELECT2_STATICS:
            s += self.media.render()
        final_attrs = self.build_attrs(attrs)
        id_ = final_attrs.get('id', None)
        s += self.render_js_code(id_, name, value, attrs, choices)

        if logger.isEnabledFor(logging.DEBUG):
            util.timer_end(t1)
            logger.debug("Generated widget code:-\n%s", s)

        return mark_safe(s)