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 })
def List(module_id): """ Lists all sessions 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(module_id) if not module: return render_template('error/resource_not_found.html') # Get list of module sessions for given module sessions = ModuleSession.findBy('module', module_id) # Get a list of all teachers teachers = TeacherModel.all() # Get a list of all module session types session_types = ModuleSessionTypeModel.all() return render_template('session_list.html', data={ 'module': module, 'sessions': sessions, 'teachers': teachers, 'session_types': session_types })
def from_dict(old): args = old args['klas'] = Klas.get(id=args['klas']['id']) args['syllabus'] = Syllabus.get(id=args['syllabus']['id']) args['subject'] = Subject.get(id=args['subject']['id']) args['teacher'] = Teacher.get(id=args['teacher']['id']) args['subtheme'] = Subtheme.get(id=args['subtheme']['id']) return args
def View(id): """ Returns teachers information """ if not Authorization.canAccess(session.get('user'), ('admin')): return render_template('error/no_access.html') teachers = TeacherModel.findById(id) if not teachers: return render_template('error/resource_not_found.html') return render_template('teacher_view.html', data={'teacher': teachers})
def Update(module_id, session_id): """ Updates a module session. """ # Verify user access if not Authorization.canAccess(session.get('user'), ('scheduling_admin')): return JsonResponse.unauthorized({ 'message': 'no_access', 'nice_message': 'You do not have access to this function. Contact system administrator.' }) # Get session object session = ModuleSessionModel.findById(session_id) if not session: return JsonResponse.notFound({ 'message': 'not_found', 'nice_message': 'Session not found.' }) # Save new values to database teacher = request.form.get('teacher') sessionType = request.form.get('type') if not teacher and not sessionType: return JsonResponse.badRequest({ 'message': 'missing_parameters', 'nice_message': 'Please enter a teacher and session type.' }) if teacher: if not TeacherModel.findById(teacher): return JsonResponse.badRequest({ 'message': 'not_found', 'nice_message': 'Teacher not found.' }) session.setStaff(teacher) if sessionType: if not ModuleSessionModel.findById(sessionType): return JsonResponse.badRequest({ 'message': 'not_found', 'nice_message': 'Session type not found.' }) session.setType(sessionType) session.save() return JsonResponse.ok()
def Update(id): """ Updates teachers information """ if not Authorization.canAccess(session.get('user'), ('admin')): return JsonResponse.unauthorized({ 'message': 'no_access', 'nice_message': 'You do not have access to this function. Contact system administrator.' }) 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: return JsonResponse.badRequest({ 'message': 'missing_parameters', 'nice_message': 'Please enter details for the teacher.' }) teachers = TeacherModel.findById(id) if not teachers: return JsonResponse.notFound({ 'message': 'not_found', 'nice_message': 'Teacher not found.' }) if first_name: teachers.setFirstName(first_name) if last_name: teachers.setLastName(last_name) if email: teachers.setEmail(email) if mobile_phone: teachers.setMobile(mobile_phone) if password: salt = teachers.getSalt() hashedPassword = Security.hashPassword(password, salt) teachers.setPassword(hashedPassword) try: teachers.save() except: return JsonResponse.badRequest({'error': 'database_error'}) return JsonResponse.ok()
def Create(module_id): """ Creates a new module session. """ # Verify user access if not Authorization.canAccess(session.get('user'), ('scheduling_admin')): return JsonResponse.unauthorized({ 'message': 'no_access', 'nice_message': 'You do not have access to this page. Contact system administrator.' }) # Get module object module = ModuleModel.findById(module_id) if not module: return JsonResponse.notFound({ 'message': 'not_found', 'nice_message': 'Module not found.' }) # Parse and validate request body teacher = request.form.get('teacher') sessionType = request.form.get('type') if not TeacherModel.findById(teacher): return JsonResponse.badRequest({ 'message': 'not_found', 'nice_message': 'Teacher not found.' }) if not ModuleSessionTypeModel.findById(sessionType): return JsonResponse.badRequest({ 'message': 'not_found', 'nice_message': 'Module session not found.' }) # Save new data to database moduleSession = ModuleSessionModel() moduleSession.setModule(module.getId()) \ .setStaff(teacher) \ .setType(sessionType) \ .save() return JsonResponse.ok()
def Update(id): """ Updates a given module. """ # Verify user access if not Authorization.canAccess(session.get('user'), ('scheduling_admin')): return JsonResponse.unauthorized({ 'message': 'no_access', 'nice_message': 'You do not have access to this page. Contact system administrator.' }) # Get module object module = ModuleModel.findById(id) if not module: return JsonResponse.notFound({ 'message': 'not_found', 'nice_message': 'Module not found.' }) # Save new values to database name = request.form.get('module_name') leader = request.form.get('leader') if not name and not leader: return JsonResponse.badRequest({ 'message': 'missing_parameters', 'nice_message': 'Please enter a new name or module leader.' }) if name: module.setName(name) if leader: if not TeacherModel.findById(leader): return JsonResponse.badRequest({ 'message': 'not_found', 'nice_message': 'Teacher not found.' }) module.setLeader(leader) module.save() return JsonResponse.ok()
def List(): """ Lists all modules. """ # Verify user access if not Authorization.canAccess(session.get('user'), ('scheduling_admin')): return render_template('error/no_access.html') # Get list of all teachers teachers = TeacherModel.all() # Get list of modules modules = ModuleModel.all() return render_template('module_list.html', data={ 'modules': modules, 'teachers': teachers })
def Delete(id): """ Deletes teacher """ if not Authorization.canAccess(session.get('user'), ('admin')): return JsonResponse.unauthorized({ 'message': 'no_access', 'nice_message': 'You do not have access to this function. Contact system administrator' }) teachers = TeacherModel.findById(id) if not teachers: return JsonResponse.notFound({ 'message': 'not_found', 'nice_message': 'Teacher not found.' }) modules = ModuleModel.findBy('leader', id) if len(modules) != 0: return JsonResponse.badRequest({ 'message': 'bad_request', 'nice_message': 'Modules exist with this teacher as module leader.' }) sessions = ModuleSessionModel.findBy('staff', id) if len(sessions) != 0: return JsonResponse.badRequest({ 'message': 'bad_request', 'nice_message': 'Sessions exist for this teacher.' }) teachers.delete() return JsonResponse.ok()
def Create(): """ Creates a new module. """ # Verify user access if not Authorization.canAccess(session.get('user'), ('scheduling_admin')): return JsonResponse.unauthorized({ 'message': 'no_access', 'nice_message': 'You do not have access to this page. Contact system administrator.' }) # Parse and validate request body name = request.form.get('module_name') leader = request.form.get('leader') if not name or not leader: return JsonResponse.badRequest({ 'message': 'missing_parameters', 'nice_message': 'Please make sure you enter a name and leader.' }) # Make sure leader is a valid staff member if not TeacherModel.findById(leader): return JsonResponse.badRequest({ 'message': 'not_found', 'nice_message': 'Teacher not found' }) # Save new data to database module = ModuleModel() module.setName(name) \ .setLeader(leader) \ .save() return JsonResponse.ok()
def View(module_id, session_id): """ Returns module session information. """ # 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(module_id) if not module: return render_template('error/resource_not_found.html') # Get session object theSession = ModuleSessionModel.findById(session_id) if not theSession: return render_template('error/resource_not_found.html') # Get the campus objects campus_list = CampusModel.all() campuses = [] for campus in campus_list: buildings = CampusBuildingModel.findBy('campus', campus.getId()) if (len(buildings) > 0): campuses.append({'campus': campus, 'buildings': buildings}) theSession = { 'session': theSession, 'staff': TeacherModel.findById(theSession.getStaff()), 'type': ModuleSessionTypeModel.findById(theSession.getType()), 'campuses': CampusModel.all() } # Get list of teachers teachers = TeacherModel.all() # Get list of session types session_types = ModuleSessionTypeModel.all() # Get terms terms = TermModel.all() term_list = [] for term in terms: term_list.append({ 'term': term, 'startDate': datetime.utcfromtimestamp(term.getStartDate()).strftime("%B %Y"), 'endDate': datetime.utcfromtimestamp(term.getEndDate()).strftime("%B %Y") }) # Get list of room bookings room_bookings = RoomBookingModel.findBy('module_session', session_id) room_bookings2 = [] for booking in room_bookings: room = CampusBuildingRoomModel.findById(booking.getRoom()) building = CampusBuildingModel.findById(room.getBuilding()) campus = CampusModel.findById(building.getCampus()) timeFrom = datetime.utcfromtimestamp( booking.getTimeFrom()).strftime("%Y-%m-%d %H:%M") timeTo = datetime.utcfromtimestamp( booking.getTimeTo()).strftime("%Y-%m-%d %H:%M") room_bookings2.append({ 'booking': booking, 'room': room, 'building': building, 'campus': campus, 'timeFrom': timeFrom, 'timeTo': timeTo }) return render_template('session_view.html', data={ 'module': module, 'session': theSession, 'teachers': teachers, 'sessionTypes': session_types, 'roomBookings': room_bookings2, 'campuses': campuses, 'terms': term_list })
def from_dict(old): args = old args['studying'] = Studying.get(id=args['studying']['id']) args['teacher'] = Teacher.get(id=args['teacher']['id']) return args
def scheduleOneOff(building_id, duration, capacity, day, hour, sessionType=None, session=None): # getTimestampGivenDayAndHour(day, theStartHour) # getTimestampGivenDayAndHour(day, theStartHour + duration) duration = int(duration) capacity = int(capacity) day = int(day) hour = int(hour) sessionType = int(sessionType) session = int(session) timedate = getTimestampGivenDayAndHour(day, hour) if duration > maxSessionDuration: raise Error() # Book Room for session if session: # Get session and module object session = ModuleSessionModel.findById(session) module = ModuleModel.findById(session.getModule()) # Check teacher availability teacher = TeacherModel.findById(session.getStaff()) if not isTeacherAvailable(teacher.getId(), timedate, timedate + hr2sec(duration)): return None # Check student availability enrolments = StudentModuleModel.findBy('module', module.getId()) for enrolment in enrolments: if not isStudentAvailable(enrolment.getStudent(), timedate, timedate + hr2sec(duration)): return None # Get room room = getAvailableRoom(building_id, len(enrolments), session.getType(), timedate, timedate + hr2sec(duration)) if not room: return None roomBooking = RoomBookingModel() roomBooking.setRoom(room.getId()) \ .setTimeFrom(timedate) \ .setTimeTo(timedate + hr2sec(duration)) \ .setModuleSession(session.getId()) \ .save() return roomBooking # Book Room for not session if not session: # Get free room that fits the requirements room = getAvailableRoom(building_id, capacity, sessionType, timedate, timedate + hr2sec(duration)) if not room: raise None roomBooking = RoomBookingModel() roomBooking.setRoom(room.getId()) \ .setTimeFrom(timedate) \ .setTimeTo(timedate + hr2sec(duration)) \ .save() return roomBooking return None # fail safe
def SessionLogin(): if 'X-App-Token' in request.headers and ApiSession.isValid(request): return JsonResponse.ok({'token': request.headers['X-App-Token']}) userEmail = request.form.get('email') userPassword = request.form.get('password') userType = request.form.get('user_type') # Step 1: Verify presence of values and validate them if not userEmail or not userPassword or not userType: return JsonResponse.badRequest({ 'message': 'post_property_missing', 'nice_message': 'Missing POST property.' }) if userType not in ('student', 'teacher'): return JsonResponse.badRequest({ 'message': 'invalid_user_type', 'nice_message': 'Given user type is invalid! Allowable types are: student/teacher.' }) # Step 2: Verify password if userType == 'student': user = StudentModel.findBy('email', userEmail) elif userType == 'teacher': user = TeacherModel.findBy('email', userEmail) else: return JsonResponse.internalServerError({ 'message': 'unexpected_user_type', 'nice_message': 'Unexpected user type. Contact system administrator.' }) if len(user) != 1: return JsonResponse.unauthorized({ 'message': 'invalid_credentials', 'nice_message': 'Supplied credentials (email/password) are invalid.' }) user = user[0] salt = user.getSalt() hashedPassword = Security.hashPassword(userPassword, salt) if hashedPassword != user.getPassword(): return JsonResponse.unauthorized({ 'message': 'invalid_credentials', 'nice_message': 'Supplied credentials (email/password) are invalid.' }) userId = user.getId() # Step 3: Create session ipAddress = request.remote_addr if Config.getValue('DEPLOYMENT') == 'heroku': ipAddress = request.headers['X-Forwarded-For'] token = ApiSession.create(userId, userType, ipAddress, request.headers['User-Agent']) if token: return JsonResponse.ok({'token': token}) return JsonResponse.internalServerError({ 'message': 'session_generation_failed', 'nice_message': 'Session generation failed. Contact system administrator.' })
def Create(): """ Creates a new teacher """ if not Authorization.canAccess(session.get('user'), ('admin')): return JsonResponse.unauthorized({ 'message': 'no_access', 'nice_message': 'You do not have access to this function. Contact system administrator' }) 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') salt = Security.generateSalt() hashedPassword = Security.hashPassword(password, salt) teachers = TeacherModel() if not teachers: return JsonResponse.notFound({ 'message': 'not_found', 'nice_message': 'Teacher not found.' }) teachers.setFirstName(first_name) teachers.setLastName(last_name) teachers.setEmail(email) teachers.setMobile(mobile_phone) teachers.setPassword(hashedPassword) teachers.setSalt(salt) try: teachers.save() except: return JsonResponse.badRequest({'error': 'database_error'}) return JsonResponse.ok()
klass1.get_number_today() """----------------------------------------------------------------------""" """Ученики""" student1 = Student(date=datetime(2006, 7, 16), first_name="Коваль", second_name="Александр", patronymic="Викторович") student2 = Student(date=datetime(2006, 8, 10), first_name="Чебыкин", second_name="Роман", patronymic="Сергеевич") klass1.add_student(student1) klass1.add_student(student2) print("Класс",klass1.get_number_today(), klass1.get_letter()) print(klass1) print("----------------------------------------------------------------------") """----------------------------------------------------------------------""" """Учителя""" teacher1 = Teacher(first_name="Иванова", second_name="Мария", patronymic="Петровна") teacher2 = Teacher(first_name="Гунёва", second_name="Раисия", patronymic="Петровна") """----------------------------------------------------------------------""" """Предметы""" subject1 = Subject(item_name="Математика", teacher=teacher1) subject2 = Subject(item_name="Биология", teacher=teacher2) """----------------------------------------------------------------------""" """Темы занятий""" topic1 = Topic(name_topic="Дроби") topic2 = Topic(name_topic="Рациональные числа") topic3 = Topic(name_topic="Анатомия человека") topic4 = Topic(name_topic="Физиология человека") """----------------------------------------------------------------------""" """Изучается"""