Re: [Django] #35314: Django 5 breaks value of Date field rendering correctly in template
#35314: Django 5 breaks value of Date field rendering correctly in template ---+-- Reporter: Michael|Owner: nobody Type: Bug| Status: closed Component: Forms | Version: 5.0 Severity: Normal | Resolution: duplicate Keywords: form date | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 |UI/UX: 0 ---+-- Comment (by Michael): Replying to [comment:8 Natalia Bidart]: > Replying to [comment:7 Michael]: > > Seems a bit counter intuitive to have a broken date input format by default. > > This feels a bit of a over statement, since Django does not support (yet) `type="date"` input (see #21470). Were you able to read the related issues I linked? This conversation is also quite relevant: https://groups.google.com/g/django-developers/c/wp-pnzcB25o/m/D5gEOzPIAQAJ Sorry, I should have toned it down and said the value being passed into the date widgets is what doesn't work. The pattern that Django forms has is quite a close relationship with HTML widgets. It's arguabley unexpected the way that the `DateInput` is not an HTML ``. Thank you for linking those conversations, sorry by the time I had answered the question I forgot there were linked issues (kids handing off arms/legs/calling for dinner time) and I lost track. Will checkout the issues thanks! -- Ticket URL: <https://code.djangoproject.com/ticket/35314#comment:9> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018e5350277a-7ddcfb11-c645-45ef-8ff1-584dbcbc8fff-00%40eu-central-1.amazonses.com.
Re: [Django] #35314: Django 5 breaks value of Date field rendering correctly in template
#35314: Django 5 breaks value of Date field rendering correctly in template ---+-- Reporter: Michael|Owner: nobody Type: Bug| Status: closed Component: Forms | Version: 5.0 Severity: Normal | Resolution: duplicate Keywords: form date | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 |UI/UX: 0 ---+-- Comment (by Natalia Bidart): Replying to [comment:7 Michael]: > Seems a bit counter intuitive to have a broken date input format by default. This feels a bit of a over statement, since Django does not support (yet) `type="date"` input (see #21470). Were you able to read the related issues I linked? This conversation is also quite relevant: https://groups.google.com/g/django-developers/c/wp-pnzcB25o/m/D5gEOzPIAQAJ -- Ticket URL: <https://code.djangoproject.com/ticket/35314#comment:8> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018e52f5aa76-adf9926b-e6df-4922-9c27-eeac0f06ff4c-00%40eu-central-1.amazonses.com.
Re: [Django] #35314: Django 5 breaks value of Date field rendering correctly in template
#35314: Django 5 breaks value of Date field rendering correctly in template ---+-- Reporter: Michael|Owner: nobody Type: Bug| Status: closed Component: Forms | Version: 5.0 Severity: Normal | Resolution: duplicate Keywords: form date | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 |UI/UX: 0 ---+-- Comment (by Michael): Hi Natalia, thanks for the comment, I am using it like this (which used to work in Django 4): {{{ class FooForm(forms.ModelForm): class Meta: model = Foo exclude = [...] widgets = { `'bar_date': forms.DateInput(attrs={'type':'date'}),` } }}} But I made the following changes to do it working: `'bar_date': forms.DateInput(format='%Y-%m-%d', attrs={'type':'date'}),` Seems a bit counter intuitive to have a broken date input format by default. -- Ticket URL: <https://code.djangoproject.com/ticket/35314#comment:7> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018e52bec407-ff6f664c-7c3f-488a-abcb-c230327276cd-00%40eu-central-1.amazonses.com.
Re: [Django] #35314: Django 5 breaks value of Date field rendering correctly in template
#35314: Django 5 breaks value of Date field rendering correctly in template ---+-- Reporter: Michael|Owner: nobody Type: Bug| Status: closed Component: Forms | Version: 5.0 Severity: Normal | Resolution: duplicate Keywords: form date | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 |UI/UX: 0 ---+-- Comment (by Natalia Bidart): Hey Michael, in one of your comments, you describe your field as: ``. But Django doesn't use `type="date"` by default (see as further reference #35293, #34853, #34660, #33113 and more). How are you generating this field? -- Ticket URL: <https://code.djangoproject.com/ticket/35314#comment:6> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018e526a0ff8-af460f35-8d45-4203-86d7-10615acd2762-00%40eu-central-1.amazonses.com.
Re: [Django] #35314: Django 5 breaks value of Date field rendering correctly in template
#35314: Django 5 breaks value of Date field rendering correctly in template ---+-- Reporter: Michael|Owner: nobody Type: Bug| Status: closed Component: Forms | Version: 5.0 Severity: Normal | Resolution: duplicate Keywords: form date | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 |UI/UX: 0 ---+-- Comment (by Michael): Replying to [comment:4 David Sanders]: > Yep you need to read the full comment: > > > Have you tried setting the DATE_FORMAT in your custom language format file as per: https://docs.djangoproject.com/en/5.0/topics/i18n/formatting /#creating-custom-format-files ? > > whereas you're using settings Thanks for the elaborating so I can try see it from your perspective. I can set a custom language format file, but surely when it comes to the HTML date value on forms, it should not depend on the language code, it should *always* be `/MM/DD`, anything else is invalid. So is it not a bug to make it depend on a custom format language code? -- Ticket URL: <https://code.djangoproject.com/ticket/35314#comment:5> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018e52014547-ffc98ca1-0f57-4962-a7f0-6ea68cc3e518-00%40eu-central-1.amazonses.com.
Re: [Django] #35314: Django 5 breaks value of Date field rendering correctly in template
#35314: Django 5 breaks value of Date field rendering correctly in template ---+-- Reporter: Michael|Owner: nobody Type: Bug| Status: closed Component: Forms | Version: 5.0 Severity: Normal | Resolution: duplicate Keywords: form date | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 |UI/UX: 0 ---+-- Comment (by David Sanders): Yep you need to read the full comment: > Have you tried setting the DATE_FORMAT in your custom language format file as per: https://docs.djangoproject.com/en/5.0/topics/i18n/formatting /#creating-custom-format-files ? whereas you're using settings -- Ticket URL: <https://code.djangoproject.com/ticket/35314#comment:4> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018e51fd3fb8-9cc84a42-24c7-4b6b-a869-469256752bb0-00%40eu-central-1.amazonses.com.
Re: [Django] #35314: Django 5 breaks value of Date field rendering correctly in template
#35314: Django 5 breaks value of Date field rendering correctly in template ---+-- Reporter: Michael|Owner: nobody Type: Bug| Status: closed Component: Forms | Version: 5.0 Severity: Normal | Resolution: duplicate Keywords: form date | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 |UI/UX: 0 ---+-- Comment (by Michael): In #35255 the author recommends passing in the value of `settings.USE_L10N` ... which is deprecated. And in the thread you then recommend setting `DATE_FORMAT`, as mentioned above I have set `DATE_INPUT_FORMATS`, and they are not used. Would you please care to explain why this issue is invalid? -- Ticket URL: <https://code.djangoproject.com/ticket/35314#comment:3> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018e51ee0e3a-0e6c6944-d34d-43ac-8b18-186e15c4d1ed-00%40eu-central-1.amazonses.com.
Re: [Django] #35314: Django 5 breaks value of Date field rendering correctly in template
#35314: Django 5 breaks value of Date field rendering correctly in template ---+-- Reporter: Michael|Owner: nobody Type: Bug| Status: closed Component: Forms | Version: 5.0 Severity: Normal | Resolution: duplicate Keywords: form date | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 |UI/UX: 0 ---+-- Changes (by David Sanders): * resolution: => duplicate * status: new => closed Comment: Duplicate of 35255 -- Ticket URL: <https://code.djangoproject.com/ticket/35314#comment:2> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018e51e0464b-3e68ea73-0b53-46cb-9f09-30ede89f3885-00%40eu-central-1.amazonses.com.
Re: [Django] #35314: Django 5 breaks value of Date field rendering correctly in template
#35314: Django 5 breaks value of Date field rendering correctly in template ---+-- Reporter: Michael|Owner: nobody Type: Bug| Status: new Component: Forms | Version: 5.0 Severity: Normal | Resolution: Keywords: form date | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 |UI/UX: 0 ---+-- Description changed by Michael: Old description: > This used to work correctly in Django 4. Django 5 removed USE_L10N > setting from settings.py > > When rendering an input field that is of type date: > {{{ > /home/michael/.venv/project/lib/python3.11/site- > packages/django/forms/boundfield.py(108)as_widget() > -> return widget.render( > /home/michael/.venv/project/lib/python3.11/site- > packages/django/forms/widgets.py(279)render() > -> context = self.get_context(name, value, attrs) > /home/michael/.venv/project/lib/python3.11/site- > packages/django/forms/widgets.py(332)get_context() > -> context = super().get_context(name, value, attrs) > /home/michael/.venv/project/lib/python3.11/site- > packages/django/forms/widgets.py(271)get_context() > -> "value": self.format_value(value), > /home/michael/.venv/project/lib/python3.11/site- > packages/django/forms/widgets.py(555)format_value() > -> value, self.format or formats.get_format(self.format_key)[0] > }}} > > We that ` formats.get_format(self.format_key)` only passes in 1 argument > to: > > {{{ > # django/utils/formats.py(109)get_format() > > def get_format(format_type, lang=None, use_l10n=None): > """ > For a specific format type, return the format for the current > language (locale). Default to the format in the settings. > format_type is the name of the format, e.g. 'DATE_FORMAT'. > > If use_l10n is provided and is not None, it forces the value to > be localized (or not), otherwise it's always localized. > """ > if use_l10n is None: > use_l10n = True > if use_l10n and lang is None: > lang = get_language() > format_type = str(format_type) # format_type may be lazy. > cache_key = (format_type, lang) > try: > return _format_cache[cache_key] > except KeyError: > pass > }}} > > this means use_l10n initial value is `None`, which means it will be set > to True via the logic: > {{{ > if use_l10n is None: > use_l10n = True > }}} > > So then it sets a language, in my case `en-gb`, which makes results in a > `cache_key` of `('DATE_INPUT_FORMATS', 'en-gb')` > > Which means the `get_format` method returns `['%d/%m/%Y', '%d/%m/%y', > '%Y-%m-%d']` > Which is really bad when `format_type = 'DATE_INPUT_FORMATS'`, because > HTML inputs must always be in the format `/MM/DD`, and hence > selecting the first format of `%d/%m/%Y` results in an error in your HTML > template when your input is rendered like ` value="31/12/2024">` instead of `` > > Not that it changes anything, but here is my `DATE_INPUT_FORMATS` from > settings.py (it has no `USE_L10N` setting as unfortunately that has been > removed): > {{{ > DATE_INPUT_FORMATS = [ > '%Y-%m-%d', > ] > }}} New description: This used to work correctly in Django 4. Django 5 removed USE_L10N setting from settings.py When rendering an input field that is of type `date`: {{{ /home/michael/.venv/project/lib/python3.11/site- packages/django/forms/boundfield.py(108)as_widget() -> return widget.render( /home/michael/.venv/project/lib/python3.11/site- packages/django/forms/widgets.py(279)render() -> context = self.get_context(name, value, attrs) /home/michael/.venv/project/lib/python3.11/site- packages/django/forms/widgets.py(332)get_context() -> context = super().get_context(name, value, attrs) /home/michael/.venv/project/lib/python3.11/site- packages/django/forms/widgets.py(271)get_context() -> "value": self.format_value(value), /home/michael/.venv/project/lib/python3.11/site- packages/django/forms/widgets.py(555)format_value() -> value, self.format or formats.get_format(self.format_key)[0] }}} We see that ` formats.get_format(self.format_key)` only passes in 1 argument to: {{{ # django/utils/formats.py(109)get_format() def get_format(format_type, lang=None, use_l10n=None): """ For a specific format type, return the format for the current language (locale
[Django] #35314: Django 5 breaks value of Date field rendering correctly in template
#35314: Django 5 breaks value of Date field rendering correctly in template --+--- Reporter: Michael | Owner: nobody Type: Bug | Status: new Component: Forms |Version: 5.0 Severity: Normal | Keywords: form date Triage Stage: Unreviewed | Has patch: 0 Needs documentation: 0 |Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | --+--- This used to work correctly in Django 4. Django 5 removed USE_L10N setting from settings.py When rendering an input field that is of type date: {{{ /home/michael/.venv/project/lib/python3.11/site- packages/django/forms/boundfield.py(108)as_widget() -> return widget.render( /home/michael/.venv/project/lib/python3.11/site- packages/django/forms/widgets.py(279)render() -> context = self.get_context(name, value, attrs) /home/michael/.venv/project/lib/python3.11/site- packages/django/forms/widgets.py(332)get_context() -> context = super().get_context(name, value, attrs) /home/michael/.venv/project/lib/python3.11/site- packages/django/forms/widgets.py(271)get_context() -> "value": self.format_value(value), /home/michael/.venv/project/lib/python3.11/site- packages/django/forms/widgets.py(555)format_value() -> value, self.format or formats.get_format(self.format_key)[0] }}} We that ` formats.get_format(self.format_key)` only passes in 1 argument to: {{{ # django/utils/formats.py(109)get_format() def get_format(format_type, lang=None, use_l10n=None): """ For a specific format type, return the format for the current language (locale). Default to the format in the settings. format_type is the name of the format, e.g. 'DATE_FORMAT'. If use_l10n is provided and is not None, it forces the value to be localized (or not), otherwise it's always localized. """ if use_l10n is None: use_l10n = True if use_l10n and lang is None: lang = get_language() format_type = str(format_type) # format_type may be lazy. cache_key = (format_type, lang) try: return _format_cache[cache_key] except KeyError: pass }}} this means use_l10n initial value is `None`, which means it will be set to True via the logic: {{{ if use_l10n is None: use_l10n = True }}} So then it sets a language, in my case `en-gb`, which makes results in a `cache_key` of `('DATE_INPUT_FORMATS', 'en-gb')` Which means the `get_format` method returns `['%d/%m/%Y', '%d/%m/%y', '%Y-%m-%d']` Which is really bad when `format_type = 'DATE_INPUT_FORMATS'`, because HTML inputs must always be in the format `/MM/DD`, and hence selecting the first format of `%d/%m/%Y` results in an error in your HTML template when your input is rendered like `` instead of `` Not that it changes anything, but here is my `DATE_INPUT_FORMATS` from settings.py (it has no `USE_L10N` setting as unfortunately that has been removed): {{{ DATE_INPUT_FORMATS = [ '%Y-%m-%d', ] }}} -- Ticket URL: <https://code.djangoproject.com/ticket/35314> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018e51da8688-d5dc3392-5448-49dc-b22e-20c7a5cdd919-00%40eu-central-1.amazonses.com.