A first very basic import.

Contains basic functionality, and an import of most of the static content
from the old site.

There is still plenty more to do...
This commit is contained in:
Magnus Hagander
2009-09-14 14:39:25 +02:00
commit 90b758c247
199 changed files with 6805 additions and 0 deletions

37
pgweb/util/middleware.py Normal file
View File

@ -0,0 +1,37 @@
from django.http import HttpResponseRedirect, HttpResponse
# Use thread local storage to pass the username down.
# http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser
try:
from threading import local, currentThread
except ImportError:
from django.utils._threading_local import local
_thread_locals = local()
def get_current_user():
return getattr(_thread_locals, 'user', None)
# General middleware for all middleware functionality specific to the pgweb
# project.
class PgMiddleware(object):
def process_view(self, request, view_func, view_args, view_kwargs):
# We implement the SSL verification in a middleware and not just a decorator, because
# if we do it just in a decorator we'd have to add a decorator for each and every
# view that *doesn't* require SSL. This is much easier, of course.
if view_func.__name__ == '_require_ssl':
# This view requires SSL, so check if we have it
if not request.is_secure():
# May need to deal with ports specified here?
return HttpResponseRedirect(request.build_absolute_uri().replace('http://','https://',1))
else:
# This view must not use SSL, so make sure we don't have it
if request.is_secure():
return HttpResponseRedirect(request.build_absolute_uri().replace('https://','http://',1))
return None
# Thread local store for username, see comment at the top of this file
def process_request(self, request):
_thread_locals.user = getattr(request, 'user', None)