Пример #1
0
def add_submission(challenge_id):
    data = request.get_json()
    challenge = Challenge.query.get(challenge_id)

    if challenge is None:
        return NotFound("Challenge not found")

    current_time = datetime.utcnow()

    if current_time >= challenge.expires_on:
        return {"message": "Challenge expired. Cannot accept answers now"}, 400

    user = User.query.get(get_jwt_identity())

    submission = Submission(challenge=challenge,
                            user=user,
                            answer=data["answer"])
    submission.save()

    return submission.serialize(), 201
Пример #2
0
    def post(self, course_name, name, page=1):
        """Creates a new submission."""
        course = Course.objects.get_or_404(name=course_name)
        project = Project.objects.get_or_404(name=name)
        if len(Submission.objects(project=project, submitter=g.user, processed=False)) > 4:
            abort(429, message="Too many pending submissions") 
        if not g.user in course.students:
            abort(403, message="Must be a course student to submit")
        if not project in course.projects:
            abort(404, message="Project not found.")
        if not project.can_submit:
            abort(498, message="Due date has passed, tough luck!")
        if project.is_quiz:
            # Verify verification code
            args = submission_parser.parse_args()
            if g.user.verification_code != args['verification_code']:
                abort(400, message="Invalid verification code.")
                

        if len(request.files.values()) == 1:
            subm = Submission(submitter=g.user, project=project)
            for file in request.files.values():
                if allowed_code_file(file.filename):
                    grid_file = db.GridFSProxy()
                    grid_file.put(
                        file, filename=secure_filename(file.filename), content_type=file.mimetype)
                    subm.code = grid_file
                else:
                    abort(400, message="Only {0} files allowed".format(','.join(api.app.config['ALLOWED_CODE_EXTENSIONS'])))
            subm.save()
            project.submissions.append(subm)
            project.save()
            if api.app.config['DELETE_SUBMISSIONS']:
                junit_task.delay(str(subm.id))
            else:
                junit_no_deletion.delay(str(subm.id))
            return marshal(subm.to_dict(parent_course=course, parent_project=project), submission_fields), 201
        else:
            abort(400, message="Can only submit one file.")  # Bad request