admin.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:jenkins-panel 作者: nikitinsm 项目源码 文件源码
def render(self, name, value, attrs=None):
        if self.is_localized:
            for widget in self.widgets:
                widget.is_localized = self.is_localized
        # value is a list of values, each corresponding to a widget
        # in self.widgets.
        if not isinstance(value, list):
            value = self.decompress(value)
        output = []
        final_attrs = self.build_attrs(attrs)
        id_ = final_attrs.get('id', None)
        output.append('<table class="table table-striped table-bordered table-hover table-condensed" style="width: 50%; margin: 0">')
        for i, widget in enumerate(self.widgets):
            try:
                widget_value = value[i]
            except IndexError:
                widget_value = None

            field = widget.attrs.pop('field', None)

            final_attrs['style'] = 'width: auto'
            if type(widget) in (widgets.CheckboxInput, ):
                if widget_value == 'false':
                    widget_value = None

            if id_:
                final_attrs = dict(final_attrs, id='%s_%s' % (id_, i))

            output.append('<tr>')
            output.append('<td style="width: 30%">')
            if field:
                output.append('<label>%s</label>' % field.label)
            output.append('</td>')
            output.append('<td>')
            output.append(widget.render(name + '_%s' % i, widget_value, final_attrs))
            if field.help_text:
                output.append('<p class="help-block">')
                output.append(field.help_text)
                output.append('</p>')
            output.append('</td>')
            output.append('<tr>')
        output.append('</table>')
        return mark_safe(self.format_output(output))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号