def process_request(self, request): """Process each request to app to ensure terms & conditions have been accepted""" LOGGER.debug('termsandconditions.middleware') current_path = request.META['PATH_INFO'] protected_path = True for exclude_path in TERMS_EXCLUDE_URL_PREFIX_LIST: if current_path.startswith(exclude_path): protected_path = False if current_path in TERMS_EXCLUDE_URL_LIST: protected_path = False if current_path.startswith(ACCEPT_TERMS_PATH): protected_path = False if request.user.is_authenticated() and protected_path: if MULTIPLE_ACTIVE_TERMS: for term in TermsAndConditions.get_active_list(): if not TermsAndConditions.agreed_to_latest( request.user, term): return redirect_to_terms_accept(current_path, term) else: if not TermsAndConditions.agreed_to_latest(request.user): return redirect_to_terms_accept(current_path)
def process_request(self, request): """Process each request to app to ensure terms & conditions have been accepted""" LOGGER.debug('termsandconditions.middleware') current_path = request.META['PATH_INFO'] protected_path = True for exclude_path in TERMS_EXCLUDE_URL_PREFIX_LIST: if current_path.startswith(exclude_path): protected_path = False if current_path in TERMS_EXCLUDE_URL_LIST: protected_path = False if current_path.startswith(ACCEPT_TERMS_PATH): protected_path = False if request.user.is_authenticated() and protected_path: if MULTIPLE_ACTIVE_TERMS: for term in TermsAndConditions.get_active_list(): if not TermsAndConditions.agreed_to_latest(request.user, term): return redirect_to_terms_accept(current_path, term) else: if not TermsAndConditions.agreed_to_latest(request.user): return redirect_to_terms_accept(current_path)
def process_request(self, request): """Process each request to app to ensure terms have been accepted""" LOGGER.debug('termsandconditions.middleware') current_path = request.META['PATH_INFO'] protected_path = is_path_protected(current_path) if request.user.is_authenticated() and protected_path: for term in TermsAndConditions.get_active_list(): if not TermsAndConditions.agreed_to_latest(request.user, term): return redirect_to_terms_accept(current_path, term) return None
def test_get_active_list(self): """Test get list of active T&Cs""" active_list = TermsAndConditions.get_active_list() self.assertEqual(2, len(active_list))