Login

More admin clock time increments

Author:
robharvey
Posted:
April 17, 2007
Language:
JavaScript
Version:
Not specified
Tags:
admin time
Score:
2 (after 2 ratings)

This is quite a hack (need to modify Django code), but relatively simple and stable. It displays various times in whichever increments and columns you specify, rather than just Midnight, Noon, Now & 6am. You can use it throughout your admin and newforms-admin code.

This is a (slightly updated) copy of the ticket #1848 which wasn't included in trunk. http://code.djangoproject.com/ticket/1848

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
 Update contrib/admin/media/js/admin/DateTimeShortcuts addClock function, replace all "quickElement" lines with the following 
*/
        var interval_mins = 30; // minutes between displayed times
        var columns = 4;        // number of columns in popup
        var total_intervals = 24 * 60 / interval_mins;
        var time = new Date(0,0,0,0,0,0,0);
        var midnight = new Date(0,0,0,0,0,0,0); 
        var noon = new Date(0,0,0,12,0,0,0);
        for (var si=0; si<columns; si++) {
            time_list = quickElement('ul', clock_box, '');
            time_list.className = 'timelist';
            if (si == columns-1) {
                time_list.id = 'timelist-end';
            }
            var this_col_count = total_intervals / columns;
            for (var sj=0; sj<this_col_count; sj++) {
                var time_text = null;
                if (time.getTime() == midnight.getTime())
                    time_text = gettext("Midnight");
                else if (time.getTime() == noon.getTime())
                    time_text = gettext("Noon");
                else {
                    var hours = time.getHours();
                    hours = hours > 12 ? hours - 12 : hours;
                    time_text = "" + (hours == 0 ? 12 : hours);
                    var mins = time.getMinutes();
                    time_text += ":" + (mins > 9 ? "" : "0") + mins;
                    time_text += (hours >= 12 ? " PM" : " AM");
                } 
                quickElement("a", quickElement("li", time_list, ""), time_text, "href", "javascript:DateTimeShortcuts.handleClockQuicklink(" + num + ", '" + time.getHourMinute() + "');");
                time = new Date(time.getTime() + (interval_mins * 60 * 1000)); // interval * seconds in a minute * millis in second
            }
        }

More like this

  1. Increment a variable in a Template by sachingupta006 4 years, 5 months ago
  2. Django Incremental Counter Tag by gwrtheyrn 4 years, 9 months ago
  3. More informative error mailings by kcarnold 8 years, 5 months ago
  4. SelectTimeWidget by bradmontgomery 7 years, 9 months ago
  5. Hidden Date Display Widget for Admin by andrew.schoen 7 years, 1 month ago

Comments

robharvey (on April 17, 2007):
<p>CSS changes required to support columns:</p> <pre>.clockbox { width: 25em; } .clockbox h2 { text-align: center; } ul.timelist { float: left; padding-right: 5px; padding-left: 5px; border-right: 1px solid lightblue; } ul.timelist a:visited { color: black; } ul#timelist-end { float: none; } </pre>

#

Please login first before commenting.