티스토리 수익 글 보기
Navigation Menu
-
-
Notifications
You must be signed in to change notification settings - Fork 33k
Refs #29822 — Improved date, time and datetime HTML inputs #15806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Hello @dennybiasiolli! Thank you for your contribution 💪 As it’s your first contribution be sure to check out the patch review checklist. If you’re fixing a ticket from Trac make sure to set the “Has patch” flag and include a link to this PR in the ticket! If you have any design or process questions then you can ask in the Django forum. Welcome aboard ⛵️! |
bc2d7ff
to
822a834
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @dennybiasiolli —
(Initial comment)
OK, so as you said on the mailing list backward-compatibility is the first thing that jumps out. Maybe it’s just better™ and folks should migrate, but have you thought at all about an opt-in or opt-out, and a migration/deprecation path? 🤔 (These thoughts would go towards release notes as well.)
What are the consequences if the admin is for instance set to german and my browser is set to english? I think it would be great to add a table here to show the current behavior and the new behaviors and possible issues. |
Oh you are right, I didn’t think about that.
|
In this case, you will se the the HTML input in the browser’s language, but the date/datetime used to pass data to the python code is the same il all cases, the ISO8601 format: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date |
Ok, let me push another commit (basically rolling back almost everything) adding opt-in admin widgets. They can be configured in ModelAdmin classes like this from django.contrib import admin
from django.contrib.admin import widgets
from django.db import models
@admin.register(MyCustom)
class MyCustomAdmin(admin.ModelAdmin):
formfield_overrides = {
models.DateField: { 'widget': widgets.AdminDateISOWidget },
models.TimeField: { 'widget': widgets.AdminTimeISOWidget },
models.DateTimeField: {
'widget': widgets.AdminDateTimeISOWidget,
'form_class': None,
},
} |
Thanks @dennybiasiolli. That sounds a good plan. I will have a proper look next week and we’ll see about the best way forwards! |
@carltongibson thanks! Meanwhile I will add a few more tests for the code I added |
26c56ce
to
2354502
Compare
3d6e8a7
to
20f0f66
Compare
Should these widgets be enabled by default? I think that everyone would appreciate seeing time fields converted to local time on their browser. Plus: If a datetime field has editable=False, the django admin doesn’t display the “You are x hours behind/ahead of server time”, which is confusing and a bit ugly. If you enable this widget by default, it would solve that issue too. |
@ldeluigi at the moment the widget is “just” using the standard html input types for date and times, not the local time. |
Should it be implemented with a new middleware that calls activate() using a session/cookie/HTTP header set by javascript, maybe at login? Or should it be javascript only, that shifts times, dates and datetimes before the user sees them, to local timezone? I don’t feel capable of such contribution given my lack of experience with Django |
@ldeluigi I think it can be something “javascript only”, so when in a template we have something with a specific class, or with a specific
We can do something like this (note: pseudo-code) const elems = document.getElementsByClassName('date-time');
for (let elem of elems) {
if (elem.dataset.isoFormat) {
elem.innerHTML = new Intl.DateTimeFormat().format(new Date()); // need to adjust this with options for date, time and datetime
}
} |
20f0f66
to
84d0417
Compare
Hi @dennybiasiolli, would you have time to keep working on this? Thank you! |
Yep, give me a couple of days and I will rebase and work on this |
Just flagging that from my perspective on Django’s accessibility team, I can’t recommend anyone use those input types. As much as I’d like to see projects adopting the native inputs, my understanding is that they’re close to completely unusable with the Dragon voice recognition software, which is by far the most popular speech recognition software in the world. For ref, see:
Those references are from 2019, 2021, and 2016 – so my preference if we wanted to proceed with this in Django would be to get help from a user of Dragon in our community, and have them report back with a recording + qualitative assessment of their experience going through the different widgets with the latest version of Dragon. Alternatively this is something @django/accessibility might be able to do if we got budget to pay for a Dragon license ($700). We’d then be able to make an informed decision on whether those input types are ready for use or not. See also similar research from other projects: |
84d0417
to
4adbb5c
Compare
Ok, branch rebased, I will wait for further decisions before working on this 😉 |
Thanks! Would you be willing to chase the accessibility aspect of this? I have started by prompting for help in the #accessibility Discord channel: https://discord.com/channels/856567261900832808/931568482489860137/1157367597185106062 It would be of great help if you could find someone to help you test the UI/UX aspect of this. |
I’m a Dragon user and a programmer who uses django, hit me up if you need me. |
Thank you @deborahgu! I’ll put together a prototype and then you can try it out, tell us about your experience and provide a recording if it works for you? |
sounds great! |
Hi @deborahgu ! Are you still open to give this a test run? |
hey, sorry, got behind on my email. I am open to it if you still need someone! |
yes please @deborahgu ! |
Hi @deborahgu! That would be great! Thanks for your offer!
|
Anything I can do to help this issue? I know there has been concerned about peoples code being broken by implementing it, but there are also people with forms that have already been broken by Django 4->5 by not having this, and are looking for a fix. |
Just for reference i would like to point to https://github.com/adamcharnock/django-tz-detect
|
Ref:
Changes: