Date and time fields use browser-default selection widgets#4202
Conversation
We adopted this implementation: https://forum.djangoproject.com/t/possible-datetime-local-bug/9477/7 The utilities are in model_utils not utils/forms to keep model_utils from developing circular imports.
60c632a to
9fa0397
Compare
ajrbyers
left a comment
There was a problem hiding this comment.
Generally this is a very welcome change. I've added a couple of questions inline though.
| :param article_id: Article PK | ||
| :return: contextualised django template | ||
| """ | ||
| from submission import forms as submission_forms |
There was a problem hiding this comment.
Does having this import in the head cause a circular import?
There was a problem hiding this comment.
Yes I believe so. There is another function in this file that has the same import.
| ) | ||
| ) | ||
| else: | ||
| modal = 'pubdate' |
There was a problem hiding this comment.
Is this unset on purpose? When the form is invalid generally we'd want to open the modal again.
There was a problem hiding this comment.
Yeah I unset it because there is a general redirect that resets the view and keeps the modal = 'pubdate' from having any effect, and I didn't want to touch the redirect because I'd have to test all the other view branches:
| return orcid | ||
|
|
||
|
|
||
| class PubDateForm(forms.ModelForm): |
| </div> | ||
| </div> | ||
| </div> | ||
| {{ pub_date_form }} |
There was a problem hiding this comment.
Huh, that is wild. Firefox clears it in my inspector pane (after parsing the HTML) but I can see it when I inspect the source. Is this a Django default feature, or something we have configured? In any case, I've added the foundation filter.


This closes #4095 as documented in that issue. Also closes #4205
The pub date selector was the only date+time combination:
In adding the form for selecting a pub date, I fixed up the confirmation message a bit so that it is crystal clear even with a timezone difference:
To make the datetime picker work, I used a custom model field as documented on the Django forum as discussed.
But as a side effect, an error is thrown when saving the model in the admin. (Change the Article admin back to
admin.ModelAdminto see the error.) To handle this I created an override to use the same widget in the admin. It is a bit ugly:If we don't like this we can simply drop the ModelField and use the custom FormField or widget independently.