context_processors.py breaks in django2

Issue #98 resolved
Anonymous created an issue

When running in django2 get:

context = processor(self.request)
  File postman/context_processors.py", line 8, in inbox
    if request.user.is_authenticated():
TypeError: 'bool' object is not callable

it is because in danjgo2 using User.is_authenticated() and User.is_anonymous() as methods rather than properties is no longer supported. (see https://docs.djangoproject.com/en/2.0/releases/2.0/)

Just removing the brackets solve the problem:

context-processors.py:

from __future__ import unicode_literals

from postman.models import Message


def inbox(request):
    """Provide the count of unread messages for an authenticated user."""
    if request.user.is_authenticated:
        return {'postman_unread_count': Message.objects.inbox_unread_count(request.user)}
    else:
        return {}

Comments (1)

  1. Log in to comment