Пример #1
0
    def post(self, request, *args, **kwargs):
        form = self.form_class(request.POST, request.FILES)

        if form.is_valid():
            data = dict(
                user=request.user,
                problem=Problem.objects.get(pk=form.cleaned_data['problem'])
            )

            try:
                submission =  UserSolution.objects.get(**data)
            except UserSolution.DoesNotExist:
                submission = UserSolution(**data)

            # do not save and return if user does not have filled profile
            try:
                userprofile = UserProfile.objects.get(user = data['user'])
                required_attrs = ('school', 'school_class', 'classlevel')
                
                for attr in required_attrs:
                    if (getattr(userprofile, attr, None) is None):               
                        raise ValidationError(_('incomplete_profile'))
                        
            except (ValidationError, UserProfile.DoesNotExist):
                messages.error(
                    request, 
                    _("User profile does not contain all required fields. "
                        "Please update your profile.")
                    )
                return redirect('competitions_season_detail_latest')
            
            # save submission 
            try:
                filelist = request.FILES.getlist('solution')
                submission.solution = convert_files_to_single_pdf(
                                          settings.SENDFILE_ROOT,
                                          submission.get_solution_path(),
                                          filelist)
                submission.user_modified_at = now()
                submission.save()
                
                # warn user if converting files could have gone wrong
                risky_extensions = ['.doc', '.docx']
                for file in filelist:
                    for extension in risky_extensions:
                        if file.name.endswith(extension):
                            messages.error(
                                request, 
                                _('Converting %s files to .pdf sometimes does not work properly, '
                                    'please check the result!' %" ".join(risky_extensions))
                                )
                         
            except ValidationError, e:
                messages.error(request, u'\n'.join(e.messages))
Пример #2
0
    def post(self, request, *args, **kwargs):
        form = self.form_class(request.POST, request.FILES)

        if form.is_valid():
            data = dict(
                user=request.user,
                problem=Problem.objects.get(pk=form.cleaned_data['problem']))

            try:
                submission = UserSolution.objects.get(**data)
            except UserSolution.DoesNotExist:
                submission = UserSolution(**data)

            # do not save and return if user does not have filled profile
            try:
                userprofile = UserProfile.objects.get(user=data['user'])
                required_attrs = ('school', 'school_class', 'classlevel')

                for attr in required_attrs:
                    if (getattr(userprofile, attr, None) is None):
                        raise ValidationError(_('incomplete_profile'))

            except (ValidationError, UserProfile.DoesNotExist):
                messages.error(
                    request,
                    _("User profile does not contain all required fields. "
                      "Please update your profile."))
                return redirect('competitions_season_detail_latest')

            # save submission
            try:
                filelist = request.FILES.getlist('solution')
                submission.solution = convert_files_to_single_pdf(
                    settings.SENDFILE_ROOT, submission.get_solution_path(),
                    filelist)
                submission.user_modified_at = now()
                submission.save()

                # warn user if converting files could have gone wrong
                risky_extensions = ['.doc', '.docx']
                for file in filelist:
                    for extension in risky_extensions:
                        if file.name.endswith(extension):
                            messages.error(
                                request,
                                _('Converting %s files to .pdf sometimes does not work properly, '
                                  'please check the result!' %
                                  " ".join(risky_extensions)))

            except ValidationError, e:
                messages.error(request, u'\n'.join(e.messages))
Пример #3
0
    def post(self, request, *args, **kwargs):
        form = self.form_class(request.POST, request.FILES)

        if form.is_valid():
            data = dict(
                user=request.user,
                problem=Problem.objects.get(pk=form.cleaned_data['problem']))

            # Since series is a part of the POST request, check that problem belongs to this series and that
            # this series is not past its deadline

            series = Series.objects.get(pk=form.cleaned_data['series'])

            if series.is_past_submission_deadline():
                messages.error(request,
                               _("Series is past its submission deadline"))
                return redirect('competitions_season_detail_latest',
                                competition_id=1)

            if not series.problemset.problems.filter(
                    pk=form.cleaned_data['problem']).exists():
                messages.error(request,
                               _("Problem does not belong to the series"))
                return redirect('competitions_season_detail_latest',
                                competition_id=1)

            try:
                submission = UserSolution.objects.get(**data)
            except UserSolution.DoesNotExist:
                submission = UserSolution(**data)

            try:
                filelist = request.FILES.getlist('solution')
                submission.solution = convert_files_to_single_pdf(
                    settings.SENDFILE_ROOT, submission.get_solution_path(),
                    filelist)
                submission.user_modified_at = now()
                submission.save()
            except ValidationError, e:
                messages.error(request, u'\n'.join(e.messages))
Пример #4
0
    def post(self, request, *args, **kwargs):
        form = self.form_class(request.POST, request.FILES)

        if form.is_valid():
            data = dict(
                user=request.user,
                problem=Problem.objects.get(pk=form.cleaned_data['problem'])
            )

            # Since series is a part of the POST request, check that problem belongs to this series and that
            # this series is not past its deadline

            series = Series.objects.get(pk=form.cleaned_data['series'])

            if series.is_past_submission_deadline():
                messages.error(request, _("Series is past its submission deadline"))
                return redirect('competitions_season_detail_latest', competition_id=1)

            if not series.problemset.problems.filter(pk=form.cleaned_data['problem']).exists():
                messages.error(request, _("Problem does not belong to the series"))
                return redirect('competitions_season_detail_latest', competition_id=1)

            try:
                submission =  UserSolution.objects.get(**data)
            except UserSolution.DoesNotExist:
                submission = UserSolution(**data)

            try:
                filelist = request.FILES.getlist('solution')
                submission.solution = convert_files_to_single_pdf(
                                          settings.SENDFILE_ROOT,
                                          submission.get_solution_path(),
                                          filelist)
                submission.user_modified_at = now()
                submission.save()
            except ValidationError, e:
                messages.error(request, u'\n'.join(e.messages))