コード例 #1
0
ファイル: views.py プロジェクト: bbiiggppiigg/NTHUOJ_web
def contest_status(request, contest):
    """Return a status table of given contest"""
    submissions = get_visible_submission(request.user)
    submissions = get_contest_submissions(contest, submissions)

    submissions = regroup_submission(submissions)
    table_content = str(render(request, 'status/statusTable.html', {'submissions': submissions}))
    # remove rendered response header
    table_content = re.sub('Content-Type: text/html; charset=utf-8', '', table_content)
    return table_content
コード例 #2
0
ファイル: views.py プロジェクト: LFsWang/NTHUOJ_web
def status(request):
    status_filter = StatusFilter(request.GET)
    submissions = get_visible_submission(request.user).order_by('-id')
    render_data = {}
    render_data['status_filter'] = status_filter
    render_data['running_contests'] = get_running_contests().order_by('id')

    if status_filter.is_valid():
        username = status_filter.cleaned_data['username']
        cid = status_filter.cleaned_data['cid']
        pid = status_filter.cleaned_data['pid']
        status = status_filter.cleaned_data['status']

        if username:
            user = User.objects.get(username=username)
            submissions = submissions.filter(user=user)

        if pid:
            problem = Problem.objects.get(id=pid)
            submissions = submissions.filter(problem=problem)

        if cid:
            contest = Contest.objects.get(id=cid)
            submissions = get_contest_submissions(contest, submissions)

        if status:
            submissions = submissions.filter(status=status)

        submissions = get_current_page(request, submissions)

        # Regroup submission details
        submissions.object_list = regroup_submission(submissions.object_list)

        # Serialize to json
        if 'type' in request.GET and request.GET['type'] == 'json':
            submissions = [submission['grouper']
                           for submission in submissions.object_list]
            # Remove unnecessary fields
            submissions = serialize("python", submissions)
            submissions = [s['fields'] for s in submissions]

            return HttpResponse(json.dumps(submissions, default=lambda obj: obj.isoformat() if hasattr(obj, 'isoformat') else obj))
    else:
        messages.warning(request, 'Please check filter constraints again!')
        return render_index(request, 'status/status.html', render_data)

    if not submissions:
        messages.warning(request, 'No submissions found for the given query!')

    render_data['submissions'] = submissions

    return render_index(request, 'status/status.html', render_data)
コード例 #3
0
def contest_status(request, contest):
    """Return a status table of given contest"""
    submissions = get_visible_submission(request.user)
    submissions = get_contest_submissions(contest, submissions)

    submissions = regroup_submission(submissions)
    table_content = str(
        render(request, 'status/statusTable.html',
               {'submissions': submissions}))
    # remove rendered response header
    table_content = re.sub('Content-Type: text/html; charset=utf-8', '',
                           table_content)
    return table_content
コード例 #4
0
def status(request):
    start_time = time.time()
    status_filter = StatusFilter(request.GET)
    submissions = get_visible_submission(request.user).order_by('-id')
    render_data = {}
    render_data['status_filter'] = status_filter
    render_data['running_contests'] = get_running_contests().order_by('id')

    if status_filter.is_valid():
        username = status_filter.cleaned_data['username']
        cid = status_filter.cleaned_data['cid']
        pid = status_filter.cleaned_data['pid']
        status = status_filter.cleaned_data['status']

        if username:
            user = User.objects.get(username=username)
            submissions = submissions.filter(user=user)

        if pid:
            problem = Problem.objects.get(id=pid)
            submissions = submissions.filter(problem=problem)

        if cid:
            contest = Contest.objects.get(id=cid)
            submissions = get_contest_submissions(contest, submissions)

        if status:
            submissions = submissions.filter(status=status)

        huge_table_count = None
        # No constriant provided, the search result would be huge
        # Cache the count for faster paging
        if not (username or pid or cid or status):
            if cache.get('huge_table_count'):
                huge_table_count = cache.get('huge_table_count')
            else:
                huge_table_count = submissions.count()
                cache.set('huge_table_count', huge_table_count, 60)

        submissions = get_current_page(request,
                                       submissions,
                                       count=huge_table_count)

        # Regroup submission details
        submissions.object_list = regroup_submission(submissions.object_list)

        # Serialize to json
        if 'type' in request.GET and request.GET['type'] == 'json':
            submissions = [
                submission['grouper'] for submission in submissions.object_list
            ]
            # Remove unnecessary fields
            submissions = serialize("python", submissions)
            submissions = [s['fields'] for s in submissions]

            return HttpResponse(
                json.dumps(submissions,
                           default=lambda obj: obj.isoformat()
                           if hasattr(obj, 'isoformat') else obj))
    else:
        messages.warning(request, 'Please check filter constraints again!')
        return render_index(request, 'status/status.html', render_data)

    if not submissions:
        messages.warning(request, 'No submissions found for the given query!')

    render_data['submissions'] = submissions
    render_data['searching_time'] = time.time() - start_time
    return render_index(request, 'status/status.html', render_data)