Beispiel #1
0
    def test_mailsubmissions_list(self):
        c1 = Contest(id='contest1', name='Contest1', controller_name=
            'oioioi.participants.tests.ParticipantsContestController')
        c1.save()
        c2 = Contest(id='contest2', name='Contest2', controller_name=
            'oioioi.participants.tests.ParticipantsContestController')
        c2.save()
        p = Problem.objects.get()
        pi1 = ProblemInstance(contest=c1, problem=p,
            short_name='problem_instance1')
        pi1.save()
        pi2 = ProblemInstance(contest=c2, problem=p,
            short_name='problem_instance2')
        pi2.save()
        u = User.objects.get(username='******')
        f = ContentFile('aaa', name='bbbb.cpp')
        ms1 = MailSubmission(problem_instance=pi1, user=u)
        ms1.source_file.save(f.name, f)
        ms1.save()
        ms2 = MailSubmission(problem_instance=pi2, user=u)
        ms2.source_file.save(f.name, f)
        ms2.save()

        self.client.login(username='******')
        url = reverse('oioioiadmin:mailsubmit_mailsubmission_changelist',
            kwargs={'contest_id': 'contest1'})
        response = self.client.get(url)
        self.assertContains(response, 'problem_instance1')
        self.assertNotContains(response, 'problem_instance2')
        url = reverse('oioioiadmin:mailsubmit_mailsubmission_changelist',
            kwargs={'contest_id': 'contest2'})
        response = self.client.get(url)
        self.assertContains(response, 'problem_instance2')
        self.assertNotContains(response, 'problem_instance1')
Beispiel #2
0
    def test_mailsubmissions_list(self):
        c1 = Contest(
            id='contest1',
            name='Contest1',
            controller_name='oioioi.participants.'
            'tests.ParticipantsContestController',
        )
        c1.save()
        c2 = Contest(
            id='contest2',
            name='Contest2',
            controller_name='oioioi.participants.'
            'tests.ParticipantsContestController',
        )
        c2.save()
        p = Problem.objects.get()
        pi1 = ProblemInstance(contest=c1,
                              problem=p,
                              short_name='problem_instance1')
        pi1.save()
        pi2 = ProblemInstance(contest=c2,
                              problem=p,
                              short_name='problem_instance2')
        pi2.save()
        u = User.objects.get(username='******')
        f = ContentFile(b'aaa', name='bbbb.cpp')
        ms1 = MailSubmission(problem_instance=pi1, user=u)
        ms1.source_file.save(f.name, f)
        ms1.save()
        ms2 = MailSubmission(problem_instance=pi2, user=u)
        ms2.source_file.save(f.name, f)
        ms2.save()

        self.assertTrue(self.client.login(username='******'))
        url = reverse(
            'oioioiadmin:mailsubmit_mailsubmission_changelist',
            kwargs={'contest_id': 'contest1'},
        )
        response = self.client.get(url)
        self.assertContains(response, 'problem_instance1')
        self.assertNotContains(response, 'problem_instance2')
        url = reverse(
            'oioioiadmin:mailsubmit_mailsubmission_changelist',
            kwargs={'contest_id': 'contest2'},
        )
        response = self.client.get(url)
        self.assertContains(response, 'problem_instance2')
        self.assertNotContains(response, 'problem_instance1')
Beispiel #3
0
def mailsubmit_view(request):
    if request.method == 'POST':
        form = MailSubmissionForm(request, request.POST, request.FILES)
        if form.is_valid():
            mailsubmission = MailSubmission(
                user=form.cleaned_data.get('user', request.user),
                problem_instance=form.cleaned_data['problem_instance'],
                date=request.timestamp)
            source_file = form.cleaned_data['file']
            if source_file is None:
                lang_exts = getattr(settings, 'SUBMITTABLE_EXTENSIONS', {})
                extension = lang_exts[form.cleaned_data['prog_lang']][0]
                source_file = ContentFile(form.cleaned_data['code'],
                                          '__pasted_code.' + extension)

            mailsubmission.source_file.save(source_file.name, source_file)
            mailsubmission.save()
            return _generate_pdfdoc(request, mailsubmission)
    else:
        form = MailSubmissionForm(request)
    return TemplateResponse(request, 'mailsubmit/submit.html', {'form': form})
Beispiel #4
0
def mailsubmit_view(request):
    if request.method == 'POST':
        form = MailSubmissionForm(request, request.POST, request.FILES)
        if form.is_valid():
            mailsubmission = MailSubmission(
                user=form.cleaned_data.get('user', request.user),
                problem_instance=form.cleaned_data['problem_instance'],
                date=request.timestamp
            )
            source_file = form.cleaned_data['file']
            if source_file is None:
                lang_exts = getattr(settings, 'SUBMITTABLE_EXTENSIONS', {})
                extension = lang_exts[form.cleaned_data['prog_lang']][0]
                source_file = ContentFile(form.cleaned_data['code'],
                                   '__pasted_code.' + extension)

            mailsubmission.source_file.save(source_file.name, source_file)
            mailsubmission.save()
            return _generate_pdfdoc(request, mailsubmission)
    else:
        form = MailSubmissionForm(request)
    return TemplateResponse(request, 'mailsubmit/submit.html', {'form': form})