1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-13 22:01:06 +00:00
Files
seahub/organizations/middleware.py

38 lines
1.0 KiB
Python
Raw Normal View History

2012-07-26 17:08:31 +08:00
from django.core.cache import cache
from django.http import HttpResponseRedirect
2012-07-27 14:12:25 +08:00
from seaserv import get_org_by_url_prefix, get_orgs_by_user
2012-07-26 17:08:31 +08:00
from settings import ORG_CACHE_PREFIX
try:
from seahub.settings import USE_ORG
except ImportError:
USE_ORG = False
2012-07-26 17:08:31 +08:00
class OrganizationMiddleware(object):
"""
Middleware that add organization info to request when user in organization
context.
"""
2012-07-30 10:25:46 +08:00
2012-07-26 17:08:31 +08:00
def process_request(self, request):
if USE_ORG:
request.use_org = True
# Get current org context
org = cache.get(ORG_CACHE_PREFIX + request.user.username)
request.user.org = org
2012-07-27 14:12:25 +08:00
# Get all orgs user created.
orgs = get_orgs_by_user(request.user.username)
request.user.orgs = orgs
else:
request.use_org = False
request.user.org = None
request.user.orgs = None
2012-07-26 17:08:31 +08:00
return None
def process_response(self, request, response):
return response