Commit e3b6fb37 authored by Enrico Zini's avatar Enrico Zini
Browse files

Add person and am info in the default request object

parent 8acb7455
......@@ -95,6 +95,14 @@ class NMUserBackend(django.contrib.auth.backends.RemoteUserBackend):
return user
class NMInfoMiddleware(object):
def process_request(self, request):
if request.user.is_authenticated():
request.person = request.user.get_profile()
request.am = request.person.am_or_none
else:
request.person = None
request.am = None
def is_am(view_func):
"""
......
......@@ -87,6 +87,13 @@ class Person(models.Model):
except AM.DoesNotExist:
return False
@property
def am_or_none(self):
try:
return self.am
except AM.DoesNotExist:
return None
def can_be_edited(self, am=None):
# If the person is already in LDAP, then we cannot edit their info
if self.status not in (const.STATUS_MM, const.STATUS_DM):
......
......@@ -106,6 +106,7 @@ MIDDLEWARE_CLASSES = (
'backend.auth.FakeRemoteUser',
'django.contrib.auth.middleware.RemoteUserMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'backend.auth.NMInfoMiddleware',
)
AUTHENTICATION_BACKENDS = (
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment