Ticket #1061: calendar2.diff

File calendar2.diff, 5.0 KB (added by Jannis Leidel, 17 years ago)

Refactored patch for use with DateField, DateTimeField and TimeField, please patch a fresh checkout

  • django/conf/global_settings.py

     
    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

     
    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

     
    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

     
     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/views/main.py

     
    212212        'has_delete_permission': context['perms'][app_label][opts.get_delete_permission()],
    213213        'has_change_permission': context['perms'][app_label][opts.get_change_permission()],
    214214        'has_file_field': opts.has_field_type(models.FileField),
     215        'has_date_field': opts.has_field_type(models.DateTimeField) or opts.has_field_type(models.TimeField) or opts.has_field_type(models.DateField),
    215216        'has_absolute_url': hasattr(model, 'get_absolute_url'),
    216217        'auto_populated_fields': auto_populated_fields,
    217218        'bound_field_sets': bound_field_sets,
  • django/contrib/admin/templates/admin/change_form.html

     
    6464   {% auto_populated_field_script auto_populated_fields change %}
    6565   </script>
    6666{% endif %}
     67{% if has_date_field %}{% load admincalendar %}
     68<script type="text/javascript">
     69    week_start_day = {% admin_week_start %};
     70    addEvent(window, 'load', DateTimeShortcuts.init);
     71</script>
     72{% endif %}
    6773</div>
    6874</form></div>
    6975{% endblock %}
  • docs/settings.txt

     
    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
Back to Top