Possible bug in Django Admin site in tabular inline or stacked inline with datetime shortcuts

148 views
Skip to first unread message

Константин Попов

unread,
Apr 19, 2016, 8:02:30 AM4/19/16
to Django users
Hi, django users.

I have found possible bug in django admin site, using tabular inline with datetime field. The same bug exists in stacked inline as I can see form code.

I am not sure what is the best way to report the bug, so I decided to write here first.
Please, give me advice on my next steps.

Now, about the bug.

Any datetime field is supplied with calendar and clock shortcuts. static/admin/js/admin/DateTimeShortcuts.js contains code, wich generated all html markup for them, this code runs on page load event.
This code makes both span class="datetimeshortcuts" and hidden div class="calendarbox module" or class="clockbox module".

TabularFormset and stackedFormset jquery plugins, that live in static/admin/js/inlines.js, both need to reinit datetime fields in the newly added formset rows.
They do it with this function:

var reinitDateTimeShortCuts = function() {
            // Reinitialize the calendar and clock widgets by force, yuck.
            if (typeof DateTimeShortcuts !== "undefined") {
                $(".datetimeshortcuts").remove();
                DateTimeShortcuts.init();
            } 
        };

As anyone can see, this function removes datetimeshortcuts spans but doesn't remove "calendarbox module" and clockbox module" divs.
Then, call to the DateTimeShortcuts.init() again and again adds both the spans and the divs for all datetime fields on the page.

Thus, by adding 20 rows in formset, I have about 400 useless hidden divs on my page.


I see several ways to fix this bug.

1. Modify DateTimeShortcuts.js to use single hidden div for all datetime fields on the page
2. Modify DateTimeShortcuts.js init function to check if the datetime field is alreay initialized to avoid it's re-initialization, and exclude removing any DOM elements from reinitDateTimeShortCuts 
3. Expand set of elements, removed in reinitDateTimeShortCuts and remove divs together with spans. Maybe it would be better to add reinit function into DateTimeShortcuts.js

Константин Попов

unread,
Apr 25, 2016, 4:52:12 AM4/25/16
to Django users
If anyone is interested in this question, I have fixed this myself, with approach number 2.
I had to copy two js files from django to my project and then fix that files.

вторник, 19 апреля 2016 г., 15:02:30 UTC+3 пользователь Константин Попов написал:
Reply all
Reply to author
Forward
0 new messages