diff --git a/citavi_mapper/settings.py b/citavi_mapper/settings.py index f065712..25a890f 100644 --- a/citavi_mapper/settings.py +++ b/citavi_mapper/settings.py @@ -60,6 +60,7 @@ MIDDLEWARE_CLASSES = ( 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'frontend.proxy.EnforceActiveProjectProxy', ) ROOT_URLCONF = 'citavi_mapper.urls' diff --git a/frontend/proxy.py b/frontend/proxy.py new file mode 100644 index 0000000..5f6bc90 --- /dev/null +++ b/frontend/proxy.py @@ -0,0 +1,48 @@ +# -*- 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 +""" + diff --git a/frontend/templates/project.html b/frontend/templates/project.html index 911552d..a30c372 100644 --- a/frontend/templates/project.html +++ b/frontend/templates/project.html @@ -3,7 +3,6 @@ {% load crispy_forms_tags %} {% endblock %} {% block navbar-header %} - {{block.super}}
  • Leave Project
  • {% endblock %} {% block content %} diff --git a/frontend/templates/projects.html b/frontend/templates/projects.html index 1817f2f..57353a9 100644 --- a/frontend/templates/projects.html +++ b/frontend/templates/projects.html @@ -24,7 +24,7 @@ {{project.id}} {{project.name}} {{project.description}} - Enter project + Enter project {% endfor %} diff --git a/frontend/views.py b/frontend/views.py index 2445400..94047dc 100644 --- a/frontend/views.py +++ b/frontend/views.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- - from django.http import HttpResponse, HttpResponseRedirect from django.views.generic import TemplateView, FormView, CreateView, UpdateView from django.views.generic.detail import SingleObjectMixin @@ -89,7 +88,7 @@ class ProtectedUpdateView(LoggedInMixin, MyUpdateView): def enterProject(request, project_id=None): try: if request.session['project_id'] != project_id: - return HttpResponse("Please leave your current project - Project ID " + request.session['project_id'] + " is still active.") + return HttpResponse(" Please leave your current project - Project ID " + request.session['project_id'] + " is still active.") except KeyError: pass request.session['project_id'] = project_id @@ -100,7 +99,7 @@ def leaveProject(request, project_id=None): if request.session['project_id'] == project_id: del request.session['project_id'] else: - return HttpResponse("You tried to leave project with ID " + project_id + ", but your active project id is " + request.session['project_id'] + ".") + return HttpResponse(" You tried to leave project with ID " + project_id + ", but your active project id is " + request.session['project_id'] + ".") except KeyError: pass return HttpResponseRedirect('/projects/') @@ -130,7 +129,7 @@ class ProjectView(ProtectedFormView, SingleObjectMixin): form_class = FileUploadForm success_url = '/projects/' - + def get(self, request, *args, **kwargs): project_id = kwargs[u'project_id'] self.object = Project.objects.get(pk=project_id)