Closed Bug 1259342 Opened 8 years ago Closed 8 years ago

datetimeformat jinja helpers does not work with RequestFactory

Categories

(support.mozilla.org :: Code Quality, task)

task
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: safwan, Assigned: safwan)

Details

The ``datetime`` jinja helpers does not work when there is no session exists.
From the http interface, its not possible to reproduce as the middleware adds session and user objects. But while testing in unit test, this thing raise issues while loading kitsune/sumo/base.html. As the tests are made with Requestfactory and it does not provide any session or time. Here is the traceback

Traceback (most recent call last):

  File "/home/travis/build/mozilla/kitsune/kitsune/sumo/tests/test_views.py", line 45, in test_deprecated_redirect

    resp = deprecated_redirect(req, url='home')

  File "/home/travis/build/mozilla/kitsune/kitsune/sumo/views.py", line 113, in deprecated_redirect

    'dest': dest, 'proto': proto, 'host': host})

  File "/home/travis/build/mozilla/kitsune/kitsune/sumo/monkeypatch.py", line 128, in _more_info

    resp = fun(request, template_name, *args, **kwargs)

  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/shortcuts.py", line 67, in render

    template_name, context, request=request, using=using)

  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/template/loader.py", line 99, in render_to_string

    return template.render(context, request)

  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django_jinja/backend.py", line 105, in render

    return self.template.render(context)

  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/jinja2/environment.py", line 891, in render

    return self.environment.handle_exception(exc_info, True)

  File "/home/travis/build/mozilla/kitsune/kitsune/sumo/jinja2/sumo/deprecated.html", line 3, in top-level template code

    {% set refresh = (dest, 10) %}

  File "/home/travis/build/mozilla/kitsune/kitsune/sumo/jinja2/base.html", line 198, in top-level template code

    {% trans year=datetimeformat(now(), 'year') %}

  File "/home/travis/build/mozilla/kitsune/kitsune/sumo/templatetags/jinja_helpers.py", line 229, in datetimeformat

    if 'timezone' not in request.session:

AttributeError: 'WSGIRequest' object has no attribute 'session'


Fixing the bug should include get the jinja helpers work while there is no session or user information in the request.
PR got merged
https://github.com/mozilla/kitsune/pull/2823
Assignee: nobody → safwan.rahman15
Status: NEW → ASSIGNED
This has been deployed to prod.
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.