def add_person_sport(self, person_id, sport_id, level): with self._database_engine.new_session() as session: person_dao = PersonDAO(session) person = person_dao.get(person_id) sport_dao = SportDAO(session) sport = sport_dao.get(sport_id) person.add_sport(sport, level, session)
def delete_person_sport(self, person_id, sport_id): with self._database_engine.new_session() as session: person_dao = PersonDAO(session) person = person_dao.get(person_id) sport_dao = SportDAO(session) sport = sport_dao.get(sport_id) person.delete_sport(sport, session)
def search_person(self, firstname, lastname, person_type=None): logging.info("Search person %s %s" % (firstname, lastname)) # Query database with self._database_engine.new_session() as session: dao = PersonDAO(session) member = dao.get_by_name(firstname, lastname) return member.to_dict()
def get_person(self, person_id, person_type=None): logging.info("Get person %s" % person_id) with self._database_engine.new_session() as session: dao = PersonDAO(session) member = dao.get(person_id) member_data = member.to_dict() return member_data
def update_person(self, person_id, person_data): self._check_profile_data(person_data, update=True) with self._database_engine.new_session() as session: person_dao = PersonDAO(session) person = person_dao.get(person_id) person = person_dao.update(person, person_data) return person.to_dict()
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 _update_person(self, member_id, member_data, person_type=None): logging.info("Update %s with data: %s" % (member_id, str(member_data))) with self._database_engine.new_session() as session: dao = PersonDAO(session) person = dao.get(member_id) person = dao.update(person, member_data) return person.to_dict()
def create_person(self, data, person_type=None): self._check_person_data(data) try: with self._database_engine.new_session() as session: member = PersonDAO(session).get_dao(type=person_type).create(data) member_data = member.to_dict() return member_data except Error as e: raise e
def create_person(self, data): self._check_profile_data(data) try: with self._database_engine.new_session() as session: # Save person in database person = PersonDAO(session).create(data) person_data = person.to_dict() return person_data except Error as e: # log error raise e
def create_person(self, data, person_type=None): logging.info("Create member with data %s" % str(data)) self._check_person_data(data) try: with self._database_engine.new_session() as session: # Save member in database dao = PersonDAO(session) person = session.query(Person).filter_by( email=data.get('email')).all() if len(person) > 0: raise InvalidData("Mail already existing") member = dao.create(data) member_data = member.to_dict() return member_data except Error as e: # log error logging.error("An Error occured (%s)" % str(e)) raise e
def connexion(self, email, password): logging.info("Connexion with email %s" % str(email)) with self._database_engine.new_session() as session: dao = PersonDAO(session) pwd = str(hashlib.sha256(password.encode('utf8')).hexdigest()) try: person = session.query(Person).filter_by(email=email).one() if pwd == person.password: logging.info("Connexion success %s %s" % (str(person.firstname), str(person.lastname))) return person.to_dict() else: logging.info("Wrong id, try again") return {0} except: logging.info("Wrong id, try again") return {0}
def list_persons(self, isAdmin=None): logging.info("List persons") with self._database_engine.new_session() as session: persons = PersonDAO(session).get_all() persons_data = [person.to_dict() for person in persons] return persons_data
def _update_person(self, member_id, member_data, person_type=None): with self._database_engine.new_session() as session: person = PersonDAO(session).get_dao(type=person_type).get(member_id) person = PersonDAO(session).get_dao(type=person_type).update(person, member_data) return person.to_dict()
def search_person(self, firstname, lastname, person_type=None): # Query database with self._database_engine.new_session() as session: dao = PersonDAO(session).get_dao(type=person_type) member = dao.get_by_name(firstname, lastname) return member.to_dict()
def delete_person(self, member_id, person_type=None): with self._database_engine.new_session() as session: dao = PersonDAO(session).get_dao(type=person_type) member = dao.get(member_id) dao.delete(member)
def search_person(self, firstname, lastname): # Query database with self._database_engine.new_session() as session: person_dao = PersonDAO(session) person = person_dao.get_by_name(firstname, lastname) return person.to_dict()
def list_persons(self): with self._database_engine.new_session() as session: persons = PersonDAO(session).get_all() persons_data = [person.to_dict() for person in persons] return persons_data
def delete_person(self, person_id): with self._database_engine.new_session() as session: person_dao = PersonDAO(session) person = person_dao.get(person_id) person_dao.delete(person)
def get_person(self, person_id, person_type=None): with self._database_engine.new_session() as session: member = PersonDAO(session).get_dao(type=person_type).get(person_id) member_data = member.to_dict() return member_data
def get_person(self, person_id): with self._database_engine.new_session() as session: person = PersonDAO(session).get(person_id) person_data = person.to_dict() return person_data
def get_person_by_username(self, username): with self._database_engine.new_session() as session: user = UserDAO(session).get_by_name(username) person = PersonDAO(session).get_by_id_user(user.id) person_data = person.to_dict() return person_data
def get_person_by_name(self, firstname, lastname): with self._database_engine.new_session() as session: person = PersonDAO(session).get_by_name(firstname, lastname) person_data = person.to_dict() return person_data
def delete_person(self, member_id, person_type=None): logging.info("Delete person %s" % member_id) with self._database_engine.new_session() as session: dao = PersonDAO(session) member = dao.get(member_id) dao.delete(member)
def list_people(self, person_type=None): with self._database_engine.new_session() as session: people = PersonDAO(session).get_dao(type=person_type).get_all() people_data = [member.to_dict() for member in people] return people_data