citavi_mapper/frontend/proxy.py

51 lines
2.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from django.http import HttpResponse, HttpResponseRedirect
class EnforceActiveProjectProxy():
def do_debug_output(self, request, *args, **kwargs):
if True:
return
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:
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("<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
"""