gestioCOF/gestioncof/shared.py

34 lines
990 B
Python
Raw Normal View History

2012-06-27 23:28:35 +02:00
from django.conf import settings
from django.contrib.sites.models import Site
from django_cas_ng.backends import CASBackend
2012-07-11 17:39:20 +02:00
from gestioncof.models import CofProfile
2012-07-11 17:39:20 +02:00
2012-06-27 23:28:35 +02:00
class COFCASBackend(CASBackend):
def clean_username(self, username):
# Le CAS de l'ENS accepte les logins avec des espaces au début
# et à la fin, ainsi quavec une casse variable. On normalise pour
# éviter les doublons.
return username.strip().lower()
def configure_user(self, user):
# cannot use "defaults" arg
profile, _ = CofProfile.objects.get_or_create(user=user)
profile.login_clipper = user.username
profile.save()
user.email = settings.CAS_EMAIL_FORMAT % profile.login_clipper
user.save()
2012-06-27 23:28:35 +02:00
return user
def context_processor(request):
2012-06-27 23:28:35 +02:00
'''Append extra data to the context of the given request'''
data = {
"user": request.user,
"site": Site.objects.get_current(),
}
2012-06-27 23:28:35 +02:00
return data