コード例 #1
0
ファイル: views.py プロジェクト: sio2project/oioioi
def add_or_update_problem(request, contest, template):
    if 'problem' in request.GET:
        existing_problem = \
                get_object_or_404(Problem, id=request.GET['problem'])
        if contest and not existing_problem.probleminstance_set.filter(
                contest=contest).exists():
            raise Http404
        if not can_admin_problem(request, existing_problem):
            raise PermissionDenied
    else:
        existing_problem = None
        if not request.user.has_perm('problems.problems_db_admin'):
            if contest and (not is_contest_admin(request)):
                raise PermissionDenied

    navbar_links = navbar_links_registry.template_context(request)

    context = {'existing_problem': existing_problem, 'navbar_links': navbar_links}
    tab_kwargs = {
        'contest': contest,
        'existing_problem': existing_problem
    }

    tab_link_params = request.GET.dict()

    def build_link(tab):
        tab_link_params['key'] = tab.key
        return request.path + '?' + six.moves.urllib.parse.urlencode(
                tab_link_params)

    return tabbed_view(request, template, context,
            problem_sources(request), tab_kwargs, build_link)
コード例 #2
0
ファイル: views.py プロジェクト: AdiNar/oioioi
def add_or_update_problem(request, contest, template):
    if 'problem' in request.GET:
        existing_problem = \
                get_object_or_404(Problem, id=request.GET['problem'])
        if contest and not existing_problem.probleminstance_set.filter(
                contest=contest).exists():
            raise Http404
        if not can_admin_problem(request, existing_problem):
            raise PermissionDenied
    else:
        existing_problem = None
        if not request.user.has_perm('problems.problems_db_admin'):
            if contest and (not is_contest_admin(request)):
                raise PermissionDenied

    context = {'existing_problem': existing_problem}
    tab_kwargs = {'contest': contest, 'existing_problem': existing_problem}

    tab_link_params = request.GET.dict()

    def build_link(tab):
        tab_link_params['key'] = tab.key
        return request.path + '?' + urllib.urlencode(tab_link_params)

    return tabbed_view(request, template, context, problem_sources(request),
                       tab_kwargs, build_link)
コード例 #3
0
ファイル: views.py プロジェクト: JacquesWhite/oioioi
def add_or_update_problem(request, contest, template):
    if 'problem' in request.GET:
        existing_problem = get_object_or_404(Problem,
                                             id=request.GET['problem'])
        if (contest and not existing_problem.probleminstance_set.filter(
                contest=contest).exists()):
            raise Http404
        if not can_admin_problem(request, existing_problem):
            raise PermissionDenied
    else:
        existing_problem = None
        if not request.user.has_perm('problems.problems_db_admin'):
            if contest and (not is_contest_basicadmin(request)):
                raise PermissionDenied

    navbar_links = navbar_links_registry.template_context(request)
    problemset_tabs = generate_problemset_tabs(request)

    context = {
        'existing_problem': existing_problem,
        'navbar_links': navbar_links,
        'problemset_tabs': problemset_tabs,
    }
    tab_kwargs = {'contest': contest, 'existing_problem': existing_problem}

    tab_link_params = request.GET.dict()

    def build_link(tab):
        tab_link_params['key'] = tab.key
        return request.path + '?' + six.moves.urllib.parse.urlencode(
            tab_link_params)

    return tabbed_view(
        request,
        template,
        context,
        problem_sources(request, existing_problem=existing_problem
                        is not None),
        tab_kwargs,
        build_link,
    )
コード例 #4
0
ファイル: views.py プロジェクト: sio2project/oioioi
def add_or_update_problem(request, contest, template):
    if "problem" in request.GET:
        existing_problem = get_object_or_404(Problem, id=request.GET["problem"])
        if contest and not existing_problem.probleminstance_set.filter(contest=contest).exists():
            raise Http404
        if not can_admin_problem(request, existing_problem):
            raise PermissionDenied
    else:
        existing_problem = None
        if not request.user.has_perm("problems.problems_db_admin"):
            if contest and (not is_contest_admin(request)):
                raise PermissionDenied

    context = {"existing_problem": existing_problem}
    tab_kwargs = {"contest": contest, "existing_problem": existing_problem}

    tab_link_params = request.GET.dict()

    def build_link(tab):
        tab_link_params["key"] = tab.key
        return request.path + "?" + urllib.urlencode(tab_link_params)

    return tabbed_view(request, template, context, problem_sources(request), tab_kwargs, build_link)
