python - Middleware redirect user to path if user is invalid -
im trying write middleware redirect auth users if invalid members.
here code:
from django.conf import settings django.http import httpresponsepermanentredirect class usercheckmiddleware: def process_request(self, request): #paths inactive_path = settings.inactive_user_url #first check if user logged in if request.user.is_authenticated(): #check if user has valid membership if not request.user.profile.is_valid_member: #check if path inactive_path prevent endless redirectloop if not request.path in (inactive_path): #redirect inactive_path return httpresponsepermanentredirect(inactive_path)
here model code:
class profile(models.model): user = models.onetoonefield(user) memberend = models.datetimefield(blank=true, null=true) def is_valid_member(self): if self.memberend: #return true if memberend in future , false if date in past return self.memberend >= timezone.now() else: #memberend not set, user valid return true
anyone know why im not redirected when set memberend date date in past?
you haven't called method.
if not request.user.profile.is_valid_member():
method objects true.
Comments
Post a Comment