def delete_lesson(self, member_id: str, lesson_id: str): with self._database_engine.new_session() as session: member_dao = MemberDAO(session) member = member_dao.get(member_id) lesson_dao = LessonDAO(session) lesson = lesson_dao.get(lesson_id) member_dao.delete_lesson(member, lesson, session)
def search_member(self, firstname, lastname): # Query database with self._database_engine.new_session() as session: member_dao = MemberDAO(session) member = member_dao.get_by_name(firstname, lastname) return member.to_dict()
def update_member(self, member_id: str, member_data: dict): self._check_profile_data(member_data, update=True) with self._database_engine.new_session() as session: member_dao = MemberDAO(session) member = member_dao.get(member_id) member = member_dao.update(member, member_data) return member.to_dict()
def search_member(self, email): # Query database with self._database_engine.new_session() as session: member_dao = MemberDAO(session) member = member_dao.get_by_email(email) if member == None: return None return member.to_dict()
def create_member(self, data): self.check_data(data) try: with self._database_engine.new_session() as session: # Save member in database member = MemberDAO(session).create(data) member_data = member.to_dict() return member_data except Error as e: return None
def create_member(self, data: dict): self._check_profile_data(data) try: with self._database_engine.new_session() as session: # Save sport in database member = MemberDAO(session).create(data) member_data = member.to_dict() return member_data except Error as e: # log error raise e
def create_member(self, data): self._check_profile_data(data) try: with self._database_engine.new_session() as session: # Save member in database member = MemberDAO(session).create(data) member_data = member.to_dict() return member_data except Error as e: # log error print("An Error occured (%s)" % str(e)) raise e
def list_members(self): # Permit to attribute the "Session" class to the new session with self._database_engine.new_session() as session: members = MemberDAO(session).get_all() # To_dict is function defined in model/mapping/member.py members_data = [member.to_dict() for member in members] return members_data
def get_dao(self, type=None): if type is None: return PersonDAO(self._database_session) if type == 'member': return MemberDAO(self._database_session) else: return PersonDAO(self._database_session)
def list_members(self): with self._database_engine.new_session() as session: members = MemberDAO(session).get_all() members_data = [member.to_dict() for member in members] ## ou session = self._database_engine.new_session() with session: members = MemberDAO(session).get_all() members_data = [member.to_dict() for member in members] ## ou alors session = self._database_engine.new_session() members = MemberDAO(session).get_all() members_data = [member.to_dict() for member in members] session.commit() session.close() return members_data
def delete_member(self, member_id): with self._database_engine.new_session() as session: member_dao = MemberDAO(session) member = member_dao.get(member_id) member_dao.delete(member)
def get_member(self, member_id): with self._database_engine.new_session() as session: member = MemberDAO(session).get(member_id) member_data = member.to_dict() return member_data
def list_members(self): with self._database_engine.new_session() as session: members = MemberDAO(session).get_all() members_data = [member.to_dict() for member in members] return members_data
def get_member_by_name(self, firstname: str, lastname: str): with self._database_engine.new_session() as session: member = MemberDAO(session).get_by_name(firstname, lastname) member_data = member.to_dict() return member_data
def update_member(self, member_id, member_data): with self._database_engine.new_session() as session: member_dao = MemberDAO(session) member = member_dao.get(member_id) member = member_dao.update(member, member_data) return member.to_dict()