12 |
12 |
import uuid
|
13 |
13 |
|
14 |
14 |
from django.forms.widgets import DateTimeInput, DateInput, TimeInput
|
15 |
|
from django.utils.formats import get_language
|
|
15 |
from django.utils.formats import get_language, get_format
|
16 |
16 |
from django.utils.safestring import mark_safe
|
|
17 |
from django.utils.translation import ugettext_lazy as _
|
17 |
18 |
|
18 |
19 |
from gadjo.templatetags.gadjo import xstatic
|
19 |
20 |
|
... | ... | |
51 |
52 |
%(rendered_widget)s
|
52 |
53 |
%(clear_button)s
|
53 |
54 |
<span class="add-on"><i class="icon-th"></i></span>
|
|
55 |
<span class="helptext">%(format_label)s %(format)s</span>
|
54 |
56 |
<script type="text/javascript">
|
55 |
57 |
$("#%(id)s").datetimepicker({%(options)s});
|
56 |
58 |
</script>
|
... | ... | |
77 |
79 |
def __init__(self, attrs=None, options=None, usel10n=None):
|
78 |
80 |
|
79 |
81 |
if attrs is None:
|
80 |
|
attrs = {'readonly': ''}
|
|
82 |
attrs = {}
|
81 |
83 |
|
82 |
84 |
self.options = options
|
83 |
85 |
self.options['language'] = get_language().split('-')[0]
|
... | ... | |
92 |
94 |
|
93 |
95 |
super(PickerWidgetMixin, self).__init__(attrs, format=self.format)
|
94 |
96 |
|
|
97 |
def get_format(self):
|
|
98 |
format = get_format(self.format_name)[0]
|
|
99 |
for py, js in DATE_FORMAT_PY_JS_MAPPING.iteritems():
|
|
100 |
format = format.replace(py, js)
|
|
101 |
return format
|
|
102 |
|
95 |
103 |
def render(self, name, value, attrs=None):
|
96 |
104 |
final_attrs = self.build_attrs(attrs)
|
97 |
105 |
final_attrs['class'] = "controls input-append date"
|
... | ... | |
115 |
123 |
rendered_widget=rendered_widget,
|
116 |
124 |
clear_button=CLEAR_BTN_TEMPLATE if self.options.get('clearBtn') else '',
|
117 |
125 |
glyphicon=self.glyphicon,
|
118 |
|
options=js_options
|
|
126 |
options=js_options,
|
|
127 |
format_label=_('Format:'),
|
|
128 |
format=self.options['format']
|
119 |
129 |
)
|
120 |
130 |
)
|
121 |
131 |
|
... | ... | |
135 |
145 |
options = {}
|
136 |
146 |
|
137 |
147 |
# Set the default options to show only the datepicker object
|
138 |
|
options['format'] = options.get('format', 'dd/mm/yyyy hh:ii')
|
|
148 |
options['format'] = options.get('format', self.get_format())
|
139 |
149 |
|
140 |
150 |
super(DateTimeWidget, self).__init__(attrs, options, usel10n)
|
141 |
151 |
|
... | ... | |
157 |
167 |
# Set the default options to show only the datepicker object
|
158 |
168 |
options['startView'] = options.get('startView', 2)
|
159 |
169 |
options['minView'] = options.get('minView', 2)
|
160 |
|
options['format'] = options.get('format', 'dd/mm/yyyy')
|
|
170 |
options['format'] = options.get('format', self.get_format())
|
161 |
171 |
|
162 |
172 |
super(DateWidget, self).__init__(attrs, options, usel10n)
|
163 |
173 |
|
... | ... | |
180 |
190 |
options['startView'] = options.get('startView', 1)
|
181 |
191 |
options['minView'] = options.get('minView', 0)
|
182 |
192 |
options['maxView'] = options.get('maxView', 1)
|
183 |
|
options['format'] = options.get('format', 'hh:ii')
|
|
193 |
options['format'] = options.get('format', self.get_format())
|
184 |
194 |
|
185 |
195 |
super(TimeWidget, self).__init__(attrs, options, usel10n)
|
186 |
|
-
|