Code

Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#654 closed defect (fixed)

DateFormat should be a subclass of TimeFormat, not Formatter

Reported by: Tom Tobin <korpios@…> Owned by: adrian
Component: Tools Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

django.utils.dateformat.DateFormat is currently a subclass of Formatter, not TimeFormat. As a result, calls to, e.g., dateformat.format will fail if they contain characters referencing units handled by TimeFormat.

Example traceback:

There's been an error:

Traceback (most recent call last):

  File "/home/korpios/devel/py3p/django/core/handlers/base.py", line 68, in get_response
    response = callback(request, **param_dict)

  File "/home/korpios/devel/py3p/django/contrib/admin/views/decorators.py", line 49, in _checklogin
    return view_func(request, *args, **kwargs)

  File "/home/korpios/devel/py3p/django/contrib/admin/views/main.py", line 1110, in history
    }, context_instance=Context(request))

  File "/home/korpios/devel/py3p/django/core/extensions.py", line 11, in render_to_response
    return HttpResponse(loader.render_to_string(*args, **kwargs))

  File "/home/korpios/devel/py3p/django/core/template/loader.py", line 82, in render_to_string
    return t.render(context_instance)

  File "/home/korpios/devel/py3p/django/core/template/__init__.py", line 116, in render
    return self.nodelist.render(context)

  File "/home/korpios/devel/py3p/django/core/template/__init__.py", line 443, in render
    bits.append(node.render(context))

  File "/home/korpios/devel/py3p/django/core/template/loader.py", line 161, in render
    return compiled_parent.render(context)

  File "/home/korpios/devel/py3p/django/core/template/__init__.py", line 116, in render
    return self.nodelist.render(context)

  File "/home/korpios/devel/py3p/django/core/template/__init__.py", line 443, in render
    bits.append(node.render(context))

  File "/home/korpios/devel/py3p/django/core/template/loader.py", line 161, in render
    return compiled_parent.render(context)

  File "/home/korpios/devel/py3p/django/core/template/__init__.py", line 116, in render
    return self.nodelist.render(context)

  File "/home/korpios/devel/py3p/django/core/template/__init__.py", line 443, in render
    bits.append(node.render(context))

  File "/home/korpios/devel/py3p/django/core/template/loader.py", line 106, in render
    result = self.nodelist.render(context)

  File "/home/korpios/devel/py3p/django/core/template/__init__.py", line 443, in render
    bits.append(node.render(context))

  File "/home/korpios/devel/py3p/django/core/template/defaulttags.py", line 178, in render
    return self.nodelist_true.render(context)

  File "/home/korpios/devel/py3p/django/core/template/__init__.py", line 443, in render
    bits.append(node.render(context))

  File "/home/korpios/devel/py3p/django/core/template/defaulttags.py", line 111, in render
    nodelist.append(node.render(context))

  File "/home/korpios/devel/py3p/django/core/template/__init__.py", line 473, in render
    output = resolve_variable_with_filters(self.var_string, context)

  File "/home/korpios/devel/py3p/django/core/template/__init__.py", line 418, in resolve_variable_with_filters
    obj = registered_filters[name][0](obj, arg)

  File "/home/korpios/devel/py3p/django/core/template/defaultfilters.py", line 317, in date
    return format(value, arg)

  File "/home/korpios/devel/py3p/django/utils/dateformat.py", line 238, in format
    return df.format(format_string)

  File "/home/korpios/devel/py3p/django/utils/dateformat.py", line 26, in format
    pieces.append(str(getattr(self, piece)()))

AttributeError: DateFormat instance has no attribute 'P'

Solution: have django.utils.dateformat.DateFormat subclass TimeFormat.

Attachments (0)

Change History (2)

comment:1 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [976]) Fixed #654 -- Fixed bug in [969]. Thanks, korpios@…

comment:2 Changed 7 years ago by korpios

  • Reporter changed from korpios@… to Tom Tobin <korpios@…>

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.