I'd like to run method decorator @user_passes_test and use a session variable in that test:
def has_correct_search(user):
source = request.session['source']
if ApiSearch.objects.filter(user=user, source=source).exists():
return True
else:
return False
The problem is that I don't know how to pass the request object:
@method_decorator(user_passes_test(has_correct_search, redirect_field_name=search_url_name))
def dispatch(self, request, *args, **kwargs):
(...)
Is there any trick to getting ahold of session variables in this case? What are my options?
I think I found my answer....