def process_view(self, request, view_func, view_args, view_kwargs, selector=None): if not self._check_requirements(request): return def _default_selector(user, contest): return not user.has_perm('contests.contest_admin', contest) if selector is None: final_selector = _default_selector else: final_selector = lambda user, contest: _default_selector( user, contest ) and selector(user, contest) if settings.ONLY_DEFAULT_CONTEST: qs = [Contest.objects.get(id=settings.DEFAULT_CONTEST)] else: qs = ExclusivenessConfig.objects.get_active( request.timestamp ).select_related('contest') qs = [ex_cf.contest for ex_cf in qs] qs = [cnst for cnst in qs if final_selector(request.user, cnst)] if len(qs) > 1: self._send_error_email(request, qs) activate_contest(request, None) auth.logout(request) return TemplateResponse( request, 'contestexcl/exclusive-contests-error.html' ) elif len(qs) == 1: contest = qs[0] if request.contest != contest: if request.is_ajax(): raise PermissionDenied else: messages.info( request, _( "You have been redirected to this contest," " because you are not currently allowed to access" " other contests." ), ) return redirect( reverse( 'default_contest_view', kwargs={'contest_id': contest.id} ) ) request.contest_exclusive = True else: request.contest_exclusive = False
def process_view(self, request, view_func, view_args, view_kwargs, selector=None): if not self._check_requirements(request): return def _default_selector(user, contest): return not user.has_perm('contests.contest_admin', contest) if selector is None: final_selector = _default_selector else: final_selector = lambda user, contest: \ _default_selector(user, contest) and selector(user, contest) if settings.ONLY_DEFAULT_CONTEST: qs = [Contest.objects.get(id=settings.DEFAULT_CONTEST)] else: qs = ExclusivenessConfig.objects.get_active(request.timestamp) \ .select_related('contest') qs = [ex_cf.contest for ex_cf in qs] qs = [cnst for cnst in qs if final_selector(request.user, cnst)] if len(qs) > 1: self._send_error_email(request, qs) activate_contest(request, None) auth.logout(request) return TemplateResponse(request, 'contestexcl/exclusive_contests_error.html') elif len(qs) == 1: contest = qs[0] if request.contest != contest: if request.is_ajax(): raise PermissionDenied else: messages.info( request, _("You have been redirected to this contest," " because you are not currently allowed to access" " other contests.") ) return redirect(reverse('default_contest_view', kwargs={'contest_id': contest.id})) request.contest_exclusive = True else: request.contest_exclusive = False