misc: simplify datetime widget, remove support for multiple bootstrap versions
This commit is contained in:
parent
308bd37ecd
commit
9ce2f42c63
|
@ -1,6 +1,6 @@
|
|||
# Bootstrap django-datetime-widget is a simple and clean widget for DateField,
|
||||
# Timefiled and DateTimeField in Django framework. It is based on Bootstrap
|
||||
# datetime picker, supports both Bootstrap 3 and Bootstrap 2
|
||||
# datetime picker, supports Bootstrap 2
|
||||
#
|
||||
# https://github.com/asaglimbeni/django-datetime-widget
|
||||
#
|
||||
|
@ -98,8 +98,7 @@ DATE_FORMAT_PY_JS_MAPPING = {
|
|||
DATE_FORMAT_TO_JS_REGEX = re.compile(r'(?<!\w)(' + '|'.join(DATE_FORMAT_PY_JS_MAPPING.keys()) + r')\b')
|
||||
|
||||
|
||||
BOOTSTRAP_INPUT_TEMPLATE = {
|
||||
2: """
|
||||
BOOTSTRAP_INPUT_TEMPLATE = """
|
||||
<div id="%(id)s" class="controls input-append date">
|
||||
%(rendered_widget)s
|
||||
%(clear_button)s
|
||||
|
@ -108,21 +107,9 @@ BOOTSTRAP_INPUT_TEMPLATE = {
|
|||
<script type="text/javascript">
|
||||
$("#%(id)s").datetimepicker({%(options)s});
|
||||
</script>
|
||||
""",
|
||||
3: """
|
||||
<div id="%(id)s" class="input-group date">
|
||||
%(rendered_widget)s
|
||||
%(clear_button)s
|
||||
<span class="input-group-addon"><span class="glyphicon %(glyphicon)s"></span></span>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$("#%(id)s").datetimepicker({%(options)s}).find('input').addClass("form-control");
|
||||
</script>
|
||||
"""
|
||||
}
|
||||
|
||||
CLEAR_BTN_TEMPLATE = {2: """<span class="add-on"><i class="icon-remove"></i></span>""",
|
||||
3: """<span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>"""}
|
||||
CLEAR_BTN_TEMPLATE = """<span class="add-on"><i class="icon-remove"></i></span>"""
|
||||
|
||||
|
||||
quoted_options = set([
|
||||
|
@ -171,13 +158,7 @@ class PickerWidgetMixin(object):
|
|||
format_name = None
|
||||
glyphicon = None
|
||||
|
||||
def __init__(self, attrs=None, options=None, usel10n=None, bootstrap_version=None):
|
||||
|
||||
if bootstrap_version in [2, 3]:
|
||||
self.bootstrap_version = bootstrap_version
|
||||
else:
|
||||
# default 2 to mantain support to old implemetation of django-datetime-widget
|
||||
self.bootstrap_version = 2
|
||||
def __init__(self, attrs=None, options=None, usel10n=None):
|
||||
|
||||
if attrs is None:
|
||||
attrs = {'readonly': ''}
|
||||
|
@ -238,12 +219,10 @@ class PickerWidgetMixin(object):
|
|||
|
||||
clear_button = quote('clearBtn', self.options.get('clearBtn', 'true')) == 'true'
|
||||
|
||||
return mark_safe(
|
||||
BOOTSTRAP_INPUT_TEMPLATE[self.bootstrap_version]
|
||||
% dict(
|
||||
return mark_safe(BOOTSTRAP_INPUT_TEMPLATE % dict(
|
||||
id=id,
|
||||
rendered_widget=rendered_widget,
|
||||
clear_button=CLEAR_BTN_TEMPLATE[self.bootstrap_version] if clear_button else "",
|
||||
clear_button=CLEAR_BTN_TEMPLATE if clear_button else "",
|
||||
glyphicon=self.glyphicon,
|
||||
options=js_options
|
||||
)
|
||||
|
@ -276,7 +255,7 @@ class DateTimeWidget(PickerWidgetMixin, DateTimeInput):
|
|||
format_name = 'DATETIME_INPUT_FORMATS'
|
||||
glyphicon = 'glyphicon-th'
|
||||
|
||||
def __init__(self, attrs=None, options=None, usel10n=None, bootstrap_version=None):
|
||||
def __init__(self, attrs=None, options=None, usel10n=None):
|
||||
|
||||
if options is None:
|
||||
options = {}
|
||||
|
@ -284,7 +263,7 @@ class DateTimeWidget(PickerWidgetMixin, DateTimeInput):
|
|||
# Set the default options to show only the datepicker object
|
||||
options['format'] = options.get('format', 'dd/mm/yyyy hh:ii')
|
||||
|
||||
super(DateTimeWidget, self).__init__(attrs, options, usel10n, bootstrap_version)
|
||||
super(DateTimeWidget, self).__init__(attrs, options, usel10n)
|
||||
|
||||
|
||||
class DateWidget(PickerWidgetMixin, DateInput):
|
||||
|
@ -296,7 +275,7 @@ class DateWidget(PickerWidgetMixin, DateInput):
|
|||
format_name = 'DATE_INPUT_FORMATS'
|
||||
glyphicon = 'glyphicon-calendar'
|
||||
|
||||
def __init__(self, attrs=None, options=None, usel10n=None, bootstrap_version=None):
|
||||
def __init__(self, attrs=None, options=None, usel10n=None):
|
||||
|
||||
if options is None:
|
||||
options = {}
|
||||
|
@ -306,7 +285,7 @@ class DateWidget(PickerWidgetMixin, DateInput):
|
|||
options['minView'] = options.get('minView', 2)
|
||||
options['format'] = options.get('format', 'dd/mm/yyyy')
|
||||
|
||||
super(DateWidget, self).__init__(attrs, options, usel10n, bootstrap_version)
|
||||
super(DateWidget, self).__init__(attrs, options, usel10n)
|
||||
|
||||
|
||||
class TimeWidget(PickerWidgetMixin, TimeInput):
|
||||
|
@ -318,7 +297,7 @@ class TimeWidget(PickerWidgetMixin, TimeInput):
|
|||
format_name = 'TIME_INPUT_FORMATS'
|
||||
glyphicon = 'glyphicon-time'
|
||||
|
||||
def __init__(self, attrs=None, options=None, usel10n=None, bootstrap_version=None):
|
||||
def __init__(self, attrs=None, options=None, usel10n=None):
|
||||
|
||||
if options is None:
|
||||
options = {}
|
||||
|
@ -329,5 +308,4 @@ class TimeWidget(PickerWidgetMixin, TimeInput):
|
|||
options['maxView'] = options.get('maxView', 1)
|
||||
options['format'] = options.get('format', 'hh:ii')
|
||||
|
||||
super(TimeWidget, self).__init__(attrs, options, usel10n, bootstrap_version)
|
||||
|
||||
super(TimeWidget, self).__init__(attrs, options, usel10n)
|
||||
|
|
Loading…
Reference in New Issue