# -*- coding: utf-8 -*- from django.http import HttpResponse, HttpResponseRedirect class EnforceActiveProjectProxy(): def do_debug_output(self, request, *args, **kwargs): print "\n########## ##########" print ',\n'.join("%s: %s" % item for item in request.session.items()) print "########## ##########" print "\n########## ##########" print ',\n'.join("%s: %s" % item for item in vars(request).items()) print "########## ##########" print "\n########## ##########" print args print "########## ##########" print "\n########## ##########" print kwargs print "########## ##########\n" def do_project_id_check(self, request, *args, **kwargs): # kwargs project_id AND path project_id have to match! print request.path try: project_id_arg = args[2][u'project_id'] if request.session[u'project_id'] != None: print "Active project ID: " + request.session[u'project_id'] if project_id_arg != request.session[u'project_id']: return HttpResponse(" You tried to work on a project with ID " + project_id_arg + ", but your active project id is " + request.session['project_id'] + ".") except KeyError: print "No project attribute set." return None def process_view(self, request, *args, **kwargs): print "\n########## ##########" self.do_debug_output(request, *args, **kwargs) print "########## ##########\n" return self.do_project_id_check(request, *args, **kwargs) """ def process_request(self, request, *args, **kwargs): return None print "\n########## ##########" self.do_debug_output(request, *args, **kwargs) print "########## ##########\n" return None """