Esempio n. 1
0
def update_all_probleminstances_after_reupload(problem):
    """Updates test_set for every problem_instance assiged to Problem.
       to main_problem_instance.test_set
    """
    for pi in problem.probleminstance_set.filter(contest__isnull=False):
        update_tests_from_main_pi(pi)
        pi.needs_rejudge = True
        pi.save()
Esempio n. 2
0
def update_all_probleminstances_after_reupload(problem):
    """Updates test_set for every problem_instance assiged to Problem.
       to main_problem_instance.test_set
    """
    for pi in problem.probleminstance_set.filter(contest__isnull=False):
        update_tests_from_main_pi(pi)
        pi.needs_rejudge = True
        pi.save()
Esempio n. 3
0
def reset_tests_limits_for_probleminstance_view(request, problem_instance_id):
    problem_instance = get_object_or_404(ProblemInstance,
                                         id=problem_instance_id)
    if request.POST:
        update_tests_from_main_pi(problem_instance)
        messages.success(request, _("Tests limits reset successfully"))
        return safe_redirect(request, reverse(
            'oioioiadmin:contests_probleminstance_changelist'))

    return TemplateResponse(request, 'contests/confirm_resetting_limits.html',
                            {'probleminstance': problem_instance})
Esempio n. 4
0
def reset_tests_limits_for_probleminstance_view(request, problem_instance_id):
    problem_instance = get_object_or_404(ProblemInstance,
                                         id=problem_instance_id)
    if request.POST:
        update_tests_from_main_pi(problem_instance)
        messages.success(request, _("Tests limits resetted successfully"))
        return safe_redirect(request, reverse(
            'oioioiadmin:contests_probleminstance_changelist'))

    return TemplateResponse(request, 'contests/confirm_resetting_limits.html',
                            {'probleminstance': problem_instance})
Esempio n. 5
0
    def view(self, request, contest, existing_problem=None):
        if not contest:
            messages.error(request, _("Option not available"))
            path = request.path
            if existing_problem:
                path += '?' + urlencode({'problem': existing_problem.id})
            return safe_redirect(request, path)

        is_reupload = existing_problem is not None
        if existing_problem:
            url_key = existing_problem.problemsite.url_key
        else:
            # take url_key form form
            url_key = request.POST.get('url_key', None)
        if url_key is None:
            # take url_key from Problemset
            url_key = request.GET.get('url_key', None)

        form = ProblemsetSourceForm(url_key)
        post_data = {'form': form, 'is_reupload': is_reupload}

        if request.POST:
            if not Problem.objects.filter(problemsite__url_key=url_key) \
                    .exists():
                messages.error(request, _('Given url key is invalid'))
                return TemplateResponse(request,
                        "problems/problemset_source.html",
                        post_data)

            problem = Problem.objects.get(problemsite__url_key=url_key)
            if existing_problem:
                assert problem == existing_problem
                assert 'instance_id' in request.GET
                pi = problem.probleminstance_set.get(contest=request.contest,
                                            id=request.GET['instance_id'])
                update_tests_from_main_pi(pi)
                # limits could be changed
                pi.needs_rejudge = True
                pi.save()
                messages.success(request, _("Problem successfully updated"))
            else:
                pi = get_new_problem_instance(problem)
                pi.contest = request.contest
                pi.short_name = None
                pi.save()
                messages.success(request, _("Problem successfully uploaded"))
            return safe_redirect(request, reverse(
                    'oioioiadmin:contests_probleminstance_changelist'))

        return TemplateResponse(request, "problems/problemset_source.html",
                                post_data)
Esempio n. 6
0
    def view(self, request, contest, existing_problem=None):
        if not contest:
            messages.error(request, _("Option not available"))
            path = request.path
            if existing_problem:
                path += '?' + urlencode({'problem': existing_problem.id})
            return safe_redirect(request, path)

        is_reupload = existing_problem is not None
        if existing_problem:
            url_key = existing_problem.problemsite.url_key
        else:
            # take url_key form form
            url_key = request.POST.get('url_key', None)
        if url_key is None:
            # take url_key from Problemset
            url_key = request.GET.get('url_key', None)

        form = ProblemsetSourceForm(url_key)
        post_data = {'form': form, 'is_reupload': is_reupload}

        if request.POST:
            if not Problem.objects.filter(problemsite__url_key=url_key) \
                    .exists():
                messages.error(request, _('Given url key is invalid'))
                return TemplateResponse(request,
                                        "problems/problemset_source.html",
                                        post_data)

            problem = Problem.objects.get(problemsite__url_key=url_key)
            if existing_problem:
                assert problem == existing_problem
                assert 'instance_id' in request.GET
                pi = problem.probleminstance_set.get(
                    contest=contest, id=request.GET['instance_id'])
                update_tests_from_main_pi(pi)
                # limits could be changed
                pi.needs_rejudge = True
                pi.save()
                messages.success(request, _("Problem successfully updated"))
            else:
                pi = get_new_problem_instance(problem, contest)
                messages.success(request, _("Problem successfully uploaded"))
            return safe_redirect(
                request,
                reverse('oioioiadmin:contests_probleminstance_changelist'))

        return TemplateResponse(request, "problems/problemset_source.html",
                                post_data)