예제 #1
0
    def post(self, request, pk):
        self.problem = get_object_or_404(Problem, pk = pk)
        self.form = SolutionSubmitForm(request.POST)
        
        user = request.user

        if not self.form.is_valid():
            return self.render(request)

        try:
            data = UserProblemData.objects.get(user = user,
                                                problem = self.problem)

            nextSubmit = data.last_submit + datetime.timedelta(seconds = 30)

            if nextSubmit > timezone.now():
                timeLeft = nextSubmit - timezone.now()
                messageText = 'You can submit a solution once every 30 seconds.\
                    Try again in {0} seconds'. format(timeLeft.seconds)
                messages.warning(request, messageText)
                return self.render(request)

            else:
                data.last_submit = timezone.now()
                data.save()

        except UserProblemData.DoesNotExist:
            data = UserProblemData(user = user,
                                    problem = self.problem,
                                    last_submit = timezone.now())

            data.save()
            UserStatts.get_for_user(user).update_statts()

        source = self.form.cleaned_data['source']
        solution = Solution(
            source = source,
            submit_date = timezone.now(),
            user = user,
            problem = self.problem)

        solution.save()
        
        test_solution.delay(solution)

        url = reverse('judge:solution_details', args = (solution.pk,))
        return HttpResponseRedirect(url)
예제 #2
0
    def post(self, request, pk):
        self.problem = get_object_or_404(Problem, pk=pk)
        self.form = SolutionSubmitForm(request.POST)

        user = request.user

        if not self.form.is_valid():
            return self.render(request)

        try:
            data = UserProblemData.objects.get(user=user, problem=self.problem)

            nextSubmit = data.last_submit + datetime.timedelta(seconds=30)

            if nextSubmit > timezone.now():
                timeLeft = nextSubmit - timezone.now()
                messageText = 'You can submit a solution once every 30 seconds.\
                    Try again in {0} seconds'.format(timeLeft.seconds)
                messages.warning(request, messageText)
                return self.render(request)

            else:
                data.last_submit = timezone.now()
                data.save()

        except UserProblemData.DoesNotExist:
            data = UserProblemData(user=user,
                                   problem=self.problem,
                                   last_submit=timezone.now())

            data.save()
            UserStatts.get_for_user(user).update_statts()

        source = self.form.cleaned_data['source']
        solution = Solution(source=source,
                            submit_date=timezone.now(),
                            user=user,
                            problem=self.problem)

        solution.save()

        test_solution.delay(solution)

        url = reverse('judge:solution_details', args=(solution.pk, ))
        return HttpResponseRedirect(url)
예제 #3
0
def retest_problem(problem):
    solutions = problem.solution_set.all()

    with transaction.atomic():
        UPdata = UserProblemData.objects.filter(problem = problem)

        for sol in solutions:
            sol.testresult_set.all().delete()
            sol.testgroupresult_set.all().delete()
            sol.score = 0
            sol.grader_message = 'In Queue'
            sol.save()

            test_solution.delay(sol)

        for data in UPdata:
            data.max_score = 0
            data.save()
            UserStatts.get_for_user(data.user).update_statts()
예제 #4
0
def retest_problem(problem):
    solutions = problem.solution_set.all()

    with transaction.atomic():
        UPdata = UserProblemData.objects.filter(problem = problem)

        for sol in solutions:
            sol.testresult_set.all().delete()
            sol.testgroupresult_set.all().delete()
            sol.score = 0
            sol.grader_message = 'In Queue'
            sol.save()

            test_solution.delay(sol)

        for data in UPdata:
            data.max_score = 0
            data.save()
            UserStatts.get_for_user(data.user).update_statts()
예제 #5
0
    def get_context_data(self, **kwargs):
        details = [('Username', self.request.user.username),
                   ('E-mail', self.request.user.email)]

        try:
            from judge.models import UserStatts
            userStatts = UserStatts.get_for_user(self.request.user)

            details.extend([('Attempted problems', userStatts.tried_problems),
                            ('Solved problems', userStatts.solved_problems)])
        except ImportError:
            pass

        context = {'details': details}

        return context
예제 #6
0
    def get_context_data(self, **kwargs):
        details = [
            ('Username', self.request.user.username),
            ('E-mail', self.request.user.email)
        ]
        
        try:
            from judge.models import UserStatts
            userStatts = UserStatts.get_for_user(self.request.user)

            details.extend([
                ('Attempted problems', userStatts.tried_problems),
                ('Solved problems', userStatts.solved_problems)
            ])
        except ImportError:
            pass

        context = { 
            'details': details
        }

        return context