2014-08-29 15:52:09 +02:00
# -*- coding: utf-8 -*-
from django . http import HttpResponse , HttpResponseRedirect
class EnforceActiveProjectProxy ( ) :
def do_debug_output ( self , request , * args , * * kwargs ) :
2014-09-01 15:30:57 +02:00
if True :
return
2014-08-29 15:52:09 +02:00
print " \n ########## <session> ########## "
print ' , \n ' . join ( " %s : %s " % item for item in request . session . items ( ) )
print " ########## </session> ########## "
print " \n ########## <request> ########## "
print ' , \n ' . join ( " %s : %s " % item for item in vars ( request ) . items ( ) )
print " ########## </request> ########## "
print " \n ########## <args> ########## "
print args
print " ########## </args> ########## "
print " \n ########## <kwargs> ########## "
print kwargs
print " ########## </kwargs> ########## \n "
def do_project_id_check ( self , request , * args , * * kwargs ) :
# kwargs project_id AND path project_id have to match!
print request . path
try :
2014-09-01 15:30:57 +02:00
project_id_arg = args [ 2 ] [ u ' project_id ' ]
if request . session [ u ' project_id ' ] != None :
2014-08-29 15:52:09 +02:00
print " Active project ID: " + request . session [ u ' project_id ' ]
if project_id_arg != request . session [ u ' project_id ' ] :
return HttpResponse ( " <proxy> 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 ########## <EnforceActiveProjectProxy:process_view> ########## "
self . do_debug_output ( request , * args , * * kwargs )
print " ########## </EnforceActiveProjectProxy:process_view> ########## \n "
return self . do_project_id_check ( request , * args , * * kwargs )
""" def process_request(self, request, *args, **kwargs):
return None
print " \n ########## <EnforceActiveProjectProxy:process_request> ########## "
self . do_debug_output ( request , * args , * * kwargs )
print " ########## </EnforceActiveProjectProxy:process_request> ########## \n "
return None
"""