Esempio 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)
    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,
               'administered_recent_contests': administered_recent_contests,
               'navbar_links': navbar_links}
    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)
Esempio n. 2
0
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)
Esempio n. 3
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)
    context = {
        "problem": problem,
        "package": package if package and package.package_file else None,
        "can_admin_problem": can_admin_problem(request, problem),
        "select_problem_src": request.GET.get("select_problem_src"),
        "show_add_button": show_add_button,
        "administered_recent_contests": administered_recent_contests,
    }
    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 + "?" + urllib.urlencode(tab_link_params)

    return tabbed_view(
        request, "problems/problemset/problem_site.html", context, problem_site_tab_registry, tab_kwargs, build_link
    )
Esempio n. 4
0
def problem_site_external_statement_view(request, site_key):
    problem = get_object_or_404(Problem, problemsite__url_key=site_key)
    statement = query_statement(problem.id)
    if statement.extension == '.zip' \
            and not can_admin_problem(request, problem):
        raise PermissionDenied
    return stream_file(statement.content, statement.download_name)
Esempio n. 5
0
 def has_change_permission(self, request, obj=None):
     if obj is None:
         return False
     problem = obj.problem
     if problem.main_problem_instance != obj:
         return False
     return can_admin_problem(request, problem)
Esempio n. 6
0
    def can_generate_user_out(self, request, submission_report):
        """Determines if the current user is allowed to generate outs from
           ``submission_report``.

           Default implementations allow only problem admins.
        """
        problem = submission_report.submission.problem_instance.problem
        return can_admin_problem(request, problem)
Esempio n. 7
0
    def get_default_submission_kind(self, request, problem_instance):
        """Returns default kind of newly created submission by the current
           user.

           The default implementation returns ``'IGNORED'`` for
           problem admins. In other cases it returns ``'NORMAL'``.
        """
        if can_admin_problem(request, problem_instance.problem):
            return 'IGNORED'
        return 'NORMAL'
Esempio n. 8
0
def _get_package(request, package_id):
    package = get_object_or_404(ProblemPackage, id=package_id)
    has_perm = False
    if package.contest:
        has_perm = request.user.has_perm("contests.contest_admin", package.contest)
    elif package.problem:
        has_perm = can_admin_problem(request, package.problem)
    else:
        has_perm = request.user.is_superuser
    if not has_perm:
        raise PermissionDenied
    return package
Esempio n. 9
0
    def get_submissions_limit(self, request, problem_instance, kind='NORMAL'):
        if kind != 'TESTRUN':
            return super(TestRunProblemControllerMixin, self) \
                    .get_submissions_limit(request, problem_instance, kind)

        if can_admin_problem(request, problem_instance.problem):
            return None

        if (hasattr(problem_instance.problem, 'test_run_config')
                and hasattr(problem_instance, 'test_run_config')):
            test_runs_limit = problem_instance.test_run_config.test_runs_limit
        else:
            test_runs_limit = settings.DEFAULT_TEST_RUNS_LIMIT

        return test_runs_limit
Esempio n. 10
0
    def _out_generate_status(self, request, testreport):
        problem = testreport.test.problem_instance.problem
        try:
            if can_admin_problem(request, problem) or \
                    testreport.userout_status.visible_for_user:
                # making sure, that output really exists or is processing
                if bool(testreport.output_file) or \
                        testreport.userout_status.status == '?':
                    return testreport.userout_status.status

        except UserOutGenStatus.DoesNotExist:
            if testreport.output_file:
                return 'OK'

        return None
Esempio n. 11
0
def problem_site_view(request, site_key):
    problem = get_object_or_404(Problem, problemsite__url_key=site_key)
    context = {'problem': problem,
               'can_admin_problem': can_admin_problem(request, problem),
               'select_problem_src': request.GET.get('select_problem_src')}
    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 + '?' + urllib.urlencode(tab_link_params)

    return tabbed_view(request, 'problems/problemset/problem_site.html',
            context, problem_site_tab_registry, tab_kwargs, build_link)
