def toggle_approval_submission(code, submission_id): activity = Activity.query.filter_by(code=code).first() if not activity: raise InvalidUsage.item_not_found() submission = Submission.query.filter_by(activity=activity, id=submission_id).first() if not submission: raise InvalidUsage.item_not_found() new_approved_state = not submission.approved submission.update(approved=new_approved_state) submission.save() return submission
def submit_submission(code, author, **kwargs): activity = Activity.query.filter_by(code=code).first() if not activity: raise InvalidUsage.item_not_found() if 'submitted_file' in kwargs and kwargs['submitted_file'] is not None: uploaded_file = kwargs.pop('submitted_file') if uploaded_file.filename == '': raise InvalidUsage.no_files_found() filename_original, file_extension = os.path.splitext( secure_filename(uploaded_file.filename)) filename = '{}{}'.format(uuid.uuid4().hex, file_extension) uploaded_file.save( os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], filename)) file_url = '/uploads/{}'.format(filename) file_size = os.path.getsize( os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], filename)) file_object = File(filename=filename, url=file_url, filemime=uploaded_file.mimetype, filename_original=uploaded_file.filename, filesize=file_size) file_object.save() else: raise InvalidUsage.no_files_found() file_type = kwargs.get('file_type') if not file_type: if file_extension in ['.png', '.jpg', '.gif', '.jpeg']: file_type = 'image' elif file_extension in ['.mp4']: file_type = 'video' submission = Submission(author=author, file=file_object, activity=activity, file_type=file_type).save() return submission
def get_activity_reactions(classroom_slug, code): classroom = Classroom.query.filter_by(slug=classroom_slug).first() if not classroom: raise InvalidUsage.classroom_not_found() activity = Activity.query.filter_by(classroom=classroom, code=code).first() if not activity: raise InvalidUsage.item_not_found() return activity.reactions
def get_activity_submissions_by_code(code): activity = Activity.query.filter_by(code=code).first() if not activity: raise InvalidUsage.item_not_found() submissions = Submission.query.filter_by( activity=activity, approved=True).order_by(Submission.created_at.desc()).all() return {'activity': activity, 'submissions': submissions}
def get_activity_submissions(code, classroom_slug): activity = Activity.query.join( Activity.classroom).filter(Classroom.slug == classroom_slug).filter( Activity.code == code).first() if not activity: raise InvalidUsage.item_not_found() submissions = Submission.query.filter_by(activity=activity).order_by( Submission.created_at.desc()).all() return {'activity': activity, 'submissions': submissions}
def get_activity(code): activity = Activity.query.filter_by(code=code).first() if not activity: raise InvalidUsage.item_not_found() return activity