Пример #1
0
 def post(self):
     per_page = app.config['SEARCH_RESULTS_PER_PAGE']
     args = search_parser.parse_args()
     args = dict([(key, value) for (key, value) in args.items()
                  if key is not None])
     if 'page' not in args:
         abort(400, message="must specify page")
     if not any(key in args
                for key in ['student_id', 'team_id', 'project_id']):
         abort(400, message="must have at least one query field")
     students = Student.objects(
         db.Q(team_id=args.get('team_id'))
         | db.Q(guc_id=args.get('guc_id')))
     if 'project_id' in args:
         if len(students) > 0:
             subs = (Submission.objects(
                 submitter__in=students,
                 project=Project.objects(id=args['project_id'])).order_by(
                     '-created_at').paginate(args['page'], per_page))
         else:
             subs = (Submission.objects(project=Project.objects(
                 id=args['project_id'])).order_by('-created_at').paginate(
                     args['page'], per_page))
     else:
         subs = Submission.objects(
             submitter__in=students).order_by('-created_at').paginate(
                 args['page'], per_page)
     return mongo_paginate_to_dict(subs, 'submissions')
Пример #2
0
 def get(self, id):
     """
     Lists all grades related to the user.
     """
     user = User.objects.get_or_404(id=id)
     return [
         sub.to_dict() for sub in Submission.objects(
             submitter=user).order_by('-created_at')
     ]
Пример #3
0
 def get(self, course_name, name, page=1):
     try:
         course = Course.objects.get(name=course_name)
     except:
         abort(404, message="Course not found")
     try:
        project = Project.objects.get(name=name, course=course)
     except: 
         abort(404, message="Project not found")
     per_page = api.app.config['SUMBISSIONS_PAGE_SIZE']
     if isinstance(g.user, Student) and project.published:
         # Filter all submissions            
         subs = Submission.objects(submitter=g.user,
             project=project).order_by('-created_at').paginate(page,
             per_page)
         return mongo_paginate_to_dict(subs, 'submissions')
     elif g.user in course.teachers:
         # No need to filter
         subs = Submission.objects(project=project).order_by('-created_at').paginate(page, per_page)
         return mongo_paginate_to_dict(subs, 'submissions')
     else:
         abort(403, message="You are not a student or course teacher.")  # not a student and not a course teacher
Пример #4
0
def junit_task(submission_id):
    submission = junit_actual(submission_id)
    if submission is not None:
        for sub in [
                s for s in Submission.objects(submitter=submission.submitter,
                                              project=submission.project,
                                              processed=True).order_by(
                                                  '-created_at')[10:]
        ]:
            app.logger.info(
                'Deleting submission id {0}, submitter {1}, project {2}'.
                format(sub.id, sub.submitter.name, sub.project.name))
            sub.delete()
            app.logger.info('Submission deleted')
Пример #5
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