Esempio n. 12
0
    def filter_visible_reports(self, request, submission, queryset):
        """Determines which reports the user should be able to see.

        It needs to check whether the submission is visible to the user
        and submission is submitted without contest.

        :param request: Django request
        :param submission: instance of
                           :class:`~oioioi.contests.models.Submission`
        :param queryset: a queryset, initially filtered at least to
                           select only given submission's reports
        :returns: updated queryset
        """
        assert not submission.problem_instance.contest
        problem = submission.problem_instance.problem
        if can_admin_problem(request, problem):
            return queryset
        return queryset.filter(status='ACTIVE', kind='NORMAL')
Esempio n. 13
0
    def filter_visible_reports(self, request, submission, queryset):
        """Determines which reports the user should be able to see.

           It needs to check whether the submission is visible to the user
           and submission is submitted without contest.

           :param request: Django request
           :param submission: instance of
                              :class:`~oioioi.contests.models.Submission`
           :param queryset: a queryset, initially filtered at least to
                              select only given submission's reports
           :returns: updated queryset
        """
        assert not submission.problem_instance.contest
        problem = submission.problem_instance.problem
        if can_admin_problem(request, problem):
            return queryset
        return queryset.filter(status='ACTIVE', kind='NORMAL')
Esempio n. 14
0
    def inline_actions(self, instance):
        result = []
        assert ProblemSite.objects.filter(problem=instance.problem).exists()
        move_href = self._move_href(instance)
        result.append((move_href, _("Edit")))
        is_quiz = hasattr(instance.problem, 'quiz') and instance.problem.quiz
        if is_quiz:
            edit_quiz_href = self._edit_quiz_href(instance)
            result.append((edit_quiz_href, _("Quiz questions")))
        else:
            models_href = self._model_solutions_href(instance)
            limits_href = self._reset_limits_href(instance)
            result.extend([
                (models_href, _("Model solutions")),
                (limits_href, _("Reset tests limits")),
            ])
        reattach_href = self._reattach_problem_href(instance)
        result.append((reattach_href, _("Attach to another contest")))
        problem_count = len(
            ProblemInstance.objects.filter(problem=instance.problem_id))
        # Problem package can only be reuploaded if the problem instance
        # is only in one contest and in the problem base
        # Package reupload does not apply to quizzes.
        if problem_count <= 2 and not is_quiz:
            add_or_update_href = self._add_or_update_href(instance)
            result.append((add_or_update_href, _("Reupload package")))
        if instance.needs_rejudge:
            rejudge_all_href = self._rejudge_all_submissions_for_problem_href(
                instance)
            result.append(
                (rejudge_all_href, _("Rejudge all submissions for problem")))
            rejudge_not_needed_href = self._set_needs_rejudge_to_false_href(
                instance)
            result.append((rejudge_not_needed_href, _("Rejudge not needed")))

        problem_change_href = self._problem_change_href(instance)
        replace_statement_href = self._replace_statement_href(instance)
        package_manage_href = self._package_manage_href(instance)
        request = self._request_local.request
        if can_admin_problem(request, instance.problem):
            result.append((problem_change_href, _("Advanced settings")))
            result.append((replace_statement_href, _("Replace statement")))
            result.append((package_manage_href, _("Edit package")))
        return result
Esempio n. 15
0
    def _out_generate_status(self, request, testreport):
        problem = testreport.test.problem_instance.problem
        try:
            if (
                can_admin_problem(request, problem)
                or testreport.userout_status.visible_for_user
            ):
                # making sure, that output really exists or is processing
                if (
                    bool(testreport.output_file)
                    or testreport.userout_status.status == '?'
                ):
                    return testreport.userout_status.status

        except UserOutGenStatus.DoesNotExist:
            if testreport.output_file:
                return 'OK'

        return None
