Commit dde64dbaa44006180342cfd323603d2e7f93201e
1 parent
00ddd60e
Exists in
master
and in
39 other branches
Fixing datetimepicker to work with more date formats
Showing
3 changed files
with
18 additions
and
7 deletions
Show diff stats
src/colab/custom_settings.py
@@ -13,6 +13,11 @@ LANGUAGES = ( | @@ -13,6 +13,11 @@ LANGUAGES = ( | ||
13 | ('pt-br', gettext('Portuguese')), | 13 | ('pt-br', gettext('Portuguese')), |
14 | ) | 14 | ) |
15 | 15 | ||
16 | +DJANGO_DATE_FORMAT_TO_JS = { | ||
17 | + 'pt-br': ('pt-BR', 'dd/MM/yyyy'), | ||
18 | + 'en': ('en', 'MM/dd/yyyy'), | ||
19 | +} | ||
20 | + | ||
16 | LANGUAGE_CODE = 'pt-br' | 21 | LANGUAGE_CODE = 'pt-br' |
17 | 22 | ||
18 | # ORDERING_DATA receives the options to order for as it's keys and a dict as | 23 | # ORDERING_DATA receives the options to order for as it's keys and a dict as |
src/search/views.py
@@ -8,6 +8,11 @@ from haystack.views import SearchView | @@ -8,6 +8,11 @@ from haystack.views import SearchView | ||
8 | 8 | ||
9 | class ColabSearchView(SearchView): | 9 | class ColabSearchView(SearchView): |
10 | def extra_context(self, *args, **kwargs): | 10 | def extra_context(self, *args, **kwargs): |
11 | + | ||
12 | + use_language, date_format = settings.DJANGO_DATE_FORMAT_TO_JS.get( | ||
13 | + self.request.LANGUAGE_CODE | ||
14 | + ) | ||
15 | + | ||
11 | types = { | 16 | types = { |
12 | 'wiki': { | 17 | 'wiki': { |
13 | 'name': _(u'Wiki'), | 18 | 'name': _(u'Wiki'), |
@@ -111,5 +116,7 @@ class ColabSearchView(SearchView): | @@ -111,5 +116,7 @@ class ColabSearchView(SearchView): | ||
111 | return dict( | 116 | return dict( |
112 | filters=types.get(type_chosen), | 117 | filters=types.get(type_chosen), |
113 | type_chosen=type_chosen, | 118 | type_chosen=type_chosen, |
114 | - order_data=settings.ORDERING_DATA | 119 | + order_data=settings.ORDERING_DATA, |
120 | + date_format=date_format, | ||
121 | + use_language=use_language, | ||
115 | ) | 122 | ) |
src/templates/search/search.html
@@ -3,15 +3,14 @@ | @@ -3,15 +3,14 @@ | ||
3 | 3 | ||
4 | {% block head_js %} | 4 | {% block head_js %} |
5 | <script type="text/javascript" src="{{ STATIC_URL }}third-party/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script> | 5 | <script type="text/javascript" src="{{ STATIC_URL }}third-party/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script> |
6 | -{% if LANGUAGE_CODE == "pt-br" %} | ||
7 | - <script type="text/javascript" src="{{ STATIC_URL }}third-party/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.pt-BR.js"></script> | ||
8 | -{% endif %} | 6 | +<script type="text/javascript" src="{{ STATIC_URL }}third-party/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.{{ use_language }}.js"></script> |
9 | 7 | ||
10 | <script type="text/javascript"> | 8 | <script type="text/javascript"> |
11 | $(function () { | 9 | $(function () { |
12 | $('#datepicker_since, #datepicker_until').datetimepicker({ | 10 | $('#datepicker_since, #datepicker_until').datetimepicker({ |
13 | pickTime: false, | 11 | pickTime: false, |
14 | - {% if LANGUAGE_CODE == "pt-br" %}language: 'pt-BR'{% endif %} | 12 | + language: '{{ use_language }}', |
13 | + format: '{{ date_format }}', | ||
15 | }); | 14 | }); |
16 | }); | 15 | }); |
17 | </script> | 16 | </script> |
@@ -124,7 +123,7 @@ | @@ -124,7 +123,7 @@ | ||
124 | <div class="form-group"> | 123 | <div class="form-group"> |
125 | <label for="since">{% trans "Since" %}</label> | 124 | <label for="since">{% trans "Since" %}</label> |
126 | <div class="input-group date" id="datepicker_since"> | 125 | <div class="input-group date" id="datepicker_since"> |
127 | - <input type="text" class="form-control" placeholder="{% trans "Since" %}" name="since" value="{{ request.GET.since }}" {% if LANGUAGE_CODE == 'pt-br' %}data-format="dd/MM/yyyy"{% endif %} /> | 126 | + <input type="text" class="form-control" placeholder="{% trans "Since" %}" name="since" value="{{ request.GET.since }}" /> |
128 | <span class="input-group-addon"> | 127 | <span class="input-group-addon"> |
129 | <span class="glyphicon glyphicon-calendar"></span> | 128 | <span class="glyphicon glyphicon-calendar"></span> |
130 | </span> | 129 | </span> |
@@ -133,7 +132,7 @@ | @@ -133,7 +132,7 @@ | ||
133 | <div class="form-group"> | 132 | <div class="form-group"> |
134 | <label for="until">{% trans "Until" %}</label> | 133 | <label for="until">{% trans "Until" %}</label> |
135 | <div class="input-group date" id="datepicker_until"> | 134 | <div class="input-group date" id="datepicker_until"> |
136 | - <input type="text" class="form-control" placeholder="{% trans "Until" %}" name="until" value="{{ request.GET.until }}" {% if LANGUAGE_CODE == 'pt-br' %}data-format="dd/MM/yyyy"{% endif %} /> | 135 | + <input type="text" class="form-control" placeholder="{% trans "Until" %}" name="until" value="{{ request.GET.until }}" /> |
137 | <span class="input-group-addon"> | 136 | <span class="input-group-addon"> |
138 | <span class="glyphicon glyphicon-calendar"></span> | 137 | <span class="glyphicon glyphicon-calendar"></span> |
139 | </span> | 138 | </span> |