Ejemplo n.º 1
0
def View(id):
    """ Gets information for given module. """
    # Verify user access
    if not Authorization.canAccess(session.get('user'), ('scheduling_admin')):
        return render_template('error/no_access.html')

    # Get module object
    module = ModuleModel.findById(id)

    if not module:
        return render_template('error/resource_not_found.html')

    # Get leader (teacher) object
    leader = TeacherModel.findById(module.getLeader())

    if not module:
        return render_template('error/server_error.html')

    # Get teachers object
    teachers = TeacherModel.all()

    # Get enrolled students
    students = []
    enrolments = StudentModuleModel.findBy('module', id)

    for enrolment in enrolments:
        students.append(StudentModel.findById(enrolment.getStudent()))

    # Get module sessions (+ teachers)
    sessions = ModuleSessionModel.findBy('module', id)
    sessions_list = []

    for session2 in sessions:
        sessions_list.append({
            'session':
            session2,
            'staff':
            TeacherModel.findById(session2.getStaff()),
            'type':
            ModuleSessionTypeModel.findById(session2.getType())
        })

    # Get session types
    sessionTypes = ModuleSessionTypeModel.all()

    return render_template('module_view.html',
                           data={
                               'module': module,
                               'leader': leader,
                               'teachers': teachers,
                               'students': students,
                               'sessionTypes': sessionTypes,
                               'sessions': sessions_list
                           })
Ejemplo n.º 2
0
def View(id):
    """Returns student information [+ student module enrolments]. (Template: student_view.html)"""

    if not Authorization.canAccess(session.get('user'), ('admin')):
        return render_template('error/no_access.html')

    student = StudentModel.findById(id)
    #Get Modules ?

    return render_template(
        "student_view.html",
        data={"student": student
              #Modules?
              })
Ejemplo n.º 3
0
def Update(id):
    """Updates student information """
    """(JSON) (Post variables: first_name, last_name, email, mobile_phone, password)"""
    #Auth
    if not Authorization.canAccess(session.get('user'), ('admin')):
        return JsonResponse.unauthorized()

    first_name = request.form.get('first_name')
    last_name = request.form.get('last_name')
    email = request.form.get('email')
    mobile_phone = request.form.get('mobile_phone')
    password = request.form.get('password')

    if not first_name and not last_name and not email and not mobile_phone and not password:
        #Bad request
        return JsonResponse.badRequest({
            'message':
            'missing_parameters',
            'nice_message':
            'Please fill out new information for the student.'
        })

    student = StudentModel.findById(id)
    #Not sure on method names
    if first_name:
        student.setFirstName(first_name)
    if last_name:
        student.setLastName(last_name)
    if email:
        student.setEmail(email)
    if mobile_phone:
        student.setMobile(mobile_phone)
    #Password hashed here
    if password:
        salt = student.getSalt()
        hashedPassword = Security.hashPassword(password, salt)
        student.setPassword(hashedPassword)

    try:
        student.save()
    except:
        return JsonResponse.badRequest({'error': 'database_error'})

    return JsonResponse.ok()
Ejemplo n.º 4
0
def List(student_id):
    """Returns all modules for given student."""
    # Verify user access
    if not Authorization.canAccess(session.get('user'), ('scheduling_admin')):
        return render_template('error/no_access.html')

    student = StudentModel.findById(student_id)

    if not student:
        return render_template('error/resource_not_found.html')

    module_enrolments = StudentModuleModel.findBy('student', student_id)
    modules = []
    module_id = []

    for enrolment in module_enrolments:
        Module = ModuleModel.findById(enrolment.getModule())
        modules.append(Module)
        module_id.append(Module.getId())

    AllModules = ModuleModel.all()
    Available_Modules = []

    for module in AllModules:
        if module.getId() not in module_id:
            Available_Modules.append(module)

    # get student timetable
    timetable = Timetable.getStudentTimetable(student_id,
                                              Timetable.getStartOfMonth(),
                                              Timetable.getEndOfMonth())

    return render_template('enrolment_list.html',
                           data={
                               "enroled_modules": modules,
                               "available_modules": Available_Modules,
                               "student": student,
                               "timetable": timetable
                           })
Ejemplo n.º 5
0
def Delete(id):
    """Deletes a Student"""
    #Authorise (Change who is authorised)
    if not Authorization.canAccess(session.get('user'), ('admin')):
        return JsonResponse.unauthorized({
            'message':
            'not_access',
            'nice_message':
            'You do not have access to this function. Contact system administrator.'
        })

    #Find student and check they exist
    student = StudentModel.findById(id)

    if not student:
        return JsonResponse.notFound({
            'message': 'not_found',
            'nice_message': 'Student not found.'
        })

    #Delete record of student
    student.delete()
    return JsonResponse.ok()