From 550d4e94daa98fd3c53548f3a6b91109619d1423 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Sat, 21 Feb 2015 17:37:14 +0000 Subject: [PATCH 1/3] Standardise date/time formats between admin datetime widgets and Javascript code. The JS for the datetime picker was previously updated to include seconds, to match Django's default format and thus fix #479 - however, the same bug also affected the time picker, which was left unfixed. Since we typically don't want seconds in our datetimes anyhow, we reverse that fix here, and instead update AdminDateWidget / AdminTimeWidget / AdminDateTimeWidget to explicitly use the seconds-less format that the JS expects. This also ensures that the JS behaviour will not break as a result of a site owner setting a non-standard value for DATE_INPUT_FORMATS / TIME_INPUT_FORMATS / DATETIME_INPUT_FORMATS in their site settings. --- .../static/wagtailadmin/js/page-editor.js | 4 +-- wagtail/wagtailadmin/widgets.py | 12 +++++++++ .../0011_update_golive_expire_help_text.py | 26 +++++++++++++++++++ wagtail/wagtailcore/models.py | 4 +-- 4 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 wagtail/wagtailcore/migrations/0011_update_golive_expire_help_text.py diff --git a/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js b/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js index 4f53792b9..448d4c052 100644 --- a/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js +++ b/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js @@ -104,7 +104,7 @@ function initDateTimeChooser(id) { if (window.dateTimePickerTranslations) { $('#' + id).datetimepicker({ closeOnDateSelect: true, - format: 'Y-m-d H:i:s', + format: 'Y-m-d H:i', scrollInput:false, i18n: { lang: window.dateTimePickerTranslations @@ -113,7 +113,7 @@ function initDateTimeChooser(id) { }); } else { $('#' + id).datetimepicker({ - format: 'Y-m-d H:i:s', + format: 'Y-m-d H:i', }); } } diff --git a/wagtail/wagtailadmin/widgets.py b/wagtail/wagtailadmin/widgets.py index 6a2f146b4..19c35a7e0 100644 --- a/wagtail/wagtailadmin/widgets.py +++ b/wagtail/wagtailadmin/widgets.py @@ -28,16 +28,28 @@ class AdminAutoHeightTextInput(WidgetWithScript, widgets.Textarea): return '$("#{0}").autosize();'.format(id_) class AdminDateInput(WidgetWithScript, widgets.DateInput): + # Set a default date format to match the one that our JS date picker expects - + # it can still be overridden explicitly, but this way it won't be affected by + # the DATE_INPUT_FORMATS setting + def __init__(self, attrs=None, format='%Y-%m-%d'): + super(AdminDateInput, self).__init__(attrs=attrs, format=format) + def render_js_init(self, id_, name, value): return 'initDateChooser({0});'.format(json.dumps(id_)) class AdminTimeInput(WidgetWithScript, widgets.TimeInput): + def __init__(self, attrs=None, format='%H:%M'): + super(AdminTimeInput, self).__init__(attrs=attrs, format=format) + def render_js_init(self, id_, name, value): return 'initTimeChooser({0});'.format(json.dumps(id_)) class AdminDateTimeInput(WidgetWithScript, widgets.DateTimeInput): + def __init__(self, attrs=None, format='%Y-%m-%d %H:%M'): + super(AdminDateTimeInput, self).__init__(attrs=attrs, format=format) + def render_js_init(self, id_, name, value): return 'initDateTimeChooser({0});'.format(json.dumps(id_)) diff --git a/wagtail/wagtailcore/migrations/0011_update_golive_expire_help_text.py b/wagtail/wagtailcore/migrations/0011_update_golive_expire_help_text.py new file mode 100644 index 000000000..b16ed85f1 --- /dev/null +++ b/wagtail/wagtailcore/migrations/0011_update_golive_expire_help_text.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailcore', '0010_change_page_owner_to_null_on_delete'), + ] + + operations = [ + migrations.AlterField( + model_name='page', + name='expire_at', + field=models.DateTimeField(help_text='Please add a date-time in the form YYYY-MM-DD hh:mm.', null=True, verbose_name='Expiry date/time', blank=True), + preserve_default=True, + ), + migrations.AlterField( + model_name='page', + name='go_live_at', + field=models.DateTimeField(help_text='Please add a date-time in the form YYYY-MM-DD hh:mm.', null=True, verbose_name='Go live date/time', blank=True), + preserve_default=True, + ), + ] diff --git a/wagtail/wagtailcore/models.py b/wagtail/wagtailcore/models.py index a761be828..7889a5b57 100644 --- a/wagtail/wagtailcore/models.py +++ b/wagtail/wagtailcore/models.py @@ -278,8 +278,8 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed show_in_menus = models.BooleanField(default=False, help_text=_("Whether a link to this page will appear in automatically generated menus")) search_description = models.TextField(blank=True) - go_live_at = models.DateTimeField(verbose_name=_("Go live date/time"), help_text=_("Please add a date-time in the form YYYY-MM-DD hh:mm:ss."), blank=True, null=True) - expire_at = models.DateTimeField(verbose_name=_("Expiry date/time"), help_text=_("Please add a date-time in the form YYYY-MM-DD hh:mm:ss."), blank=True, null=True) + go_live_at = models.DateTimeField(verbose_name=_("Go live date/time"), help_text=_("Please add a date-time in the form YYYY-MM-DD hh:mm."), blank=True, null=True) + expire_at = models.DateTimeField(verbose_name=_("Expiry date/time"), help_text=_("Please add a date-time in the form YYYY-MM-DD hh:mm."), blank=True, null=True) expired = models.BooleanField(default=False, editable=False) locked = models.BooleanField(default=False, editable=False) From 3d705dc43d6f666183a7606671a8b7ddf30c3c22 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Thu, 19 Mar 2015 11:37:14 +0000 Subject: [PATCH 2/3] renumber migration --- ...pire_help_text.py => 0013_update_golive_expire_help_text.py} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename wagtail/wagtailcore/migrations/{0011_update_golive_expire_help_text.py => 0013_update_golive_expire_help_text.py} (92%) diff --git a/wagtail/wagtailcore/migrations/0011_update_golive_expire_help_text.py b/wagtail/wagtailcore/migrations/0013_update_golive_expire_help_text.py similarity index 92% rename from wagtail/wagtailcore/migrations/0011_update_golive_expire_help_text.py rename to wagtail/wagtailcore/migrations/0013_update_golive_expire_help_text.py index b16ed85f1..dea1ca318 100644 --- a/wagtail/wagtailcore/migrations/0011_update_golive_expire_help_text.py +++ b/wagtail/wagtailcore/migrations/0013_update_golive_expire_help_text.py @@ -7,7 +7,7 @@ from django.db import models, migrations class Migration(migrations.Migration): dependencies = [ - ('wagtailcore', '0010_change_page_owner_to_null_on_delete'), + ('wagtailcore', '0012_extend_page_slug_field'), ] operations = [ From 8e3ea58b25dda4e22acbc09d60095746773a5a97 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Thu, 19 Mar 2015 11:53:43 +0000 Subject: [PATCH 3/3] release note for #1018 --- CHANGELOG.txt | 1 + docs/releases/0.9.rst | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index e05cd9045..12b8febd7 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -34,6 +34,7 @@ Changelog * The Page model now records the date/time that a page was first published, as the field `first_published_at` * Increased the maximum length of a page slug from 50 to 255 characters * Plain text fields in the page editor now use auto-expanding text areas + * Date / time pickers now consistently use times without seconds, to prevent Javascript behaviour glitches when focusing / unfocusing fields 0.8.6 (10.03.2015) diff --git a/docs/releases/0.9.rst b/docs/releases/0.9.rst index 58898fa3b..1274cf428 100644 --- a/docs/releases/0.9.rst +++ b/docs/releases/0.9.rst @@ -63,6 +63,7 @@ Admin * Removed the need to add permission check on admin views (now automated) * Reversing ``django.contrib.auth.admin.login`` will no longer lead to Wagtails login view (making it easier to have front end views) * Added cache-control headers to all admin views. This allows Varnish/Squid/CDN to run on vanilla settings in front of a Wagtail site + * Date / time pickers now consistently use times without seconds, to prevent Javascript behaviour glitches when focusing / unfocusing fields Project template