#15231: Admin DateTimeShortcuts + Inlines performance
----------------------------------+-----------------------------------------
 Reporter:  fabianbuechler        |          Owner:  nobody    
   Status:  new                   |      Milestone:            
Component:  django.contrib.admin  |        Version:  SVN       
 Keywords:                        |   Triage Stage:  Unreviewed
Has patch:  1                     |  
----------------------------------+-----------------------------------------
 In the admin, stacked or tabular inlines reinitialize the
 DateTimeShortcuts widgets for date or time fields whenever an inline
 row/form is added or removed.

 This has serious performance problems if your inline has a couple of
 date/time fields per row.
 About 95% of JS execution time is spent on the reinitialization of
 DateTimeShortcuts resulting in continious JS timeouts in even the most
 modern browsers.

 A couple of days ago I've offered to fix this in the django-devleopers
 list:
 http://groups.google.com/group/django-
 developers/browse_thread/thread/ff460085a3bfb12e/

 I've rewritten {{{admin/DateTimeShortcuts.js}}} and {{{calendar.js}}} and
 combinded them in a new {{{datetimeshortcuts.js}}} (+ minified version),
 which is jQuery based and uses 1.4.2 event delegation.
 This way, inlines do not need to reinitialize the DateTimeShortcuts
 widgets at all.


 The usage of the new datetimeshortcuts.js is as follows:

 By default, all {{{.fieldsets}}} are dts-enabled by the following call at
 the bottom of {{{datetimeshortcuts.js}}}
 {{{
   $("fieldset.module").datetimeshortcuts();
 }}}

 Users can use the plugin as well, for their own fields, specifing field
 selectors and enabling or disabling the today, calendar, now and clock
 widgets separately:
 {{{
   $('my-selector').datetimeshortcuts({
       date_fields: "input:text.date_from, input:text.date_to",
       time_fields: "input:text.time_from, input:text.time_to",
       enable_calendar: true,
       enable_today: true,
       enable_clock: false,
       enable_now: false
   });
 }}}

 In the admin's {{{base.html}}}, I've defined a basic set of options for
 DateTimeShortcuts, which override the default options of
 {{{datetimeshortcuts.js}}}:
 {{{
   $('body').data('datetimeshortcuts_defaults', {
       enable_calendar: true,
       enable_today: true,
       enable_clock: true,
       enable_now: true
   });
 }}}
 It would be great to add a variable to Django's settings to define these
 in your {{{settings.py}}} and include the values via a template tag in the
 {{{base.html}}}.
 I don't know if you are willing to do this, so I didn't prepare it for
 this patch.

 A patch is ready and attached.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/15231>
Django <http://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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to