diff --git a/__pycache__/main.cpython-312.pyc b/__pycache__/main.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c0a103ab4bc10ecf94bfb2896fbe25635bfaac5d Binary files /dev/null and b/__pycache__/main.cpython-312.pyc differ diff --git a/main.py b/main.py index e83ee9d8b4300acbb5359a165faad200fbb281e8..d1e027e7bc07690765f799668cc77b8b2d1854f4 100644 --- a/main.py +++ b/main.py @@ -34,9 +34,10 @@ def loginAttempt(username: str, password: str) -> StaffUser | ManagerUser | Admi StaffUser | ManagerUser | AdminUser | None: returns user object or NoneType if login unsucssesfull. """ # get permissionLevel and user_id where username and password are match. - conditon = json.loads(select_from_tbl_where("tblUsers", f"userName='{username}' AND userPass='{password}'", "permissionLevel")) + conditon = json.loads(select_from_tbl_where("tblUsers", f"userName='{username}' AND userPass='{password}'", "permissionLevel")) # condition is a 2 item dict. + # based on permissonLevel create the relevant user class object. - match conditon["permissionLevel"]: + match conditon['permissionLevel']: case 0: user = StaffUser() case 1: @@ -141,18 +142,19 @@ def main_cli() -> None: # if not getConnection(): # logging.critical("Database cannot connect, or dose not exist. \nClosing application.") # exit() - + print("To login please enter your credentials.\n") while True: - username = encrypt(sanitize(input("To login please enter your credentials.\nUsername: "))) + username = encrypt(sanitize(input("Username: "))) password = encrypt(sanitize(input("Password: "))) - user = loginAttempt(username=username, password=password) + #user = loginAttempt(username=username, password=password) + user = ManagerUser() # dev remove later if user is None: print("Login attempt failed please try again.") else: break logging.info("successful login, loading menu...") - + # based on the different user permision levels, load different menus. match user.permissionLevel: case 1: managerUser_options_cli(user) diff --git a/src/__pycache__/__init__.cpython-312.pyc b/src/__pycache__/__init__.cpython-312.pyc index 0cba8d46f71ba21ea04c1033328133f407f77394..3f1fc8b9e0a01db80694b92be3fcaab43153e0cf 100644 Binary files a/src/__pycache__/__init__.cpython-312.pyc and b/src/__pycache__/__init__.cpython-312.pyc differ diff --git a/src/__pycache__/adminUser.cpython-312.pyc b/src/__pycache__/adminUser.cpython-312.pyc index 1ce0eee75e4ec8ac2a3496117bc7619a00e5d8ac..59b6ca51d02eb599240a53f84bd560ae3b735992 100644 Binary files a/src/__pycache__/adminUser.cpython-312.pyc and b/src/__pycache__/adminUser.cpython-312.pyc differ diff --git a/src/__pycache__/bookingObj.cpython-312.pyc b/src/__pycache__/bookingObj.cpython-312.pyc index a2f036df950fecf70e47eb294cfde883113a4db0..608b7ed8602e445546f3e6f5f05508f9f3851e13 100644 Binary files a/src/__pycache__/bookingObj.cpython-312.pyc and b/src/__pycache__/bookingObj.cpython-312.pyc differ diff --git a/src/__pycache__/cinemaObj.cpython-312.pyc b/src/__pycache__/cinemaObj.cpython-312.pyc index e886960bf7fa1ad9e95c8c9ebfe351b8cfbf70c9..8ed8d33b9767d6df731b780292a6cee3a72e52dc 100644 Binary files a/src/__pycache__/cinemaObj.cpython-312.pyc and b/src/__pycache__/cinemaObj.cpython-312.pyc differ diff --git a/src/__pycache__/constants.cpython-312.pyc b/src/__pycache__/constants.cpython-312.pyc index d0c5771a74f6e00d0d95ce63a28d65419c2fd8f8..7ee442bfdb3ba45e22195732f7d80ad565f07e9a 100644 Binary files a/src/__pycache__/constants.cpython-312.pyc and b/src/__pycache__/constants.cpython-312.pyc differ diff --git a/src/__pycache__/dbfunc.cpython-312.pyc b/src/__pycache__/dbfunc.cpython-312.pyc index baa613f041aa89555c1d081687cfd42919666024..eb843504dc7790e9bd0f122a324b2154a3d89437 100644 Binary files a/src/__pycache__/dbfunc.cpython-312.pyc and b/src/__pycache__/dbfunc.cpython-312.pyc differ diff --git a/src/__pycache__/managerUser.cpython-312.pyc b/src/__pycache__/managerUser.cpython-312.pyc index fb770360819bfadb7dbfbfa2ec63fd35edb6e544..ea3ceee10e626fb3e288ed6bfe4a169886048fc3 100644 Binary files a/src/__pycache__/managerUser.cpython-312.pyc and b/src/__pycache__/managerUser.cpython-312.pyc differ diff --git a/src/__pycache__/reportObj.cpython-312.pyc b/src/__pycache__/reportObj.cpython-312.pyc index 360bea155476c7b106ff54ed5768a1a7c5630e31..642554601c431f1833b8aa56b9135901b1a274e8 100644 Binary files a/src/__pycache__/reportObj.cpython-312.pyc and b/src/__pycache__/reportObj.cpython-312.pyc differ diff --git a/src/__pycache__/screenObj.cpython-312.pyc b/src/__pycache__/screenObj.cpython-312.pyc index 25f1508332319a4a30b6e008a412499ac94d1c45..818715ed3fa550818788af402c31924b8c63a4cd 100644 Binary files a/src/__pycache__/screenObj.cpython-312.pyc and b/src/__pycache__/screenObj.cpython-312.pyc differ diff --git a/src/__pycache__/staffUser.cpython-312.pyc b/src/__pycache__/staffUser.cpython-312.pyc index ae126525ad63e99d11e39104430142ead3fe4212..7646ac2ece181c549112fca4ccf3c14f045548b3 100644 Binary files a/src/__pycache__/staffUser.cpython-312.pyc and b/src/__pycache__/staffUser.cpython-312.pyc differ diff --git a/src/constants.py b/src/constants.py index b8ca0ff898ad48ba62d5b19d2d7d2667cc42ca33..348dab207ed55090fbf5194f13730357db1f755c 100644 --- a/src/constants.py +++ b/src/constants.py @@ -19,3 +19,8 @@ MAX_CAP:int = 500 """Maximum screen room seating capacity""" MIN_CAP:int = 0 """Minimum screen room seating capacity""" + +# filmObject: + + +#cinemaObject: diff --git a/src/dbfunc.py b/src/dbfunc.py index e0190f031d0bbc7afe43b7dbfe658b98dc98e2fa..72465bd373043759022724402d5aa41653169cce 100644 --- a/src/dbfunc.py +++ b/src/dbfunc.py @@ -1,10 +1,12 @@ -import logging, json, mysql +import logging, json, mysql.connector from .constants import DBNAME, DBHOSTNAME, DBUSERNAME, DBPASSWORD from mysql.connector import errorcode + + def getConnection(db=""): # if specified database if db != "": @@ -115,9 +117,16 @@ def select_from_tbl_where(table:str, condition:str, dbname:str=DBNAME, *args:str raise ConnectionError() -def save_to_Tbl(table, dbname, jsonData): +def save_to_Tbl(table, data): """need to fix""" - logging.debug(f"running update statment with values: tablename='{table}', dbname='{dbname}', data='{jsonData}'") + logging.debug(f"running update statment with values: tablename='{table}', data='{data}'") + if type(data) is json: + data = json.loads(data) + elif type(data) is dict: + pass + else: + raise TypeError() + conn = getConnection(db=DBNAME) if conn == None: logging.error("conn returned NoneType") @@ -125,10 +134,10 @@ def save_to_Tbl(table, dbname, jsonData): if conn.is_connected(): logging.debug("MySQL Connection is established.") INSERT_statement = f"INSERT INTO {table} (" - dictData = json.loads(jsonData) + keys = "" values = "" - for key, value in dictData.items(): + for key, value in data.items(): keys.append(f"{key}, ") values.append(f"{value}, ") INSERT_statement.append(f"{keys.removesuffix(", ")}) VALUES ({values.removesuffix(", ")});") diff --git a/src/reciptObj.py b/src/reciptObj.py new file mode 100644 index 0000000000000000000000000000000000000000..30cac69180247643126b281e156eb49cee95310e --- /dev/null +++ b/src/reciptObj.py @@ -0,0 +1,35 @@ +from .constants import DBNAME +from .dbfunc import * +import pandas as pd + + +class Recipt(object): + """_summary_ + + Args: + object (_type_): _description_ + """ + + def __init__(self) -> None: + # on creation, call SQL report from server..? + pass + + def display_cli(self) -> str: + """ output self attributes in a string readable format. """ + data = self.__dict__ + data = pd.DataFrame.from_dict(data, orient="index") + return data + + def display_GUI(self): + # output attributes in format for GUI.py + pass + + + + + + +if __name__ == "__main__": + # testing + test = Recipt() + print(test.display_cli()) \ No newline at end of file diff --git a/src/reportObj.py b/src/reportObj.py index 0252017c801a17628b11241251da43ebd62987f1..f9d86f402e355db9d1f38bdcc84cfe7e0d33ae12 100644 --- a/src/reportObj.py +++ b/src/reportObj.py @@ -1,3 +1,8 @@ + +# +# Currently not sure if this object is required, as the reports will be generated by the database...? +# + class Report(object): """_summary_ diff --git a/src/staffUser.py b/src/staffUser.py index cc4ba0043e6add3e2b02aa26f4b65f06fb360e17..4cf93e0668b120cf804675019fbd3b52ece7407f 100644 --- a/src/staffUser.py +++ b/src/staffUser.py @@ -3,14 +3,17 @@ from .constants import DBNAME from .dbfunc import * from .cinemaObj import Cinema + # trying to make this a base implementation for all user classes. -class StaffUser(object): +class StaffUser(object): def __init__(self): - + # staff id number assigned by manager during onboarding. self.userID:int = 0 self.userName:str = "" self.userPass:str = "" + # staff software level. self.permissionLevel:int = 0 + # list of branches active at. self.cinemas = [] def __str__(self): @@ -30,19 +33,19 @@ class StaffUser(object): self.cinemas[i] = Cinema(id=i) def _save_self_to_db(self) -> None: - """save self.__dict__ to db.""" - logging.debug("called _save_self_to_db func") + """save a jason of all self attributes to db. internal function.""" + selfDir = self.__dict__ # pull out class variables and values as dict + logging.debug(f"called _save_self_to_db func with data:{selfDir}") try: - save_to_Tbl("tblUsers", DBNAME, self.__dict__) + save_to_Tbl("tblUsers", DBNAME, selfDir) except Exception as e: - logging.error(e.message, e.args) + logging.error(e) def logout(self) -> None: """save to database then """ logging.debug("called logout func") logging.info(f"user {self.userID} logging out.") self._save_self_to_db() - self.close() def return_film_listings(self) -> list: """gets film listings from cinema object"""