Ticket #17255: asremoval.diff

File asremoval.diff, 13.4 KB (added by Jannis Leidel, 12 years ago)
  • django/contrib/admin/util.py

    diff --git a/django/contrib/admin/util.py b/django/contrib/admin/util.py
    index af8fad3..5511464 100644
    a b def display_for_field(value, field):  
    295295    elif value is None:
    296296        return EMPTY_CHANGELIST_VALUE
    297297    elif isinstance(field, models.DateTimeField):
    298         return formats.localize(timezone.aslocaltime(value))
     298        return formats.localize(timezone.localtime(value))
    299299    elif isinstance(field, models.DateField) or isinstance(field, models.TimeField):
    300300        return formats.localize(value)
    301301    elif isinstance(field, models.DecimalField):
  • django/template/base.py

    diff --git a/django/template/base.py b/django/template/base.py
    index 572ec61..40a577d 100644
    a b from django.utils.safestring import (SafeData, EscapeData, mark_safe,  
    1818from django.utils.formats import localize
    1919from django.utils.html import escape
    2020from django.utils.module_loading import module_has_submodule
    21 from django.utils.timezone import aslocaltime
     21from django.utils.timezone import localtime
    2222
    2323
    2424TOKEN_TEXT = 0
    class FilterExpression(object):  
    595595                else:
    596596                    arg_vals.append(arg.resolve(context))
    597597            if getattr(func, 'expects_localtime', False):
    598                 obj = aslocaltime(obj, context.use_tz)
     598                obj = localtime(obj, context.use_tz)
    599599            if getattr(func, 'needs_autoescape', False):
    600600                new_obj = func(obj, autoescape=context.autoescape, *arg_vals)
    601601            else:
    def _render_value_in_context(value, context):  
    856856    means escaping, if required, and conversion to a unicode object. If value
    857857    is a string, it is expected to have already been translated.
    858858    """
    859     value = aslocaltime(value, use_tz=context.use_tz)
     859    value = localtime(value, use_tz=context.use_tz)
    860860    value = localize(value, use_l10n=context.use_l10n)
    861861    value = force_unicode(value)
    862862    if ((context.autoescape and not isinstance(value, SafeData)) or
  • django/template/debug.py

    diff --git a/django/template/debug.py b/django/template/debug.py
    index d4b973b..74aa82b 100644
    a b from django.utils.encoding import force_unicode  
    33from django.utils.html import escape
    44from django.utils.safestring import SafeData, EscapeData
    55from django.utils.formats import localize
    6 from django.utils.timezone import aslocaltime
     6from django.utils.timezone import localtime
    77
    88
    99class DebugLexer(Lexer):
    class DebugVariableNode(VariableNode):  
    8282    def render(self, context):
    8383        try:
    8484            output = self.filter_expression.resolve(context)
    85             output = aslocaltime(output, use_tz=context.use_tz)
     85            output = localtime(output, use_tz=context.use_tz)
    8686            output = localize(output, use_l10n=context.use_l10n)
    8787            output = force_unicode(output)
    8888        except UnicodeDecodeError:
  • django/templatetags/tz.py

    diff --git a/django/templatetags/tz.py b/django/templatetags/tz.py
    index 14b613e..48c511f 100644
    a b from django.utils import timezone  
    1313
    1414register = Library()
    1515
     16
    1617# HACK: datetime is an old-style class, create a new-style equivalent
    1718# so we can define additional attributes.
    1819class datetimeobject(datetime, object):
    class datetimeobject(datetime, object):  
    2223# Template filters
    2324
    2425@register.filter
    25 def aslocaltime(value):
     26def localtime(value):
    2627    """
    2728    Converts a datetime to local time in the active time zone.
    2829
    2930    This only makes sense within a {% localtime off %} block.
    3031    """
    31     return astimezone(value, timezone.get_current_timezone())
     32    return do_timezone(value, timezone.get_current_timezone())
     33
    3234
    3335@register.filter
    34 def asutc(value):
     36def utc(value):
    3537    """
    3638    Converts a datetime to UTC.
    3739    """
    38     return astimezone(value, timezone.utc)
     40    return do_timezone(value, timezone.utc)
    3941
    40 @register.filter
    41 def astimezone(value, arg):
     42
     43@register.filter('timezone')
     44def do_timezone(value, arg):
    4245    """
    4346    Converts a datetime to local time in a given time zone.
    4447
    class LocalTimeNode(Node):  
    103106        context.use_tz = old_setting
    104107        return output
    105108
     109
    106110class TimezoneNode(Node):
    107111    """
    108112    Template node class used by ``timezone_tag``.
    class TimezoneNode(Node):  
    116120            output = self.nodelist.render(context)
    117121        return output
    118122
     123
    119124class GetCurrentTimezoneNode(Node):
    120125    """
    121126    Template node class used by ``get_current_timezone_tag``.
    class GetCurrentTimezoneNode(Node):  
    127132        context[self.variable] = timezone.get_current_timezone_name()
    128133        return ''
    129134
     135
    130136@register.tag('localtime')
    131137def localtime_tag(parser, token):
    132138    """
    def localtime_tag(parser, token):  
    142148    if len(bits) == 1:
    143149        use_tz = True
    144150    elif len(bits) > 2 or bits[1] not in ('on', 'off'):
    145         raise TemplateSyntaxError("%r argument should be 'on' or 'off'" % bits[0])
     151        raise TemplateSyntaxError("%r argument should be 'on' or 'off'" %
     152                                  bits[0])
    146153    else:
    147154        use_tz = bits[1] == 'on'
    148155    nodelist = parser.parse(('endlocaltime',))
    149156    parser.delete_first_token()
    150157    return LocalTimeNode(nodelist, use_tz)
    151158
     159
    152160@register.tag('timezone')
    153161def timezone_tag(parser, token):
    154162    """
    def timezone_tag(parser, token):  
    167175    """
    168176    bits = token.split_contents()
    169177    if len(bits) != 2:
    170         raise TemplateSyntaxError("'%s' takes one argument (timezone)" % bits[0])
     178        raise TemplateSyntaxError("'%s' takes one argument (timezone)" %
     179                                  bits[0])
    171180    tz = parser.compile_filter(bits[1])
    172181    nodelist = parser.parse(('endtimezone',))
    173182    parser.delete_first_token()
    174183    return TimezoneNode(nodelist, tz)
    175184
     185
    176186@register.tag("get_current_timezone")
    177187def get_current_timezone_tag(parser, token):
    178188    """
    def get_current_timezone_tag(parser, token):  
    187197    """
    188198    args = token.contents.split()
    189199    if len(args) != 3 or args[1] != 'as':
    190         raise TemplateSyntaxError("'get_current_timezone' requires 'as variable' (got %r)" % args)
     200        raise TemplateSyntaxError("'get_current_timezone' requires "
     201                                  "'as variable' (got %r)" % args)
    191202    return GetCurrentTimezoneNode(args[2])
  • django/utils/timezone.py

    diff --git a/django/utils/timezone.py b/django/utils/timezone.py
    index 22860eb..9e78134 100644
    a b from django.conf import settings  
    1717__all__ = [
    1818    'utc', 'get_default_timezone', 'get_current_timezone',
    1919    'activate', 'deactivate', 'override',
    20     'aslocaltime', 'isnaive',
     20    'localtime', 'isnaive',
    2121]
    2222
    2323
    class override(object):  
    198198
    199199# Utilities
    200200
    201 def aslocaltime(value, use_tz=None):
     201def localtime(value, use_tz=None):
    202202    """
    203203    Checks if value is a datetime and converts it to local time if necessary.
    204204
  • docs/ref/settings.txt

    diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt
    index 0d91f16..a35d99a 100644
    a b Otherwise, Django will use naive datetimes in local time.  
    21082108See also :setting:`TIME_ZONE`, :setting:`USE_I18N` and :setting:`USE_L10N`.
    21092109
    21102110.. note::
     2111
    21112112    The default :file:`settings.py` file created by
    21122113    :djadmin:`django-admin.py startproject <startproject>` includes
    21132114    ``USE_TZ = True`` for convenience.
  • docs/ref/utils.txt

    diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt
    index 9a9adba..2c0110f 100644
    a b For a complete discussion on the usage of the following see the  
    660660    ``None``, the :ref:`current time zone <default-current-time-zone>` is unset
    661661    on entry with :func:`deactivate()` instead.
    662662
    663 .. function:: aslocaltime(value, use_tz=None)
     663.. function:: localtime(value, use_tz=None)
    664664
    665665    This function is used by the template engine to convert datetimes to local
    666666    time where appropriate.
  • docs/topics/i18n/timezones.txt

    diff --git a/docs/topics/i18n/timezones.txt b/docs/topics/i18n/timezones.txt
    index 41e8380..18d30b9 100644
    a b These filters accept both aware and naive datetimes. For conversion purposes,  
    330330they assume that naive datetimes are in the default time zone. They always
    331331return aware datetimes.
    332332
    333 .. templatefilter:: aslocaltime
     333.. templatefilter:: localtime
    334334
    335 aslocaltime
    336 ~~~~~~~~~~~
     335localtime
     336~~~~~~~~~
    337337
    338338Forces conversion of a single value to the current time zone.
    339339
    For example::  
    341341
    342342    {% load tz %}
    343343
    344     {{ value|aslocaltime }}
     344    {{ value|localtime }}
    345345
    346 .. templatefilter:: asutc
     346.. templatefilter:: utc
    347347
    348 asutc
    349 ~~~~~
     348utc
     349~~~
    350350
    351351Forces conversion of a single value to UTC.
    352352
    For example::  
    354354
    355355    {% load tz %}
    356356
    357     {{ value|asutc }}
     357    {{ value|utc }}
    358358
    359 astimezone
    360 ~~~~~~~~~~
     359.. templatefilter:: timezone
     360
     361timezone
     362~~~~~~~~
    361363
    362364Forces conversion of a single value to an arbitrary timezone.
    363365
    For example::  
    368370
    369371    {% load tz %}
    370372
    371     {{ value|astimezone:"Europe/Paris" }}
     373    {{ value|timezone:"Europe/Paris" }}
    372374
    373375.. _time-zones-migration-guide:
    374376
  • tests/modeltests/timezones/tests.py

    diff --git a/tests/modeltests/timezones/tests.py b/tests/modeltests/timezones/tests.py
    index e33d4c6..547680c 100644
    a b class TemplateTests(BaseDateTimeTests):  
    537537            'naive': datetime.datetime(2011, 9, 1, 13, 20, 30),
    538538        }
    539539        templates = {
    540             'notag': Template("{% load tz %}{{ dt }}|{{ dt|aslocaltime }}|{{ dt|asutc }}|{{ dt|astimezone:ICT }}"),
    541             'noarg': Template("{% load tz %}{% localtime %}{{ dt }}|{{ dt|aslocaltime }}|{{ dt|asutc }}|{{ dt|astimezone:ICT }}{% endlocaltime %}"),
    542             'on':    Template("{% load tz %}{% localtime on %}{{ dt }}|{{ dt|aslocaltime }}|{{ dt|asutc }}|{{ dt|astimezone:ICT }}{% endlocaltime %}"),
    543             'off':   Template("{% load tz %}{% localtime off %}{{ dt }}|{{ dt|aslocaltime }}|{{ dt|asutc }}|{{ dt|astimezone:ICT }}{% endlocaltime %}"),
     540            'notag': Template("{% load tz %}{{ dt }}|{{ dt|localtime }}|{{ dt|utc }}|{{ dt|timezone:ICT }}"),
     541            'noarg': Template("{% load tz %}{% localtime %}{{ dt }}|{{ dt|localtime }}|{{ dt|utc }}|{{ dt|timezone:ICT }}{% endlocaltime %}"),
     542            'on':    Template("{% load tz %}{% localtime on %}{{ dt }}|{{ dt|localtime }}|{{ dt|utc }}|{{ dt|timezone:ICT }}{% endlocaltime %}"),
     543            'off':   Template("{% load tz %}{% localtime off %}{{ dt }}|{{ dt|localtime }}|{{ dt|utc }}|{{ dt|timezone:ICT }}{% endlocaltime %}"),
    544544        }
    545545
    546546        # Transform a list of keys in 'datetimes' to the expected template
    class TemplateTests(BaseDateTimeTests):  
    600600    @skipIf(pytz is None, "this test requires pytz")
    601601    def test_localtime_filters_with_pytz(self):
    602602        """
    603         Test the |aslocaltime, |asutc, and |astimezone filters with pytz.
     603        Test the |localtime, |utc, and |timezone filters with pytz.
    604604        """
    605605        # Use a pytz timezone as local time
    606         tpl = Template("{% load tz %}{{ dt|aslocaltime }}|{{ dt|asutc }}")
     606        tpl = Template("{% load tz %}{{ dt|localtime }}|{{ dt|utc }}")
    607607        ctx = Context({'dt': datetime.datetime(2011, 9, 1, 12, 20, 30)})
    608608
    609609        timezone._localtime = None
    class TemplateTests(BaseDateTimeTests):  
    612612        timezone._localtime = None
    613613
    614614        # Use a pytz timezone as argument
    615         tpl = Template("{% load tz %}{{ dt|astimezone:tz }}")
     615        tpl = Template("{% load tz %}{{ dt|timezone:tz }}")
    616616        ctx = Context({'dt': datetime.datetime(2011, 9, 1, 13, 20, 30),
    617617                       'tz': pytz.timezone('Europe/Paris')})
    618618        self.assertEqual(tpl.render(ctx), "2011-09-01T12:20:30+02:00")
    619619
    620620        # Use a pytz timezone name as argument
    621         tpl = Template("{% load tz %}{{ dt|astimezone:'Europe/Paris' }}")
     621        tpl = Template("{% load tz %}{{ dt|timezone:'Europe/Paris' }}")
    622622        ctx = Context({'dt': datetime.datetime(2011, 9, 1, 13, 20, 30),
    623623                       'tz': pytz.timezone('Europe/Paris')})
    624624        self.assertEqual(tpl.render(ctx), "2011-09-01T12:20:30+02:00")
    class TemplateTests(BaseDateTimeTests):  
    629629
    630630    def test_localtime_filters_do_not_raise_exceptions(self):
    631631        """
    632         Test the |aslocaltime, |asutc, and |astimezone filters on bad inputs.
     632        Test the |localtime, |utc, and |timezone filters on bad inputs.
    633633        """
    634         tpl = Template("{% load tz %}{{ dt }}|{{ dt|aslocaltime }}|{{ dt|asutc }}|{{ dt|astimezone:tz }}")
     634        tpl = Template("{% load tz %}{{ dt }}|{{ dt|localtime }}|{{ dt|utc }}|{{ dt|timezone:tz }}")
    635635        with self.settings(USE_TZ=True):
    636636            # bad datetime value
    637637            ctx = Context({'dt': None, 'tz': ICT})
    class TemplateTests(BaseDateTimeTests):  
    639639            ctx = Context({'dt': 'not a date', 'tz': ICT})
    640640            self.assertEqual(tpl.render(ctx), "not a date|||")
    641641            # bad timezone value
    642             tpl = Template("{% load tz %}{{ dt|astimezone:tz }}")
     642            tpl = Template("{% load tz %}{{ dt|timezone:tz }}")
    643643            ctx = Context({'dt': datetime.datetime(2011, 9, 1, 13, 20, 30), 'tz': None})
    644644            self.assertEqual(tpl.render(ctx), "")
    645645            ctx = Context({'dt': datetime.datetime(2011, 9, 1, 13, 20, 30), 'tz': 'not a tz'})
Back to Top