8
0
Fork 0
mirror of https://gitlab.federez.net/re2o/re2o synced 2024-07-04 05:04:06 +00:00
re2o/users/widgets.py

24 lines
1.3 KiB
Python
Raw Normal View History

2018-05-05 15:58:13 +00:00
from django.forms.widgets import Input
from django.forms.utils import flatatt
from django.utils.safestring import mark_safe
from django.template import Context, Template
from django.template.loader import get_template
class DateTimePicker(Input):
def render(self, name, value, attrs=None):
super().render(name, value, attrs)
flat_attrs = flatatt(attrs)
html = '''{% load static %}<script src="{% static 'js/jquery-2.2.4.min.js' %}"></script><script src="{% static 'js/jquery-ui-1.12.1/jquery-ui.min.js' %}"></script><script src="{% static 'js/jquery-ui-timepicker-addon.js' %}"></script><link href="{% static 'js/jquery-ui-1.12.1/jquery-ui.min.css' %}" rel="stylesheet"/><link href="{% static 'css/jquery-ui-timepicker-addon.css' %}" rel="stylesheet"/>'''
html += '''<input %(attrs)s name="datetimepicker" type="text" class="form-control" id="datetimepicker"/>
<script>
$(document).ready(function(){
$("#%(id)s").datetimepicker({
dateFormat:'yy-mm-dd',
timeFormat: 'HH:mm:ss',
})
});
</script>'''%{'attrs':flat_attrs, 'id':attrs['id']}
template = Template(html)
context = Context({})
return template.render(context)