Django

Code

Ticket #1061: calendar.diff

File calendar.diff, 4.2 kB (added by jezdez, 7 months ago)

Implemented WEEK_START_DAY and a little change to the calendar javascript code

  • django/conf/global_settings.py

    old new  
    244244# http://www.djangoproject.com/documentation/templates/#now 
    245245MONTH_DAY_FORMAT = 'F j' 
    246246 
     247# Default number of the first day of the week, starting sunday. 
     248# 0 = Sunday, 1 = Monday, 2 = Tuesday etc. 
     249WEEK_START_DAY = 0 
     250 
    247251# Do you want to manage transactions manually? 
    248252# Hint: you really don't! 
    249253TRANSACTIONS_MANAGED = False 
  • django/contrib/admin/media/js/calendar.js

    old new  
    5555 
    5656        // Draw days-of-week header 
    5757        var tableRow = quickElement('tr', tableBody); 
    58         for (var i = 0; i < 7; i++) { 
    59             quickElement('th', tableRow, CalendarNamespace.daysOfWeek[i]); 
     58        for (var i = week_start_day; i < week_start_day+7; i++) { 
     59            if (i < 7) { 
     60                dayIndex = i; 
     61            } else { 
     62                dayIndex = i - 7; 
     63            } 
     64            quickElement('th', tableRow, CalendarNamespace.daysOfWeek[dayIndex]); 
    6065        } 
    6166 
    62         var startingPos = new Date(year, month-1, 1).getDay(); 
     67        var startingPos = new Date(year, month-1, 1-week_start_day).getDay(); 
    6368        var days = CalendarNamespace.getDaysInMonth(month, year); 
    6469 
    6570        // Draw blanks before first of month 
  • django/contrib/admin/media/js/admin/DateTimeShortcuts.js

    old new  
    1313    clockLinkName: 'clocklink',      // name of the link that is used to toggle 
    1414    admin_media_prefix: '', 
    1515    init: function() { 
     16        week_start_day = week_start_day%7; 
    1617        // Deduce admin_media_prefix by looking at the <script>s in the 
    1718        // current document and finding the URL of *this* module. 
    1819        var scripts = document.getElementsByTagName('script'); 
     
    250251        if (e.stopPropagation) e.stopPropagation(); 
    251252    } 
    252253} 
    253  
    254 addEvent(window, 'load', DateTimeShortcuts.init); 
  • django/contrib/admin/templatetags/admincalendar.py

    old new  
     1from django.template import Library 
     2 
     3register = Library() 
     4 
     5def admin_week_start(): 
     6    """ 
     7    Returns the integer contained in the setting WEEK_START_DAY. 
     8    """ 
     9    try: 
     10        from django.conf import settings 
     11    except ImportError: 
     12        return '' 
     13    return settings.WEEK_START_DAY 
     14admin_week_start = register.simple_tag(admin_week_start) 
  • django/contrib/admin/templates/widget/date_time.html

    old new  
    1 {% load i18n %} 
     1{% load i18n admincalendar %} 
    22<p class="datetime">  
    33   {% trans "Date:" %} {{ bound_field.form_fields.0 }}<br /> 
    44   {% trans "Time:" %} {{ bound_field.form_fields.1 }} 
    55</p> 
     6 
     7<script type="text/javascript"> 
     8    week_start_day = {% admin_week_start %}; 
     9    addEvent(window, 'load', DateTimeShortcuts.init); 
     10</script> 
  • docs/settings.txt

    old new  
    10251025set to ``False``, Django will make some optimizations so as not to load the 
    10261026internationalization machinery. 
    10271027 
     1028WEEK_START_DAY 
     1029-------------- 
     1030 
     1031Default: ``0`` 
     1032 
     1033An integer representing the first day of the week, where 0 is Sunday, 1 is 
     1034Monday, 2 is Tuesday, 3 is Wednesday, 4 is Thursday, 5 is Friday and 6 is 
     1035Saturday. This is used in the Django admin contrib app in DateTimeField and 
     1036DateField. 
     1037 
    10281038YEAR_MONTH_FORMAT 
    10291039----------------- 
    10301040