예제 #1
0
def export_results(request):
    contest = service.get_contest_from_request(request, True)
    matches = Match.objects.filter(contestant__in=Contestant.objects.filter(
        contest=contest, is_deleted=False))
    data = []
    writing_questions = WritingQuestion.objects.filter(contest=contest)
    now = timezone.now()
    for m in matches:
        t = {}
        t[resource.contestant_user_username] = m.contestant.user.username
        t[resource.contestant_user_fullname] = str(m.contestant.user)
        t[resource.contestant_match] = m.match_id
        t[resource.contest_time] = ''
        if not in_range(m.start_time, m.end_time, now):
            t[resource.contest_time] = get_time_string(
                (m.end_time - m.start_time).seconds)
        t[resource.mc_passed_responses] = m.mc_passed_responses
        i = 1
        writing_responses = json.loads(m.writing_responses)
        for q in writing_questions:
            l = '%s %s %s' % (unicode(
                str(i + 5)), resource.writing, unicode(str(i)))
            if i + 5 < 10:
                l = unicode(str(0)) + l
            if str(q.id) in writing_responses:
                t[l] = writing_responses[str(q.id)]
            else:
                t[l] = ''
            i += 1
        data.append(t)
    return excel.make_response_from_records(data, 'xlsx', file_name='results')
예제 #2
0
def contest_do_contest(request):
    contest = service.get_contest_from_request(request)
    contestants = Contestant.objects.filter(contest=contest, user=request.user)
    if contestants.count() == 0:
        raise PermissionDenied
    data = service.get_current_match(contestants[0])
    if data is None:
        raise PermissionDenied
    data['contest'] = contest
    return render(request, 'contests/do_contest.html', data)
예제 #3
0
def contest_overview(request):
    contest = service.get_contest_from_request(request)
    if not contest.from_time or not contest.to_time:
        contest.time_string = None
    else:
        contest.time_string = '%s - %s' % (str(
            contest.from_time), str(contest.to_time))
    template_data = {
        'contest': contest,
        'can_participate': service.can_participate_contest(contest),
        'can_manage': service.can_manage_contest(contest, request.user)
    }
    if request.user.id:
        template_data['remaining_matches'] = service.remaining_matches(
            contest, request.user)
    return render(request, 'contests/overview.html', template_data)
예제 #4
0
def update(request):
    result = {'success': False}
    contest = service.get_contest_from_request(request, True)
    if request.method == 'POST':
        for f in Contest.get_field_list():
            if f in request.POST:
                try:
                    if f == 'from_time' or f == 'to_time':
                        update_time(contest, f, request.POST[f])
                    elif f == 'use_mc_test' or f == 'use_writing_test':
                        setattr(contest, f, request.POST[f] == 'true')
                    else:
                        setattr(contest, f, request.POST[f])
                except:
                    pass
        contest.save()
        result['success'] = True
    return HttpResponse(json.dumps(result), content_type='application/json')
예제 #5
0
def match_results(request):
    contest = service.get_contest_from_request(request)
    contestants = Contestant.objects.filter(contest=contest, user=request.user)
    if contestants.count() == 0:
        return HttpResponse(json.dumps([]), content_type='application/json')
    matches = Match.objects.filter(contestant=contestants[0])
    result = []
    now = timezone.now()
    for m in matches:
        t = {
            'use_mc_test': contest.use_mc_test,
            'contest_time': (m.end_time - m.start_time).seconds,
            'mc_passed_responses': m.mc_passed_responses,
            'match_name': m.match_id,
            'doing': in_range(m.start_time, m.end_time, now)
        }
        result.append(t)
    return HttpResponse(json.dumps(result), content_type='application/json')
예제 #6
0
def questions(request):
    contest = service.get_contest_from_request(request, True)
    result = []
    if 'type' in request.GET:
        if request.GET['type'] == 'mc':
            questions = MCQuestion.objects.filter(contest=contest)
            for q in questions:
                result.append({
                    'id': q.id,
                    'content': q.content,
                    'a': q.a,
                    'b': q.b,
                    'c': q.c,
                    'd': q.d,
                    'answer': q.answer
                })
        elif request.GET['type'] == 'wt':
            questions = WritingQuestion.objects.filter(contest=contest)
            for q in questions:
                result.append({'id': q.id, 'content': q.content})
    return HttpResponse(json.dumps(result), content_type='application/json')
예제 #7
0
def upload_questions(request):
    contest = service.get_contest_from_request(request, True)
    form = UploadFileForm(request.POST, request.FILES)
    if form.is_valid():
        if request.POST['type'] == 'mc':
            MCQuestion.objects.filter(contest=contest).delete()
            sheet = request.FILES['file'].get_sheet().get_array()
            for row in sheet[1:]:
                question = MCQuestion(contest=contest)
                i = 0
                for f in MCQuestion.get_field_list():
                    setattr(question, f, row[i])
                    i += 1
                question.save()
        elif request.POST['type'] == 'wt':
            WritingQuestion.objects.filter(contest=contest).delete()
            sheet = request.FILES['file'].get_sheet().get_array()
            for row in sheet[1:]:
                question = WritingQuestion(contest=contest, content=row[0])
                question.save()
    result = {'success': True}
    return HttpResponse(json.dumps(result), content_type='application/json')
예제 #8
0
def contest_admin(request):
    contest = service.get_contest_from_request(request, True)
    return render(request, 'contests/admin/admin.html', {'contest': contest})
예제 #9
0
def match_detail(request):
    contest = service.get_contest_from_request(request, True)
    match = get_object_or_404(Match, pk=request.GET.get('match_id'))
    data = {}

    return HttpResponse(json.dumps(data), content_type='application/json')
예제 #10
0
def contestants(request):
    contest = service.get_contest_from_request(request, True)
    page = request.GET.get('page')
    pages, page, matches = service.get_matches(contest, request, page)
    result = {'pages': pages, 'page': page, 'data': matches}
    return HttpResponse(json.dumps(result), content_type='application/json')