Beispiel #1
0
def scoreboard(request, access_code=None, template='scoreboard/_cacheboard.html'):
    if not request.user.is_staff and not ScoreboardAccess.valid(access_code, increment=True):
        # Check the cache for a response object and return that if set. We're not
        # using Django's view/template cacher because we cannot invalidate them.
        sb_cache = cache.get('scoreboard')
        if sb_cache:
            return render_cached(sb_cache, request)
        context = {}
    else:
        # If the user is a staff, we show the extended results page
        # We won't cache this since it won't be checked often and we don't want to
        # take a chance that the cache was not invalidated when reviewing results
        context = {'results': True, 'template_fullwidth': True}

    # Get information (fname, lname) for each user, map user object over id
    ranks, problems = Scoreboard.results()
    profiles = Profile.objects.select_related('user').in_bulk(map(lambda x: x[0], ranks))
    context['scoreboard'] = map(lambda y: (profiles[y[0]].user, y[1], y[2], y[3]), ranks)
    context['problems'] = problems
    # Default this to "" so that the resume links work
    context['access_code'] = access_code or ""

    resp = render_to_string(template, context,
            context_instance=RequestContext(request))
    if not request.user.is_staff:
        cache.set('scoreboard', resp)
    return render_cached(resp, request)
Beispiel #2
0
def scoreboard(request,
               access_code=None,
               template='scoreboard/_cacheboard.html'):
    if not request.user.is_staff and not ScoreboardAccess.valid(
            access_code, increment=True):
        # Check the cache for a response object and return that if set. We're not
        # using Django's view/template cacher because we cannot invalidate them.
        sb_cache = cache.get('scoreboard')
        if sb_cache:
            return render_cached(sb_cache, request)
        context = {}
    else:
        # If the user is a staff, we show the extended results page
        # We won't cache this since it won't be checked often and we don't want to
        # take a chance that the cache was not invalidated when reviewing results
        context = {'results': True, 'template_fullwidth': True}

    # Get information (fname, lname) for each user, map user object over id
    ranks, problems = Scoreboard.results()
    profiles = Profile.objects.select_related('user').in_bulk(
        map(lambda x: x[0], ranks))
    context['scoreboard'] = map(
        lambda y: (profiles[y[0]].user, y[1], y[2], y[3]), ranks)
    context['problems'] = problems
    # Default this to "" so that the resume links work
    context['access_code'] = access_code or ""

    resp = render_to_string(template,
                            context,
                            context_instance=RequestContext(request))
    if not request.user.is_staff:
        cache.set('scoreboard', resp)
    return render_cached(resp, request)
Beispiel #3
0
def resume(request, user_id=None, access_code=None):
    user = request.user
    if user_id:
        if request.user.is_staff or ScoreboardAccess.valid(access_code):
            try:
                user = User.objects.select_related('profile').get(pk=user_id)
            except ScoreboardAccess.DoesNotExist:
                raise Http404
        else:
            raise Http404

    if not user.profile.resume:
        raise Http404

    path = user.profile.resume.path
    resume_type = mimetypes.guess_type(path)[0] or 'application/force-download'
    return serve_file(request, path,  force_download=False, content_type=resume_type)
Beispiel #4
0
def resume(request, user_id=None, access_code=None):
    user = request.user
    if user_id:
        if request.user.is_staff or ScoreboardAccess.valid(access_code):
            try:
                user = User.objects.select_related('profile').get(pk=user_id)
            except ScoreboardAccess.DoesNotExist:
                raise Http404
        else:
            raise Http404

    if not user.profile.resume:
        raise Http404

    path = user.profile.resume.path
    resume_type = mimetypes.guess_type(path)[0] or 'application/force-download'
    return serve_file(request,
                      path,
                      force_download=False,
                      content_type=resume_type)