Self hosted FLOSS fitness/workout, nutrition and weight tracker
Format date for html5 datepickers
Roland Geidercbe745e4f1e0
diff --git a/docs/changelog.rst b/docs/changelog.rstindex f058794ba..4ef1ca9c7 100644--- a/docs/changelog.rst+++ b/docs/changelog.rst@@ -35,7 +35,7 @@ Upgrade steps from 1.9:🐛 Bug Fixes:* `#426`_ (thanks `@austin-leung`_), `#499`_, `#505`_, `#504`_, `#511`_, `#516`_,- `#522`_, `#554`_ and `#560`_ (thanks `@sandilsranasinghe`_), `#564`_+ `#522`_, `#554`_ and `#560`_ (thanks `@sandilsranasinghe`_), `#564`_, `#565`_🧰 Maintenance:@@ -81,6 +81,7 @@ Upgrade steps from 1.9:.. _#555: https://github.com/wger-project/wger/issues/555.. _#560: https://github.com/wger-project/wger/issues/560.. _#564: https://github.com/wger-project/wger/issues/564+.. _#565: https://github.com/wger-project/wger/issues/565diff --git a/wger/core/templates/forms/html5_date.html b/wger/core/templates/forms/html5_date.htmlnew file mode 100644index 000000000..8aa34c93a--- /dev/null+++ b/wger/core/templates/forms/html5_date.html@@ -0,0 +1 @@+<input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.orig_value|date:'Y-m-d' }}"{% endif %}{% include "django/forms/widgets/attrs.html" %}>diff --git a/wger/utils/widgets.py b/wger/utils/widgets.pyindex 1c2e1177e..f522df4ac 100644--- a/wger/utils/widgets.py+++ b/wger/utils/widgets.py@@ -49,11 +49,19 @@ logger = logging.getLogger(__name__)class Html5DateInput(DateInput):"""Custom Input class that is rendered with an HTML5 type="date"-- This is specially useful in mobile devices"""+ template_name = 'forms/html5_date.html'input_type = 'date'+ def get_context(self, name, value, attrs):+ """Pass the value as a date to the template. This is necessary because+ django's default behaviour is to convert it to a string, where it can't+ be formatted anymore."""++ context = super(Html5DateInput, self).get_context(name, value, attrs)+ context['widget']['orig_value'] = value+ return context+class Html5FormDateField(fields.DateField):"""