示例#1
0
    def clean_pid(self):
        pid = self.cleaned_data['pid']
        if not unicode(pid).isnumeric():
            raise forms.ValidationError("Problem ID must be a number")
        try:
            problem = Problem.objects.get(id=pid)
            if not user_info.has_problem_auth(self.user, problem):
                raise forms.ValidationError("You don't have permission to submit that problem")
        except Problem.DoesNotExist:
            logger.warning('Pid %s doe not exist' % pid)
            raise forms.ValidationError('Problem of this pid does not exist')

        return pid
示例#2
0
    def clean_pid(self):
        pid = self.cleaned_data['pid']
        if not unicode(pid).isnumeric():
            raise forms.ValidationError("Problem ID must be a number")
        try:
            problem = Problem.objects.get(id=pid)
            if not user_info.has_problem_auth(self.user, problem):
                raise forms.ValidationError(
                    "You don't have permission to submit that problem")
        except Problem.DoesNotExist:
            logger.warning('Pid %s doe not exist' % pid)
            raise forms.ValidationError('Problem of this pid does not exist')

        return pid
示例#3
0
def detail(request, pid):
    user = validate_user(request.user)
    tag_form = TagForm()
    try:
        problem = Problem.objects.get(pk=pid)
        if not has_problem_auth(user, problem):
            logger.warning("%s has no permission to see problem %d" % (user, problem.pk))
            raise PermissionDenied()
    except Problem.DoesNotExist:
        logger.warning('problem %s not found' % (pid))
        raise Http404('problem %s does not exist' % (pid))
    problem.testcase = get_testcase(problem)
    problem = verify_problem_code(problem)
    return render_index(request, 'problem/detail.html', {'problem': problem, 'tag_form': tag_form})
示例#4
0
def detail(request, pid):
    user = validate_user(request.user)
    tag_form = TagForm()
    try:
        problem = Problem.objects.get(pk=pid)
        if not has_problem_auth(user, problem):
            logger.warning(
                "%s has no permission to see problem %d" % (user, problem.pk))
            raise PermissionDenied()
    except Problem.DoesNotExist:
        logger.warning('problem %s not found' % (pid))
        raise Http404('problem %s does not exist' % (pid))
    problem.testcase = get_testcase(problem)
    problem = verify_problem_code(problem)
    problem.in_contest = check_in_contest(problem)
    return render_index(request, 'problem/detail.html', {'problem': problem, 'tag_form': tag_form})
示例#5
0
def download_partial(request, filename):
    pid = filename.split('.')[0]
    try:
        problem = Problem.objects.get(pk=pid)
    except:
        raise Http404()
    if not has_problem_auth(request.user, problem):
        logger.warning("%s has no permission to download problem %d partial judge code"
                       % (request.user, problem.pk))
        raise Http404()
    try:
        f = open(PARTIAL_PATH + filename, "r")
    except IOError:
        raise Http404()
    response = HttpResponse(FileWrapper(f), content_type="text/plain")
    response['Content-Disposition'] = 'attachment; filename=' + filename
    return response