def process_request(self, request):
try:<EOL><INDENT>session = request.session<EOL><DEDENT>except AttributeError:<EOL><INDENT>raise ImproperlyConfigured('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if settings.ENABLED is False:<EOL><INDENT>return None<EOL><DEDENT>if self.remote_addr_exceptions:<EOL><INDENT>remote_addr_exceptions = self.remote_addr_exceptions<EOL><DEDENT>else:<EOL><INDENT>remote_addr_exceptions = settings.REMOTE_ADDR_EXCEPTIONS<EOL><DEDENT>if remote_addr_exceptions:<EOL><INDENT>trusted_proxies = self.trusted_proxies or settings.TRUSTED_PROXIES<EOL>remote_addr = request.META.get('<STR_LIT>')<EOL>if remote_addr in remote_addr_exceptions:<EOL><INDENT>return None<EOL><DEDENT>if remote_addr in trusted_proxies:<EOL><INDENT>x_forwarded_for = request.META.get('<STR_LIT>')<EOL>if x_forwarded_for:<EOL><INDENT>remote_addr = x_forwarded_for.split('<STR_LIT:U+002C>')[-<NUM_LIT:1>].strip()<EOL>if remote_addr in remote_addr_exceptions:<EOL><INDENT>return None<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if self.url_exceptions:<EOL><INDENT>url_exceptions = compile_url_exceptions(self.url_exceptions)<EOL><DEDENT>else:<EOL><INDENT>url_exceptions = compile_url_exceptions(settings.URL_EXCEPTIONS)<EOL><DEDENT>for pattern in url_exceptions:<EOL><INDENT>if pattern.search(request.path):<EOL><INDENT>return None<EOL><DEDENT><DEDENT>try:<EOL><INDENT>resolved_path = resolve(request.path)<EOL><DEDENT>except Resolver404:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>if resolved_path.func in settings.VIEW_EXCEPTIONS:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>if self.until_date:<EOL><INDENT>until_date = self.until_date<EOL><DEDENT>else:<EOL><INDENT>until_date = settings.UNTIL_DATE<EOL><DEDENT>if self.after_date:<EOL><INDENT>after_date = self.after_date<EOL><DEDENT>else:<EOL><INDENT>after_date = settings.AFTER_DATE<EOL><DEDENT>if until_date or after_date:<EOL><INDENT>locked_date = False<EOL>if until_date and datetime.datetime.now() < until_date:<EOL><INDENT>locked_date = True<EOL><DEDENT>if after_date and datetime.datetime.now() > after_date:<EOL><INDENT>locked_date = True<EOL><DEDENT>if not locked_date:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>form_data = request.POST if request.method == '<STR_LIT:POST>' else None<EOL>if self.form:<EOL><INDENT>form_class = self.form<EOL><DEDENT>else:<EOL><INDENT>form_class = get_lockdown_form(settings.FORM)<EOL><DEDENT>form = form_class(data=form_data, **self.form_kwargs)<EOL>authorized = False<EOL>token = session.get(self.session_key)<EOL>if hasattr(form, '<STR_LIT>'):<EOL><INDENT>if form.authenticate(token):<EOL><INDENT>authorized = True<EOL><DEDENT><DEDENT>elif token is True:<EOL><INDENT>authorized = True<EOL><DEDENT>if authorized and self.logout_key and self.logout_key in request.GET:<EOL><INDENT>if self.session_key in session:<EOL><INDENT>del session[self.session_key]<EOL><DEDENT>querystring = request.GET.copy()<EOL>del querystring[self.logout_key]<EOL>return self.redirect(request)<EOL><DEDENT>if authorized:<EOL><INDENT>return None<EOL><DEDENT>if form.is_valid():<EOL><INDENT>if hasattr(form, '<STR_LIT>'):<EOL><INDENT>token = form.generate_token()<EOL><DEDENT>else:<EOL><INDENT>token = True<EOL><DEDENT>session[self.session_key] = token<EOL>return self.redirect(request)<EOL><DEDENT>page_data = {'<STR_LIT>': until_date, '<STR_LIT>': after_date}<EOL>if not hasattr(form, '<STR_LIT>') or form.show_form():<EOL><INDENT>page_data['<STR_LIT>'] = form<EOL><DEDENT>if self.extra_context:<EOL><INDENT>page_data.update(self.extra_context)<EOL><DEDENT>return render(request, '<STR_LIT>', page_data)<EOL>
Check if each request is allowed to access the current resource.