def delete_room(self, room): meetings = session.query(Meeting).filter(Meeting.room == room.id).all() for m in meetings: for em in m.employees: session.delete(em) session.delete(m) session.delete(room) session.commit()
def update_employee_by_obj(self, employee): try: employee_id = employee.id session.commit() return self.get_employee(employee_id) except Exception as e: session.rollback() handle_exception() return False
def update_room_by_object(self, room_obj): try: room_id = room_obj.id session.commit() return self.get_room_by_id(room_id) except Exception as e: session.rollback() handle_exception() return False
def bulk_create_timeslots(self, times): _times = [] for time in times: timeslot = TimeSlot(begin_time=time) session.add(timeslot) session.flush() _times.append(self.get_timeslot(timeslot.id)) session.commit() return _times
def add_room(self, roomname, number, building, capacity=None): try: if capacity: room = Room(roomname=roomname, number=number, building=building, capacity=capacity) else: room = Room(roomname=roomname, number=number, building=building) session.add(room) session.commit() room = session.query(Room).filter(Room.number == number).filter(Room.building == building).one() return room except Exception as e: session.rollback() handle_exception() return False
def create_meeting(self, title, room_id, owner_id, date, timeslots=None, employees=None): meeting = Meeting(title=title, room=room_id, owner=owner_id, date=date) if employees: for employee in employees: rel = EmployeeMeeting() rel.employee = employee meeting.employees.append(rel) if timeslots: meeting.timeslots = timeslots session.add(meeting) session.flush() meeting_id = meeting.id session.commit() return session.query(Meeting).filter(Meeting.id == meeting_id).one()
def decline_meeting(self, employee_meeting): employee_meeting.pending = False employee_meeting.accepted = False session.delete(employee_meeting) session.commit()
def add_employee(self, username, password): employee = Employee(username=username, password=password) session.add(employee) session.commit() return self.get_employee_by_username(username)
def accept_meeting(self, employee_meeting): employee_meeting.pending = False employee_meeting.accepted = True session.commit()
def update_employee_meeting(self, emp_meet, kwargs): for kwarg, value in kwargs.items(): setattr(emp_meet, kwarg, value) session.commit()
def update_employee(self, employee_id, kwargs): employee = self.get_employee(employee_id) for kwarg, value in kwargs.items(): setattr(employee, kwarg, value) session.commit() return self.get_employee(employee_id)
def delete_employee_obj(self, employee): for em in employee.meetings: session.delete(em) session.delete(employee) session.commit()
def delete_employee(self, employee_id): employee = session.query(Employee).filter(Employee.id == employee_id).one() session.delete(employee) session.commit()
def delete_meeting(self, meeting): for em in meeting.employees: session.delete(em) session.delete(meeting) session.commit()