Exemplo n.º 1
0
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))
Exemplo n.º 2
0
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'))
Exemplo n.º 3
0
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))
Exemplo n.º 4
0
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'))
Exemplo n.º 5
0
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'))
Exemplo n.º 6
0
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'))
Exemplo n.º 7
0
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))
Exemplo n.º 8
0
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'))
Exemplo n.º 9
0
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'))
Exemplo n.º 10
0
def delete(course_id):

    course = LightCourse.query.get(course_id)
    course.delete()
    flash(notify_danger('course deleted!'))
    return redirect(url_for('course.index'))
Exemplo n.º 11
0
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'))
Exemplo n.º 12
0
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'))
Exemplo n.º 13
0
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))