Esempio n. 16
0
    def filter_my_visible_submissions(self, request, queryset):
        """Returns the submissions which the user should see in the
           problemset in "My submissions" view.

           The default implementation returns all submissions belonging to
           the user for current problem except for author, who
           gets all his submissions.

           Should return the updated queryset.
        """
        if not request.user.is_authenticated:
            return queryset.none()
        qs = queryset \
            .filter(problem_instance=self.problem.main_problem_instance)
        if can_admin_problem(request, self.problem):
            return qs.filter(Q(user=request.user) | Q(user__isnull=True))
        else:
            return qs.filter(user=request.user, date__lte=request.timestamp) \
            .exclude(kind='IGNORED_HIDDEN')
Esempio n. 17
0
    def filter_my_visible_submissions(self, request, queryset):
        """Returns the submissions which the user should see in the
           problemset in "My submissions" view.

           The default implementation returns all submissions belonging to
           the user for current problem except for author, who
           gets all his submissions.

           Should return the updated queryset.
        """
        if not request.user.is_authenticated():
            return queryset.none()
        qs = queryset \
            .filter(problem_instance=self.problem.main_problem_instance)
        if can_admin_problem(request, self.problem):
            return qs.filter(Q(user=request.user) | Q(user__isnull=True))
        else:
            return qs.filter(user=request.user, date__lte=request.timestamp) \
            .exclude(kind='IGNORED_HIDDEN')
Esempio n. 18
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)
    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
        })
Esempio n. 19
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,
        'problemsite_key': site_key,
        '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)
Esempio n. 20
0
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,
    )
Esempio n. 21
0
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)
Esempio n. 22
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)
    context = {'problem': problem,
               'package': package if package and package.package_file
                        else None,
               'can_admin_problem': can_admin_problem(request, problem),
               'select_problem_src': request.GET.get('select_problem_src'),
               'show_add_button': show_add_button,
               'administered_recent_contests': administered_recent_contests}
    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 + '?' + urllib.urlencode(tab_link_params)

    return tabbed_view(request, 'problems/problemset/problem_site.html',
            context, problem_site_tab_registry, tab_kwargs, build_link)
Esempio n. 23
0
 def has_change_permission(self, request, obj=None):
     if obj is None:
         return self.get_queryset(request).exists()
     return can_admin_problem(request, obj)
Esempio n. 24
0
 def has_change_permission(self, request, obj=None):
     if obj is None:
         return self.get_queryset(request).exists()
     else:
         return can_admin_problem(request, obj)
Esempio n. 25
0
    def get_submissions_limit(self, request, problem_instance):
        problem = problem_instance.problem

        if can_admin_problem(request, problem):
            return None
        return problem_instance.submissions_limit
Esempio n. 26
0
    def get_submissions_limit(self, request, problem_instance):
        problem = problem_instance.problem

        if can_admin_problem(request, problem):
            return None
        return problem_instance.submissions_limit
Esempio n. 27
0
def download_extra_file_view(request, file_id):
    file = get_object_or_404(ExtraFile, id=file_id)
    if not can_admin_problem(request, file.problem):
        raise PermissionDenied
    return stream_file(file.file)
Esempio n. 28
0
 def check_repeated_submission(self, request, problem_instance, form):
     return not can_admin_problem(request, problem_instance.problem) \
             and form.kind == 'NORMAL' and \
             getattr(settings, 'WARN_ABOUT_REPEATED_SUBMISSION', False)
