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

8 years ago
8 years ago
8 years ago
8 years ago
  1. from hc.accounts.models import Profile, Project
  2. class TeamAccessMiddleware(object):
  3. def __init__(self, get_response):
  4. self.get_response = get_response
  5. def __call__(self, request):
  6. if not request.user.is_authenticated:
  7. return self.get_response(request)
  8. projects_q = Project.objects.filter(member__user_id=request.user.id)
  9. projects_q = projects_q.select_related("owner")
  10. request.get_projects = lambda: list(projects_q)
  11. profile = Profile.objects.for_user(request.user)
  12. if profile.current_project is None:
  13. profile.current_project = profile.get_own_project()
  14. profile.save()
  15. request.profile = profile
  16. request.project = profile.current_project
  17. return self.get_response(request)