Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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()
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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()
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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()
Exemplo n.º 8
0
 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
Exemplo n.º 9
0
 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
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
    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}
Exemplo n.º 12
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
Exemplo n.º 13
0
 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()
Exemplo n.º 14
0
 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()
Exemplo n.º 15
0
 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)
Exemplo n.º 16
0
 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()
Exemplo n.º 17
0
 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
Exemplo n.º 18
0
 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)
Exemplo n.º 19
0
 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
Exemplo n.º 20
0
 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
Exemplo n.º 21
0
 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
Exemplo n.º 22
0
 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
Exemplo n.º 23
0
 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)
Exemplo n.º 24
0
 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