def add_chapter_check(course_id): form = AddLightChapterForm() if request.method == 'POST': if form.validate_on_submit(): course = LightCourse.query.get(course_id) course.chapters.append(LightChapter(name=form.name.data)) course.update() else: flash_errors(form) return redirect(url_for('lightcourse.view', course_id=course_id))
def add_homework_check(chapter_id): form = AddHomeworkForm() if request.method == 'POST': if form.validate_on_submit(): filename = docs.save(request.files[form.file_input.data.name]) homework = LightHomework(filename=filename) chapter = LightChapter.query.get(chapter_id) chapter.homeworks.append(homework) chapter.update() flash(notify_success('Homework file uploaded')) else: flash_errors(form) return redirect(url_for('lightcourse.view_chapter', chapter_id=chapter_id))
def resource_add_photos_check(chapter_id): form = AddPhotosForm() if request.method == 'POST': if form.validate_on_submit(): filename = photos.save(request.files[form.file_input.data.name]) resource = LightResource(type='photo', filename=filename) chapter = LightChapter.query.get(chapter_id) chapter.resources.append(resource) chapter.update() flash(notify_success('Photo file uploaded')) else: flash_errors(form) return redirect(url_for('lightcourse.view_chapter', chapter_id=chapter_id))
def resource_add_alldocs_check(chapter_id): form = AddDocsForm() if request.method == 'POST': if form.validate_on_submit(): filename = alldocs.save(request.files[form.file_input.data.name]) # filename = '{}_{}'.format(file_prefix(), filename) resource = LightResource(type='doc', filename=filename) chapter = LightChapter.query.get(chapter_id) chapter.resources.append(resource) chapter.update() flash(notify_success('Document file uploaded')) else: flash_errors(form) return redirect(url_for('lightcourse.view_chapter', chapter_id=chapter_id))
def submit_homework_check(chapter_id): form = SubmitHomeworkForm() if request.method == 'POST': if form.validate_on_submit(): filename = homeworksubmits.save( request.files[form.file_input.data.name]) homework_submit = LightHomeworkSubmission( filename=filename, course_taker_id=current_user.id) chapter = LightChapter.query.get(chapter_id) chapter.homework_submissions.append(homework_submit) chapter.update() flash(notify_success('Homework file submitted for evaluation')) else: flash_errors(form) return redirect(url_for('lightcourse.view_chapter', chapter_id=chapter_id))
def add_logo_check(): form = AddLogoForm() if request.method == 'POST': if form.validate_on_submit(): filename = photos.save(request.files[form.file_input.data.name]) logo = Setting.query.filter(Setting.name == 'logo').first() os.remove( os.path.join(current_app.config['UPLOADED_PHOTOS_DEST'], logo.value)) logo.value = filename logo.update() flash(notify_success('Logo uploaded')) return redirect(url_for('school.index')) else: flash_errors(form) return redirect(url_for('school.index'))
def subsection_add_homework_check(subsection_id): form = AddHomeworkForm() if request.method == 'POST': if form.validate_on_submit(): subsection = SubSection.query.get(subsection_id) filename = docs.save(request.files[form.homework_doc.data.name]) subsection.homeworks.append(Homework(filename=filename)) subsection.update() # flash(notify_info(form.homework_doc.data.name)) flash(notify_success('Homework file uploaded')) else: flash_errors(form) flash('ERROR! Homework') return redirect( url_for('course.subsection_add_homework', subsection_id=subsection_id))
def add_grade_check(): if request.method == 'POST': context = base_context() form = AddGradeForm() # if form.validate_on_submit(): if not form.validate_on_submit(): flash_errors(form) return redirect(url_for('student.index')) grade = Grade.query.filter(Grade.name == form.name.data).first() if grade: flash(notify_danger('Grade already exists!')) return redirect(url_for('student.index')) grade = Grade(name=form.name.data) grade.insert() flash(notify_success('Added grade {}!'.format(form.name.data))) return redirect(url_for('student.index'))
def subsection_submit_homework_check(subsection_id): form = SubmitHomeworkForm() if request.method == 'POST': if form.validate_on_submit(): subsection = SubSection.query.get(subsection_id) filename = homeworksubmits.save( request.files[form.homework_submit.data.name]) subsection.homework_submissions.append( HomeworkSubmission(filename=filename, course_taker_id=current_user.id)) subsection.update() # flash(notify_info(form.homework_doc.data.name)) flash(notify_success('Homework file submitted!')) else: flash_errors(form) return redirect( url_for('course.view_subsection', subsection_id=subsection_id))
def evaluate_homework_submission_check(submission_id): if request.method == 'POST': form = AddHomeworkNoteForm() if form.validate_on_submit(): submission = LightHomeworkSubmission.query.get(submission_id) course_taker_id = submission.course_taker_id chapter_id = submission.chapter_id notes = form.notes.data hwork_eval = LightHomeworkEvaluation( course_taker_id=course_taker_id, chapter_id=chapter_id, notes=notes, filename=submission.filename) submission.delete() hwork_eval.insert() else: flash_errors(form) return redirect(url_for('course.view_homework_submissions'))
def add_check(): if request.method == 'POST': context = base_context() form = AddTeacherForm() # if form.validate_on_submit(): if not form.validate_on_submit(): flash_errors(form) return redirect(url_for('teacher.index')) user = User.query.filter(User.email == form.email.data).first() if user: flash(notify_danger('Mail already exists!')) return redirect(url_for('teacher.index')) teacher = User(name=form.name.data, email=form.email.data, role='teacher') teacher.set_hash(current_app.config['DEFAULT_PASS_ALL']) teacher.insert() flash(notify_success('Added {}!'.format(teacher.name))) return redirect(url_for('teacher.index'))
def add_check(grade_id): if request.method == 'POST': context = base_context() form = AddStudentForm() # if form.validate_on_submit(): if not form.validate_on_submit(): flash_errors(form) return redirect(url_for('student.view', grade_id=grade_id)) user = User.query.filter(User.email == form.email.data).first() if user: flash(notify_danger('Mail already exists!')) return redirect(url_for('student.index')) student = User(name=form.name.data, email=form.email.data, role='student') grade = Grade.query.get(grade_id) student.grade = grade student.set_hash(current_app.config['DEFAULT_PASS_ALL']) student.insert() flash(notify_success('Added {}!'.format(form.email.data))) return redirect(url_for('student.view', grade_id=grade_id))