Esempio n. 29
0
def model_solutions_view(request, problem_instance_id):
    problem_instance = \
        get_object_or_404(ProblemInstance, id=problem_instance_id)
    problem = problem_instance.problem
    contest = problem_instance.contest
    if (contest is None and not can_admin_problem(request, problem)) or \
            (contest and
             not request.user.has_perm('contests.contest_admin', contest)):
        raise PermissionDenied

    filter_kwargs = {
        'test__isnull': False,
        'submission_report__submission__problem_instance':
            problem_instance,
        'submission_report__submission__programsubmission'
                '__modelprogramsubmission__isnull': False,
        'submission_report__status': 'ACTIVE',
    }
    test_reports = TestReport.objects.filter(**filter_kwargs) \
            .select_related()
    filter_kwargs = {
        'submission_report__submission__problem_instance':
            problem_instance,
        'submission_report__submission__programsubmission'
                '__modelprogramsubmission__isnull': False,
        'submission_report__status': 'ACTIVE',
    }
    group_reports = GroupReport.objects.filter(**filter_kwargs) \
            .select_related()
    submissions = ModelProgramSubmission.objects \
            .filter(problem_instance=problem_instance) \
            .order_by('model_solution__order_key') \
            .select_related('model_solution') \
            .all()
    tests = problem_instance.test_set \
            .order_by('order', 'group', 'name').all()

    group_results = defaultdict(lambda: defaultdict(lambda: None))
    for gr in group_reports:
        group_results[gr.group][gr.submission_report.submission_id] = gr

    test_results = defaultdict(lambda: defaultdict(lambda: None))
    for tr in test_reports:
        test_results[tr.test_id][tr.submission_report.submission_id] = tr

    submissions_percentage_statuses = {s.id: '25' for s in submissions}
    rows = []
    submissions_row = []
    for t in tests:
        row_test_results = test_results[t.id]
        row_group_results = group_results[t.group]
        percentage_statuses = {s.id: '100' for s in submissions}
        for s in submissions:
            if row_test_results[s.id] is not None:
                time_ratio = float(row_test_results[s.id].time_used) / \
                        row_test_results[s.id].test_time_limit
                if time_ratio <= 0.25:
                    percentage_statuses[s.id] = '25'
                elif time_ratio <= 0.50:
                    percentage_statuses[s.id] = '50'
                    if submissions_percentage_statuses[s.id] is not '100':
                        submissions_percentage_statuses[s.id] = '50'
                else:
                    percentage_statuses[s.id] = '100'
                    submissions_percentage_statuses[s.id] = '100'

        rows.append({
            'test': t,
            'results': [{
                    'test_report': row_test_results[s.id],
                    'group_report': row_group_results[s.id],
                    'is_partial_score': s.problem_instance.controller
                        ._is_partial_score(row_test_results[s.id]),
                    'percentage_status': percentage_statuses[s.id]
                    }
                for s in submissions
                ]
        })

    for s in submissions:
        status = s.status
        if s.status == 'OK' or s.status == 'INI_OK':
            status = 'OK' + submissions_percentage_statuses[s.id]

        submissions_row.append({
            'submission': s,
            'status': status
            })

    context = {
            'problem_instance': problem_instance,
            'submissions_row': submissions_row,
            'submissions': submissions,
            'rows': rows
    }

    return TemplateResponse(request, 'programs/admin/model_solutions.html',
            context)
Esempio n. 30
0
 def check_repeated_submission(self, request, problem_instance, form):
     return not can_admin_problem(request, problem_instance.problem) \
             and form.kind == 'NORMAL' and \
             getattr(settings, 'WARN_ABOUT_REPEATED_SUBMISSION', False)
Esempio n. 31
0
 def can_see_test(self, request, test):
     return can_admin_problem(request, self.problem)
Esempio n. 32
0
 def is_admin(self, request, report):
     return can_admin_problem(request, self.problem)
Esempio n. 33
0
 def is_admin(self, request, report):
     return can_admin_problem(request, self.problem)
Esempio n. 34
0
def test_view_for_problem(request, package_id):
    tp = get_object_or_404(TestsPackage, id=package_id)
    if not can_admin_problem(request, tp.problem):
        raise PermissionDenied
    return get_tests_package_file(tp)
Esempio n. 35
0
 def can_see_checker_exe(self, request, checker):
     return can_admin_problem(request, self.problem)
Esempio n. 36
0
def download_extra_file_view(request, file_id):
    file = get_object_or_404(ExtraFile, id=file_id)
    if not can_admin_problem(request, file.problem):
        raise PermissionDenied
    return stream_file(file.file)