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

27 lines
739 B
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
class OrganizationMiddleware(object):
"""
Middleware that add organization info to request when user in organization
context.
"""
def process_request(self, request):
2012-07-27 14:12:25 +08:00
# Get current org context
2012-07-26 17:08:31 +08:00
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
2012-07-26 17:08:31 +08:00
return None
def process_response(self, request, response):
return response