Repository: wagtail/wagtail

Issue:
Datetime picker for golive/expiry reverts to the current date when returning to the edit page
- Go to the edit form of a page that has previously had a go-live / expiry date set, and go to the Settings tab
- Note that the timestamp includes a 'seconds' part, in contrast to the datetime picker's own format which just uses 'HH:mm'
- Focus on the go-live field - the datetime picker opens up on today's date, presumably because it can't parse a timestamp with a seconds field
- Focus away from the go-live field - the field reverts to the current date/time, even though we haven't interacted with the datetime picker at all.



Discussion:

Resolving patch:
diff --git a/wagtail/wagtailadmin/widgets.py b/wagtail/wagtailadmin/widgets.py
--- a/wagtail/wagtailadmin/widgets.py
+++ b/wagtail/wagtailadmin/widgets.py
@@ -28,16 +28,28 @@ def render_js_init(self, id_, name, value):
         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/0013_update_golive_expire_help_text.py b/wagtail/wagtailcore/migrations/0013_update_golive_expire_help_text.py
new file mode 100644
--- /dev/null
+++ b/wagtail/wagtailcore/migrations/0013_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', '0012_extend_page_slug_field'),
+    ]
+
+    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
--- 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)


Test patch: