Exemplo n.º 1
0
def problem_site_view(request, site_key):
    problem = get_object_or_404(Problem, problemsite__url_key=site_key)
    package = ProblemPackage.objects.filter(problem=problem).first()
    show_add_button, administered_recent_contests = \
        generate_add_to_contest_metadata(request)
    extra_actions = problem.controller.get_extra_problem_site_actions(problem)
    navbar_links = navbar_links_registry.template_context(request)
    problemset_tabs = generate_problemset_tabs(request)
    problemset_tabs.append({'name': _('Problem view'), 'url': reverse('problem_site', kwargs={'site_key': site_key})})
    context = {'problem': problem,
               'package': package if package and package.package_file
                        else None,
               'extra_actions': extra_actions,
               'can_admin_problem': can_admin_problem(request, problem),
               'select_problem_src': request.GET.get('select_problem_src'),
               'show_add_button': show_add_button,
               'show_proposal_form': show_proposal_form(problem, request.user),
               'administered_recent_contests': administered_recent_contests,
               'navbar_links': navbar_links,
               'problemset_tabs': problemset_tabs}
    tab_kwargs = {'problem': problem}

    tab_link_params = request.GET.dict()
    if 'page' in tab_link_params:
        del tab_link_params['page']

    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, 'problems/problemset/problem-site.html',
            context, problem_site_tab_registry, tab_kwargs, build_link)
Exemplo n.º 2
0
def problem_site_settings(request, problem):
    show_add_button, administered_recent_contests = generate_add_to_contest_metadata(request)
    package = ProblemPackage.objects.filter(problem=problem).first()
    problem_instance = get_object_or_404(ProblemInstance, id=problem.main_problem_instance_id)
    model_solutions = generate_model_solutions_context(request, problem_instance)
    extra_actions = problem.controller.get_extra_problem_site_actions(problem)
    algorithm_tag_proposals = AlgorithmTagProposal.objects.all().filter(problem=problem).order_by('-pk')[:25]
    return TemplateResponse(request, 'problems/settings.html',
                            {'site_key': problem.problemsite.url_key,
                             'problem': problem, 'administered_recent_contests': administered_recent_contests,
                             'package': package if package and package.package_file else None,
                             'model_solutions': model_solutions,
                             'algorithm_tag_proposals': algorithm_tag_proposals,
                             'can_admin_problem': can_admin_problem(request, problem),
                             'extra_actions': extra_actions})
Exemplo n.º 3
0
def problem_site_settings(request, problem):
    show_add_button, administered_recent_contests = generate_add_to_contest_metadata(
        request)
    package = ProblemPackage.objects.filter(problem=problem).first()
    model_solutions = generate_model_solutions_context(
        request, problem.main_problem_instance_id)
    extra_actions = problem.controller.get_extra_problem_site_actions(problem)
    return TemplateResponse(
        request, 'problems/settings.html', {
            'site_key': problem.problemsite.url_key,
            'problem': problem,
            'administered_recent_contests': administered_recent_contests,
            'package': package if package and package.package_file else None,
            'model_solutions': model_solutions,
            'can_admin_problem': can_admin_problem(request, problem),
            'extra_actions': extra_actions
        })
Exemplo n.º 4
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
        })