コード例 #5
0
ファイル: views.py プロジェクト: matrach/oioioi
def add_or_update_problem_view(request, contest_id=None):
    sources = problem_sources(request)
    if 'key' not in request.GET:
        qs = request.GET.dict()
        qs['key'] = sources[0].key
        return HttpResponseRedirect(request.path + '?' + urllib.urlencode(qs))
    key = request.GET['key']
    for s in sources:
        if s.key == key:
            current_source = s
            break
    else:
        raise Http404

    contest = contest_id and request.contest

    if 'problem' in request.GET:
        existing_problem = \
                get_object_or_404(Problem, id=request.GET['problem'])
        if contest and not existing_problem.probleminstance_set.filter(
                contest=contest).exists():
            raise Http404
        if not can_change_problem(request, existing_problem):
            raise PermissionDenied
    else:
        existing_problem = None
        if not request.user.has_perm('problems.problems_db_admin'):
            if not contest_id:
                raise PermissionDenied
            if not is_contest_admin(request):
                raise PermissionDenied

    problem_or_content = current_source.view(request, contest,
                                             existing_problem)

    if isinstance(problem_or_content, Problem):
        problem = problem_or_content
        if not problem.package_backend_name:
            raise AssertionError(
                "Problem package source (%r) did not "
                "set Problem.package_backend_name. This is a bug in "
                "the problem package backend." % (s, ))
        if contest:
            if not existing_problem:
                problem.contest = contest
                problem.save()
            pi, created = ProblemInstance.objects.get_or_create(
                problem=problem,
                contest=contest,
                submissions_limit=contest.default_submissions_limit)
            if not pi.round:
                if contest.round_set.count() == 1:
                    pi.round = contest.round_set.get()
                    pi.save()
                else:
                    messages.info(
                        request,
                        _("Please select the round for "
                          "this problem."))
                    return redirect(
                        'oioioiadmin:contests_probleminstance_change', pi.id)
            return redirect('oioioiadmin:contests_probleminstance_changelist')
        else:
            return redirect('oioioiadmin:problems_problem_changelist')

    if isinstance(problem_or_content, TemplateResponse):
        content = problem_or_content.render().content
    else:
        content = problem_or_content

    sources_context = []
    qs = request.GET.dict()
    for s in sources:
        qs['key'] = s.key
        link = request.path + '?' + urllib.urlencode(qs)
        sources_context.append({'obj': s, 'link': link})

    context = {
        'sources': sources_context,
        'current_source': current_source,
        'content': mark_safe(force_unicode(content)),
        'existing_problem': existing_problem,
    }
    return TemplateResponse(request, 'problems/add_or_update.html', context)
コード例 #6
0
ファイル: views.py プロジェクト: matrach/oioioi
def add_or_update_problem_view(request, contest_id=None):
    sources = problem_sources(request)
    if 'key' not in request.GET:
        qs = request.GET.dict()
        qs['key'] = sources[0].key
        return HttpResponseRedirect(request.path + '?' + urllib.urlencode(qs))
    key = request.GET['key']
    for s in sources:
        if s.key == key:
            current_source = s
            break
    else:
        raise Http404

    contest = contest_id and request.contest

    if 'problem' in request.GET:
        existing_problem = \
                get_object_or_404(Problem, id=request.GET['problem'])
        if contest and not existing_problem.probleminstance_set.filter(
                contest=contest).exists():
            raise Http404
        if not can_change_problem(request, existing_problem):
            raise PermissionDenied
    else:
        existing_problem = None
        if not request.user.has_perm('problems.problems_db_admin'):
            if not contest_id:
                raise PermissionDenied
            if not is_contest_admin(request):
                raise PermissionDenied

    problem_or_content = current_source.view(request, contest,
            existing_problem)

    if isinstance(problem_or_content, Problem):
        problem = problem_or_content
        if not problem.package_backend_name:
            raise AssertionError("Problem package source (%r) did not "
                    "set Problem.package_backend_name. This is a bug in "
                    "the problem package backend." % (s,))
        if contest:
            if not existing_problem:
                problem.contest = contest
                problem.save()
            pi, created = ProblemInstance.objects.get_or_create(
                    problem=problem, contest=contest,
                    submissions_limit=contest.default_submissions_limit)
            if not pi.round:
                if contest.round_set.count() == 1:
                    pi.round = contest.round_set.get()
                    pi.save()
                else:
                    messages.info(request, _("Please select the round for "
                        "this problem."))
                    return redirect(
                            'oioioiadmin:contests_probleminstance_change',
                            pi.id)
            return redirect('oioioiadmin:contests_probleminstance_changelist')
        else:
            return redirect('oioioiadmin:problems_problem_changelist')

    if isinstance(problem_or_content, TemplateResponse):
        content = problem_or_content.render().content
    else:
        content = problem_or_content

    sources_context = []
    qs = request.GET.dict()
    for s in sources:
        qs['key'] = s.key
        link = request.path + '?' + urllib.urlencode(qs)
        sources_context.append({'obj': s, 'link': link})

    context = {
        'sources': sources_context,
        'current_source': current_source,
        'content': mark_safe(force_unicode(content)),
        'existing_problem': existing_problem,
    }
    return TemplateResponse(request, 'problems/add_or_update.html', context)