예제 #1
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)
예제 #2
0
def problemset_generate_view(request, page_title, problems, query_string, view_type):
    # We want to show "Add to contest" button only
    # if user is contest admin for any contest.
    show_add_button, administered_recent_contests = \
        _generate_add_to_contest_metadata(request)
    form = ProblemsetSourceForm("")

    return TemplateResponse(request,
       'problems/problemset/problem-list.html',
      {'problems': problems,
       'page_title': page_title,
        'select_problem_src': request.GET.get('select_problem_src'),
       'problem_search': query_string,
       'show_tags': getattr(settings, 'PROBLEM_TAGS_VISIBLE', False),
       'show_search_bar': True,
       'show_add_button': show_add_button,
       'administered_recent_contests': administered_recent_contests,
       'form': form,
       'view_type': view_type})
예제 #3
0
def problemset_generate_view(request, page_title, problems, view_type):
    # We want to show "Add to contest" button only
    # if user is contest admin for any contest.
    show_add_button, administered_recent_contests = \
        generate_add_to_contest_metadata(request)
    show_tags = settings.PROBLEM_TAGS_VISIBLE
    show_statistics = settings.PROBLEM_STATISTICS_AVAILABLE
    show_user_statistics = show_statistics and request.user.is_authenticated
    show_filters = settings.PROBLEM_STATISTICS_AVAILABLE and request.user.is_authenticated
    col_proportions = {
        'id': 1,
        'name': 2,
        'tags': 5,
        'statistics1': 1,
        'statistics2': 1,
        'statistics3': 1,
        'user_score': 1,
        'add_button': 1,
    }
    if not show_add_button:
        col_proportions['tags'] += col_proportions.pop('add_button')
    if not show_statistics:
        col_proportions['id'] += col_proportions.pop('statistics1')
        col_proportions['name'] += col_proportions.pop('statistics2')
        col_proportions['tags'] += col_proportions.pop('statistics3')
    if not show_user_statistics:
        col_proportions['tags'] += col_proportions.pop('user_score')
    if not show_tags:
        col_proportions['name'] += col_proportions.pop('tags')
    assert sum(col_proportions.values()) == 13
    form = ProblemsetSourceForm("")

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

    origintags = {}
    for param in request.GET.getlist('origin'):
        param = param.split('_')
        if len(param) in (1, 2):
            if param[0] not in origintags:
                origintags[param[0]] = []
            if len(param) == 2:
                origintags[param[0]].append(param[1])
        else:
            raise Http404

    return TemplateResponse(
        request, 'problems/problemset/problem-list.html', {
            'problems': problems,
            'navbar_links': navbar_links,
            'problemset_tabs': problemset_tabs,
            'page_title': page_title,
            'select_problem_src': request.GET.get('select_problem_src'),
            'problem_search': request.GET.get('q', ''),
            'tags': request.GET.getlist('tag'),
            'origintags': origintags,
            'algorithmtags': request.GET.getlist('algorithm'),
            'difficultytags': request.GET.getlist('difficulty'),
            'show_tags': show_tags,
            'show_statistics': show_statistics,
            'show_user_statistics': show_user_statistics,
            'show_filters': show_filters,
            'show_search_bar': True,
            'show_add_button': show_add_button,
            'administered_recent_contests': administered_recent_contests,
            'col_proportions': col_proportions,
            'form': form,
            'view_type': view_type
        })