You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

24 lines
802 B

from hc.accounts.models import Profile, Project
class TeamAccessMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
if not request.user.is_authenticated:
return self.get_response(request)
projects_q = Project.objects.filter(member__user_id=request.user.id)
projects_q = projects_q.select_related("owner")
request.get_projects = lambda: list(projects_q)
profile = Profile.objects.for_user(request.user)
if profile.current_project is None:
profile.current_project = profile.get_own_project()
profile.save()
request.profile = profile
request.project = profile.current_project
return self.get_response(request)