aboutsummaryrefslogtreecommitdiff
path: root/middleware
diff options
context:
space:
mode:
authorBobby <[email protected]>2025-05-20 08:08:56 +0530
committerBobby <[email protected]>2025-05-20 08:08:56 +0530
commit0686a7fa66f7ae173045d73e60fbdcdac7349ea8 (patch)
tree6fc58a2d744ab1dfd12cc8346009e9d49a6843e2 /middleware
parent85bef77e0d2810dfc63807ed62e8c222f05aabf4 (diff)
downloadthatcomputerscientist-0686a7fa66f7ae173045d73e60fbdcdac7349ea8.tar.xz
thatcomputerscientist-0686a7fa66f7ae173045d73e60fbdcdac7349ea8.zip
moving older templates to `templates.old` temporarily; auth module; user profile middleware; localegen generator
Diffstat (limited to 'middleware')
-rw-r--r--middleware/userprofilemiddleware.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/middleware/userprofilemiddleware.py b/middleware/userprofilemiddleware.py
new file mode 100644
index 00000000..724f7f04
--- /dev/null
+++ b/middleware/userprofilemiddleware.py
@@ -0,0 +1,14 @@
+from django.utils.deprecation import MiddlewareMixin
+from users.models import UserProfile
+
+class UserProfileMiddleware(MiddlewareMixin):
+ def process_request(self, request):
+ if request.user.is_authenticated:
+ try:
+ user_profile = UserProfile.objects.get(user=request.user)
+ except UserProfile.DoesNotExist:
+ user_profile = UserProfile(user=request.user)
+ user_profile.save()
+ request.user.profile = user_profile
+ else:
+ request.user.profile = None \ No newline at end of file