def delete(student_id): student = User.query.get(student_id) student_grade = student.grade email = student.email student.delete() flash(notify_danger('deleted user {}!'.format(email))) return redirect(url_for('student.view', grade_id=student_grade.id))
def delete_check(course_id): context = base_context() course = Course.query.get(course_id) if current_user.id == course.teacher_id or current_user.role == 'admin': course.delete() else: flash(notify_danger('No permission to delete')) return redirect(url_for('course.index'))
def submit(course_id): course = Course.query.get(course_id) if current_user.id == course.teacher_id or current_user.role == 'admin': course.submitted = True course.update() return redirect(url_for('course.view', course_id=course_id)) else: flash(notify_danger('No permission to submit')) return redirect(url_for('course.view', course_id=course_id))
def approve_certif_req(certif_req_id): certif_request = CertificateRequest.query.get(certif_req_id) course = Course.query.get(certif_request.course_id) if not course: flash(notify_warning('Course no longer exist')) certif_request.delete() return redirect(url_for('course.view_certificate_request')) if not (current_user.id == course.teacher_id or current_user.role == 'admin'): return "You don't have permission to approve" course_taker_id = certif_request.course_taker_id course_id = certif_request.course_id certif_request.delete() certif = Certificate(course_taker_id=course_taker_id, course_id=course_id) person = User.query.get(course_taker_id) course = Course.query.get(course_id) person_name = person.name.replace(' ', '_').replace('-', '_') course_name = course.name.replace(' ', '_') #flash(notify_info('{}'.format(os.getcwd()))) try: dirname = current_app.config['UPLOAD_CERTIFICATES_FOLDER'] try: os.mkdir(dirname) except: pass filename = "{}_{}.pdf".format(person_name, course_name) fname = os.path.join(dirname, filename) # flash(notify_info(fname)) #with open(fname, 'w+') as f: # f.write('') c = canvas.Canvas(fname) c.setTitle("Certificate") init_y = 250 c.drawString(100, init_y, "Certificate Awarded To") init_y -= 20 c.drawString(100, init_y, person.name) init_y -= 20 c.drawString(100, init_y, "For") init_y -= 20 c.drawString(100, init_y, course.name) init_y -= 20 c.drawString(100, init_y, "On") init_y -= 20 datetime_now = datetime.datetime.now() datenow = '{} - {} - {}'.format(datetime_now.year, datetime_now.month, datetime_now.day) c.drawString(100, init_y, datenow) c.save() certif.filename = filename certif.insert() except Exception as e: flash(notify_danger('{}'.format(e))) return redirect(url_for('course.view_certificate_request'))
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 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))
def approve_certif_req(certif_req_id): certif_request = LightCertificateRequest.query.get(certif_req_id) course = LightCourse.query.get(certif_request.course_id) if not course: flash(notify_warning('Course no longer exist')) certif_request.delete() return redirect(url_for('course.view_certificate_request')) if not (current_user.id == course.teacher_id or current_user.role == 'admin'): return "You don't have permission to approve" course_taker_id = certif_request.course_taker_id course_id = certif_request.course_id certif_request.delete() certif = LightCertificate(course_taker_id=course_taker_id, course_id=course_id) person = User.query.get(course_taker_id) course = LightCourse.query.get(course_id) person_name = person.name.replace(' ', '_').replace('-', '_') course_name = course.name.replace(' ', '_') #flash(notify_info('{}'.format(os.getcwd()))) try: dirname = current_app.config['UPLOAD_CERTIFICATES_FOLDER'] try: os.mkdir(dirname) except: pass filename = "{}_{}.pdf".format(person_name, course_name) fname = os.path.join(dirname, filename) # flash(notify_info(fname)) #with open(fname, 'w+') as f: # f.write('') create_certificate(fname, person.name, course.name) certif.filename = filename certif.insert() except Exception as e: flash(notify_danger('{}'.format(e))) return redirect(url_for('course.view_certificate_request'))
def grade_delete(grade_id): grade = Grade.query.get(grade_id) grade.delete() flash(notify_danger('deleted grade {}!'.format(grade.name))) return redirect(url_for('student.index'))
def delete(course_id): course = LightCourse.query.get(course_id) course.delete() flash(notify_danger('course deleted!')) return redirect(url_for('course.index'))
def delete(admin_id): admin = User.query.get(admin_id) admin.delete() flash(notify_danger('Deleted {}!'.format(admin.name))) return redirect(url_for('admin.index'))
def delete(teacher_id): teacher = User.query.get(teacher_id) teacher.delete() flash(notify_danger('Deleted {}!'.format(teacher.name))) return redirect(url_for('teacher.index'))
def delete_section(section_id): section = Section.query.get(section_id) course_id = section.course.id section.delete() flash(notify_danger('Deleted section {}!'.format(section.name))) return redirect(url_for('course.view', course_id=course_id))