sshwsfc / xadmin

Drop-in replacement of Django admin comes with lots of goodies, fully extensible with plugin support, pretty UI based on Twitter Bootstrap.
http://www.xadmin.io
BSD 3-Clause "New" or "Revised" License
4.76k stars 1.41k forks source link

django2.0 分支 AdminSplitDateTime 里render()方法处理错误 #499

Open JzwOnly opened 6 years ago

JzwOnly commented 6 years ago

Admin后台 User 打开 会造成小标越界 image

image

super(AdminSplitDateTime, self).render()方法 返回的两个input 标签 之间没有\n ,split(‘\n’)无法分割 input_html[1] 下标越界

Actmerce commented 6 years ago

我也遇到了! model里边有DateTimeField就报错。暂时用 '/><' 作为切割符暂时用着

yuhan963 commented 6 years ago

input_html = [ht for ht in super(AdminSplitDateTime, self).render(name, value, attrs).split('/><') if ht != ''] if (len(input_html) > 1): input_html[0] = input_html[0] + "/>" input_html[1] = "<" + input_html[1] 改成这样用

zzp1006050233 commented 6 years ago

谢谢。解决了呢

chengdalei commented 6 years ago

大佬们,有点小问题,现在那个按钮只能点击一下,如果你重新换了时间,再从新点击,就没有效果了

cupen commented 6 years ago

@dalei1995 改 el.val(value); 看看。 https://github.com/sshwsfc/xadmin/blob/master/xadmin/static/xadmin/js/xadmin.widget.datetime.js#L67

msterzhang commented 6 years ago

能解决在windows本地,但是在服务器上就gg,无法获取时间,需要修改成如下

def render(self, name, value, attrs=None):
        # input_html = [ht for ht in super(AdminSplitDateTime, self).render(name, value, attrs).split('\n') if ht != '']
        # return input_html
        super_render = super().render(name,value,attrs).replace('/>','/>\n')
        import re
        input_html = [ht for ht in re.split(r'\n+',super_render) if ht != '']
        # input_html = [ht for ht in super(AdminSplitDateTime, self).render(name, value, attrs).split('/><') if ht != '']
        # if (len(input_html) > 1):
        #     input_html[0] = input_html[0] + "/>"
        #     input_html[1] = "<" + input_html[1]

        return mark_safe(
                '<div class="datetime clearfix"><div class="input-group date bootstrap-datepicker"><span class="input-group-addon"><i class="fa fa-calendar"></i></span>%s'
                '<span class="input-group-btn"><button class="btn btn-default" type="button">%s</button></span></div>'
                '<div class="input-group time bootstrap-clockpicker"><span class="input-group-addon"><i class="fa fa-clock-o">'
                '</i></span>%s<span class="input-group-btn"><button class="btn btn-default" type="button">%s</button></span></div></div>' % (
                    input_html[0], _(u'Today'), input_html[1], _(u'Now')))