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.

19 lines
599 B

8 years ago
8 years ago
8 years ago
  1. from hc.accounts.models import Profile
  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. teams_q = Profile.objects.filter(member__user_id=request.user.id)
  9. teams_q = teams_q.select_related("user")
  10. request.teams = list(teams_q)
  11. request.profile = Profile.objects.for_user(request.user)
  12. request.team = request.profile.team()
  13. return self.get_response(request)