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.

25 lines
785 B

8 years ago
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 request.user.is_authenticated:
  7. teams_q = Profile.objects.filter(member__user_id=request.user.id)
  8. teams_q = teams_q.select_related("user")
  9. request.teams = list(teams_q)
  10. try:
  11. profile = request.user.profile
  12. except Profile.DoesNotExist:
  13. profile = Profile(user=request.user)
  14. profile.save()
  15. if profile.current_team:
  16. request.team = profile.current_team
  17. else:
  18. request.team = profile
  19. return self.get_response(request)