aboutsummaryrefslogtreecommitdiff
path: root/middleware/preferences.py
blob: 90d459e81a6e9a36ac398574f3232d6a74d60a51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from user_profile.models import UserPreferences

class PreferencesMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        if request.user.is_authenticated:
            user_preferences = UserPreferences.objects.get_or_create(user=request.user)[0]
            request.user.preferences = user_preferences

        response = self.get_response(request)
        return response