예제 #1
0
def new_student():
    if current_user.level == 1:
        form = NewStudentForm()
        if form.validate_on_submit():
            student = Student(studentid=form.studentid.data, name=form.name.data, date_enrolled=form.dateenrolled.data, email=form.email.data)
            hashed_password = bcrypt.generate_password_hash('password').decode('utf-8')
            comp_tbl = Comp.query.all()
            s = User2(username=form.studentid.data, email=form.email.data, level=3, rotation1='Student', rotation2=form.studentid.data, password=hashed_password) # automatically adding students user accounts
            db.session.add(s)
            db.session.commit()
            for c in comp_tbl:
                d = Competancy_rec(mark=0, comp_id=c.descrip, comp_name=c.rot_name, clinician_id=current_user.id, student_id=form.studentid.data) #automatically building comp rec table for each student
                db.session.add(d)
            db.session.commit()
            db.session.add(student)
            db.session.commit()
            activity = Activity(activityType='ASS', actionID=form.studentid.data, clincianID=current_user.id)
            db.session.add(activity)
            db.session.commit()
            flash('The Student has been added to the Database', 'success')
            return redirect(url_for('students'))
        return render_template('new_student.html', title="New Student", form=form, legend='Add a new Student to the Database')
    else:
        flash('ONLY CLINICIANS CAN VIEW THIS PAGE','danger')
        return redirect(url_for('home'))
예제 #2
0
def delete_user(user_id):
    user = User2.query.filter_by(id=user_id).first()
    db.session.delete(user)
    db.session.commit()
    activity = Activity(activityType='DU', actionID=user.id, clincianID=current_user.id)
    db.session.add(activity)
    db.session.commit()
    flash('The User Account has been Deleted', 'success')
    return redirect(url_for('competancy'))
예제 #3
0
def delete_comp(comp_id):
    if current_user.level == 1:
        comp = Comp.query.filter_by(id=comp_id).first()
        db.session.delete(comp)
        db.session.commit()
        activity = Activity(activityType='DCP', actionID=comp_id, clincianID=current_user.id)
        db.session.add(activity)
        db.session.commit()
        flash('The Competancy has been Deleted', 'success')
        return redirect(url_for('rotations'))
    else:
        flash('ONLY ADMINS CAN DELETE COMPETENCIES','danger')
    return redirect(url_for('home'))
예제 #4
0
def update_rec2(comp_rec):
      
        record= Competancy_rec.query.filter_by(id=comp_rec).first()
        if record.mark == 0:
            record.mark = 1
        else:
            record.mark = 0
        
        db.session.commit()
        activity = Activity(activityType='MS', actionID=record.student_id, clincianID=current_user.id)
        db.session.add(activity)
        db.session.commit()
        flash('Mark Updated', 'success')
        return redirect(url_for('comp_rec2', student_id=record.student_id))
예제 #5
0
def new_comp():
    if current_user.level == 1:
        form = NewCompForm()
        if form.validate_on_submit():
            comp = Comp(descrip=form.content.data, code=form.compid.data, rot_name=form.rotation.data)
            db.session.add(comp)
            db.session.commit()
            activity = Activity(activityType='ACP', actionID=form.compid.data, clincianID=current_user.id)
            db.session.add(activity)
            db.session.commit()
            flash('The Competancy has been added to the Database', 'success')
            return redirect(url_for('rotations'))
        return render_template('new_comp.html', title="New Competancy", form=form, legend='Add a new Competancy to the Database')
    else:
        flash('ONLY ADMINS CAN ADD NEW COMPETENCIES','danger')
    return redirect(url_for('home'))
예제 #6
0
def register():
    if current_user.level == 1:
        form = RegistrationForm()
        if form.validate_on_submit():
            hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
            user = User2(username=form.username.data, email=form.email.data, level=form.level.data, rotation1=form.rotation1.data, rotation2=form.rotation2.data, password=hashed_password)
            db.session.add(user)
            db.session.commit()
            activity = Activity(activityType='AC', actionID=user.id, clincianID=current_user.id)
            db.session.add(activity)
            db.session.commit()
            flash('Your account has been created! You are now able to log in', 'success')
            return redirect(url_for('login'))
        
    else:
        flash('You did not have privilages to view that page', 'danger')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
예제 #7
0
def update_rec(comp_rec, mark):
    if current_user.level == 1 or current_user.level == 2:
        try:
            print(mark)
            if mark == "false":
                mark = 0
            else:
                mark = 1
            record= Competancy_rec.query.filter_by(id=int(comp_rec)).first()
            record.mark = int(mark)
            print(record.mark)
            db.session.commit()
            activity = Activity(activityType='MS', actionID=record.student_id, clincianID=current_user.id)
            db.session.add(activity)
            db.session.commit()
            return jsonify({"success":"record updated"})
        except Exception as e:
            print(e)
            return jsonify({"error":"Error has occured"})
    else:
        flash('ONLY ADMINS CAN ACCESS THIS PAGE','danger')
    return redirect(url_for('home'))
예제 #8
0
def update_comp(comp_id):
    if current_user.level == 1:
        comp = Comp.query.filter_by(id=comp_id).first()
    
        form= EditCompForm()
        if form.validate_on_submit():
            comp.descrip = form.content.data
        
            db.session.commit()
            activity = Activity(activityType='UCP', actionID=comp_id, clincianID=current_user.id)
            db.session.add(activity)
            db.session.commit()

            flash('The Competancy has been updated', 'success')
            return redirect(url_for('rotations', comp_id=comp.id))
        elif request.method == 'GET':
        
            form.content.data = comp.descrip
        
        return render_template('editcomp.html', title='Update Competancy', 
                            form=form, legend='Edit a Competancy')
    else:
        flash('ONLY ADMINS CAN UPDATE COMPETENCIES','danger')
    return redirect(url_for('home'))