예제 #1
0
def json(request, template = 'submission/download_page.html'):
    import json
    from django.template.defaultfilters import capfirst
    # The submission ids that we are looking for are sent via GET
    try:
        ids = map(lambda x: int(x), request.GET.get('submissions', '').split(','))
        graded = Submission.user_summary(request.user).filter(pk__in=ids).exclude(result=None)
        graded = dict([(sub.id, sub.result.diff and reverse('diff', args=[sub.id]) or capfirst(sub.result.status)) for sub in graded])
    except ValueError:
        # Invalid value for submissions, int() failed
        graded = {}
    response = json.dumps(graded)
    response = HttpResponse(response, mimetype='application/json')
    response['Cache-Control'] = 'no-cache'
    return response
예제 #2
0
class SampleResult(Result):
    temp_input = None
    submission = Submission(id=0)

    @property
    @contextmanager
    def expected_output_file(self):
        with open(os.path.join(settings.MEDIA_ROOT, 'sample.out')) as f:
            yield f

    @property
    @contextmanager
    def user_output_file(self):
        with self.temp_input as f:
            yield f

    def __init__(self, temp_input, user, *args, **kwargs):
        self.temp_input = temp_input
        self.submission.registrant = user
        super(SampleResult, self).__init__(*args, **kwargs)
예제 #3
0
def download(request, template='submission/download_page.html'):
    problems = Problem.objects.all()
    submissions = Submission.user_summary(request.user)

    correct = set()
    for sub in submissions:
        # Because we don't know if there is a result yet, and it is not a
        # member of the Submission model, we need to use a try-except block
        try:
            if sub.result.status == 'success':
                correct.add(sub.attempt.problem.slug)
        except:
            pass

    problems = [(p.id, p.name, p.slug in correct) for p in problems]

    context = {'submissions': submissions, 'problems': problems}
    return render_to_response(template,
                              context,
                              context_instance=RequestContext(request))
예제 #4
0
def json(request, template='submission/download_page.html'):
    import json
    from django.template.defaultfilters import capfirst
    # The submission ids that we are looking for are sent via GET
    try:
        ids = map(lambda x: int(x),
                  request.GET.get('submissions', '').split(','))
        graded = Submission.user_summary(
            request.user).filter(pk__in=ids).exclude(result=None)
        graded = dict([
            (sub.id, sub.result.diff and reverse('diff', args=[sub.id])
             or capfirst(sub.result.status)) for sub in graded
        ])
    except ValueError:
        # Invalid value for submissions, int() failed
        graded = {}
    response = json.dumps(graded)
    response = HttpResponse(response, mimetype='application/json')
    response['Cache-Control'] = 'no-cache'
    return response
예제 #5
0
def download(request, template = 'submission/download_page.html'):
    problems = Problem.objects.all()
    submissions = Submission.user_summary(request.user)

    correct = set()
    for sub in submissions:
        # Because we don't know if there is a result yet, and it is not a
        # member of the Submission model, we need to use a try-except block
        try:
            if sub.result.status == 'success':
                correct.add(sub.attempt.problem.slug)
        except:
            pass

    problems = [(p.id, p.name, p.slug in correct) for p in problems]

    context = {
        'submissions':submissions,
        'problems':problems
    }
    return render_to_response( template, context,
            context_instance=RequestContext(request))
예제 #6
0
def index(request, template='account/index.html'):
    context = {
        'submissions':Submission.user_summary(request.user)[:5]
    }
    return render_to_response(template, context,
            context_instance=RequestContext(request))