from django.contrib.sites.models import Site from django.conf import settings from django_cas.backends import CASBackend from django.template import RequestContext, loader from django.http import HttpResponse from gestioncof.models import CofProfile def render_page (request, data, template): template = loader.get_template (template) context = RequestContext (request, data) return HttpResponse (template.render (context)) class COFCASBackend(CASBackend): def authenticate(self, ticket, service): """Authenticates CAS ticket and retrieves user data""" user = super(COFCASBackend, self).authenticate(ticket, service) try: profile = user.get_profile() except CofProfile.DoesNotExist: profile, created = CofProfile.objects.get_or_create(user = user) profile.save() if not profile.login_clipper: profile.login_clipper = user.username profile.save() if not user.email: user.email = settings.CAS_EMAIL_FORMAT % profile.login_clipper user.save() if profile.is_buro and not user.is_superuser: user.is_superuser = True user.is_staff = True user.save() return user def context_processor (request): '''Append extra data to the context of the given request''' data = { "user": request.user, "site": Site.objects.get_current(), } return data