class User(NamedBusinessObject): """ Realisierung der User """ r_student = Role("Student") r_dozent = Role("Dozent") r_admin = Role("Admin") r_platzhalter_rolle = Role("Platzhalter_Rolle") def __init__(self): super().__init__() self._mail = "" self._google_id = "" self._role_id = 4 def get_mail(self): """Auslesen der Mail""" return self._mail def set_mail(self, new_mail): """Setzen der Mail""" self._mail = new_mail def get_google_id(self): """Auslesen der Google Mail""" return self._google_id def set_google_id(self, new_google_id): """Setzen der google Mail""" self._google_id = new_google_id def get_role_id(self): """Auslesen der Rollen-ID""" return self._role_id def set_role_id(self, new_role_id): """Setzen der Rollen-Id """ self._role_id = new_role_id @staticmethod def from_dict(dict = dict()): new_user = User() new_user.set_id(dict["id"]) new_user.set_name(dict["name"]) new_user.set_mail(dict["mail"]) new_user.set_google_id(dict["google_id"]) new_user.set_role_id(dict["role_id"]) new_user.set_create_time(dict["create_time"]) return new_user
def find_by_key(self, id): """Suchen einer Rolle mit vorgegebener Rollen-ID""" result = [] cursor = self._cnx.cursor() command = "SELECT * FROM role WHERE id like '{}'".format(id) cursor.execute(command) tuples = cursor.fetchall() if len(tuples) != 0: for (id, name, create_time) in tuples: role = Role() role.set_id(id) role.set_name(name) role.set_create_time(create_time) result.append(role) result = role else: result = None self._cnx.commit() cursor.close() return result
def create_role(self, name): """Eine Rolle anlegen""" role = Role() role.set_name(name) role.set_id(1) with RoleMapper() as mapper: return mapper.insert(role)
def find_by_name(self, name): """Suchen einer Rolle anhand des Namens""" result = [] cursor = self._cnx.cursor() command = "SELECT * FROM role WHERE name like '{}'".format(name) cursor.execute(command) tuples = cursor.fetchall() for (id, name, create_time) in tuples: role = Role() role.set_id(id) role.set_name(name) role.set_create_time(create_time) result.append(role) self._cnx.commit() cursor.close() return result
def find_all(self): """Auslesen aller Rolle""" result = [] cursor = self._cnx.cursor() command = "SELECT * FROM role" cursor.execute(command) tuples = cursor.fetchall() for (id, name, create_time) in tuples: role = Role() role.set_id(id) role.set_name(name) role.set_create_time(create_time) result.append(role) self._cnx.commit() cursor.close() return result
def find_all(self): result = [] cursor = self._cnx.cursor() cursor.execute("SELECT id, name FROM role") tuples = cursor.fetchall() for (id, name) in tuples: role = Role() role.set_id(id) role.set_name(name) result.append(role) self._cnx.commit() cursor.close() return result
def find_by_id(self, id): result = [] cursor = self._cnx.cursor() command = "SELECT id, name FROM role WHERE id={}".format(id) cursor.execute(command) tuples = cursor.fetchall() if tuples[0] is not None: (id, name) = tuples[0] role = Role() role.set_id(id) role.set_name(name) result.append(role) self._cnx.commit() cursor.close() return result