Browse Source

Finish up datetime picker work

* Document new datetime picker in release notes.
* Update the tests to new format
* Fix some PEP8 issues
master
Maik Hoepfel 11 years ago
parent
commit
0d5dc9e4c4
3 changed files with 24 additions and 16 deletions
  1. 5
    0
      docs/source/releases/v0.8.rst
  2. 15
    12
      oscar/forms/widgets.py
  3. 4
    4
      tests/unit/forms/widget_tests.py

+ 5
- 0
docs/source/releases/v0.8.rst View File

@@ -237,7 +237,12 @@ Minor changes
237 237
   when displaying tabular data, allowing sorting, etc. It also makes it easier
238 238
   to adapt e.g. the product list view in the dashboard to additional fields.
239 239
 
240
+* ``jquery-ui-datepicker`` has been replaced in the dashboard by
241
+  bootstrap-datetimepicker_. We still ship with ``jquery-ui-datepicker`` and
242
+  ``JQuery UI`` as it's in use in the frontend.
243
+
240 244
 .. _django-tables2: http://django-tables2.readthedocs.org/en/latest/
245
+.. _bootstrap-datetimepicker: http://jdewit.github.io/bootstrap-timepicker/
241 246
 
242 247
 .. _incompatible_changes_in_0.8:
243 248
 

+ 15
- 12
oscar/forms/widgets.py View File

@@ -1,16 +1,13 @@
1 1
 import re
2
-from django.utils import six
3
-from django.utils.six.moves import filter
4
-from django.utils.six.moves import map
5
-
6
-import django
7 2
 from django import forms
8 3
 from django.core.files.uploadedfile import InMemoryUploadedFile
9 4
 from django.forms.util import flatatt
10 5
 from django.forms.widgets import FileInput
11 6
 from django.template import Context
12 7
 from django.template.loader import render_to_string
13
-from django.utils import formats
8
+from django.utils import formats, six
9
+from django.utils.six.moves import filter
10
+from django.utils.six.moves import map
14 11
 from django.utils.encoding import force_text
15 12
 from django.utils.html import format_html
16 13
 from django.utils.safestring import mark_safe
@@ -121,9 +118,11 @@ class TimePickerInput(forms.TimeInput):
121 118
     def render(self, name, value, attrs=None):
122 119
         format = self.format
123 120
         if hasattr(self, 'manual_format'):
124
-            # For django <= 1.6.5, see https://code.djangoproject.com/ticket/21173
121
+            # For django <= 1.6.5, see
122
+            # https://code.djangoproject.com/ticket/21173
125 123
             if self.is_localized and not self.manual_format:
126
-                format = force_text(formats.get_format('DATE_INPUT_FORMATS')[0])
124
+                format = force_text(
125
+                    formats.get_format('DATE_INPUT_FORMATS')[0])
127 126
         else:
128 127
             # For django >= 1.7
129 128
             format = format or formats.get_format(self.format_key)[0]
@@ -153,9 +152,11 @@ class DatePickerInput(forms.DateInput):
153 152
     def render(self, name, value, attrs=None):
154 153
         format = self.format
155 154
         if hasattr(self, 'manual_format'):
156
-            # For django <= 1.6.5, see https://code.djangoproject.com/ticket/21173
155
+            # For django <= 1.6.5, see
156
+            # https://code.djangoproject.com/ticket/21173
157 157
             if self.is_localized and not self.manual_format:
158
-                format = force_text(formats.get_format('DATE_INPUT_FORMATS')[0])
158
+                format = force_text(
159
+                    formats.get_format('DATE_INPUT_FORMATS')[0])
159 160
         else:
160 161
             # For django >= 1.7
161 162
             format = format or formats.get_format(self.format_key)[0]
@@ -199,9 +200,11 @@ class DateTimePickerInput(forms.DateTimeInput):
199 200
     def render(self, name, value, attrs=None):
200 201
         format = self.format
201 202
         if hasattr(self, 'manual_format'):
202
-            # For django <= 1.6.5, see https://code.djangoproject.com/ticket/21173
203
+            # For django <= 1.6.5, see
204
+            # https://code.djangoproject.com/ticket/21173
203 205
             if self.is_localized and not self.manual_format:
204
-                format = force_text(formats.get_format('DATETIME_INPUT_FORMATS')[0])
206
+                format = force_text(
207
+                    formats.get_format('DATETIME_INPUT_FORMATS')[0])
205 208
         else:
206 209
             # For django >= 1.7
207 210
             format = format or formats.get_format(self.format_key)[0]

+ 4
- 4
tests/unit/forms/widget_tests.py View File

@@ -10,8 +10,8 @@ def compare_date_format(format, expected):
10 10
 
11 11
 def test_datetime_to_date_format_conversion():
12 12
     format_testcases = (
13
-        ('%Y-%m-%d', 'yy-mm-dd'),
14
-        ('%Y-%m-%d %H:%M', 'yy-mm-dd'),
13
+        ('%Y-%m-%d', 'yyyy-mm-dd'),
14
+        ('%Y-%m-%d %H:%M', 'yyyy-mm-dd'),
15 15
     )
16 16
     for format, expected in format_testcases:
17 17
         yield compare_date_format, format, expected
@@ -24,8 +24,8 @@ def compare_time_format(format, expected):
24 24
 
25 25
 def test_datetime_to_time_format_conversion():
26 26
     format_testcases = (
27
-        ('%Y-%m-%d %H:%M', 'HH:mm'),
28
-        ('%H:%M', 'HH:mm'),
27
+        ('%Y-%m-%d %H:%M', 'hh:ii'),
28
+        ('%H:%M', 'hh:ii'),
29 29
     )
30 30
     for format, expected in format_testcases:
31 31
         yield compare_time_format, format, expected

Loading…
Cancel
Save