import datetime from crud import * def add_person(): first_name = input('First name: ') last_name = input('Last name: ') date = datetime.date.fromisoformat(input('Date (YYYY-MM-DD): ')) person_model = PersonModel(first_name=first_name, last_name=last_name, date=date) print("Adding Person ...") db_add_person(person_model) print("Person added") return None def list_person(): query_filter = input('Filter: ') if query_filter: person_list = db_list_person(query_filter) else: person_list = db_list_person() for person in person_list.tuples().iterator(): print(person) return None def edit_person(): person_id = int(input('Person ID: ')) person = Person.get(id=person_id) first_name = input(f'First name [{person.first_name}]: ') if first_name == '': first_name = person.first_name last_name = input(f'Last name [{person.last_name}]: ') if last_name == '': last_name = person.last_name date = datetime.date.fromisoformat(input(f'Date [{datetime.date.isoformat(person.date)}]: ')) if date == '': date = person.date print('Editing Person...') db_edit_person(person_id, person_model=PersonModel(first_name=first_name, last_name=last_name, date=date)) print('Person edited') return None def delete_person(): person_id = int(input('Person ID: ')) print('Deleting Person...') db_delete_person(person_id) print('Person deleted') return None def add_resource(): name = input('Resource name: ') resource_model = ResourceModel(name=name) print("Adding Resource...") db_add_resource(resource_model) print("Resource added") return None def list_resource(): query_filter = input('Filter: ') if query_filter: resource_list = db_list_resource(query_filter) else: resource_list = db_list_resource() for resource in resource_list.tuples().iterator(): print(resource) return None def edit_resource(): resource_id = int(input('Resource ID: ')) resource = Resource.get(id=resource_id) # Editing name name = input(f'Resource name [{resource.name}]: ') if name == '': name = resource.name # Editing resource print('Editing Resource...') db_edit_resource(resource_id, resource_model=ResourceModel(name=name)) print('Resource edited') return None def delete_resource(): resource_id = int(input('Resource ID: ')) print('Deleting Resource...') db_delete_resource(resource_id) print('Resource deleted') return None def add_role(): name = input('Role Name: ') description = input('Role Description: ') role_model = RoleModel(name=name, description=description) print("Adding Role...") db_add_role(role_model) print("Role added") return None def list_role(): query_filter = input('Filter: ') if query_filter: role_list = db_list_role(query_filter) else: role_list = db_list_role() for role in role_list.tuples().iterator(): print(role) return None def edit_role(): role_id = int(input('Role ID: ')) role = Role.get(id=role_id) # Editing name name = input(f'Role name [{role.name}]: ') if name == '': name = role.name # Editing description description = input(f'Role description [{role.description}]: ') if description == '': description = role.description # Editing role print('Editing Role...') db_edit_role(role_id, role_model=RoleModel(name=name, description=description)) print('Role edited') return None def delete_role(): role_id = int(input('Role ID: ')) print('Deleting Role...') db_delete_role(role_id) print('Role deleted') return None def add_permission(): resource_id = int(input('Resource ID: ')) role_id = int(input('Role ID: ')) name = input('Permission Name: ') description = input('Permission Description: ') permission_model = PermissionModel(name=name, idResource=resource_id, idRole=role_id, description=description) print("Adding Permission...") db_add_permission(permission_model) print("Permission added") return None def list_permission(): query_filter = input('Filter: ') if query_filter: permission_list = db_list_permission(query_filter) else: permission_list = db_list_permission() for permission in permission_list.tuples().iterator(): print(permission) return None def edit_permission(): permission_id = int(input('Permission ID: ')) permission = Permission.get(id=permission_id) # Editing name name = input(f'Permission name [{permission.name}]: ') if name == '': name = permission.name # Editing description description = input(f'Permission description [{permission.description}]: ') if description == '': description = permission.description # Editing resource resource_id = input(f'Resource ID [{permission.idResource}]: ') if resource_id == '': resource_id = permission.idResource # Editing role role_id = input(f'Role ID [{permission.idRole}]: ') if role_id == '': role_id = permission.idRole # Editing permission print('Editing Permission...') db_edit_permission(permission_id, permission_model=PermissionModel(name=name, idResource=resource_id, idRole=role_id, description=description)) print('Permission edited') return None def delete_permission(): permission_id = int(input('Permission ID: ')) print('Deleting Permission...') db_delete_permission(permission_id) print('Permission deleted') return None def add_user_account(): username = input('Username: ') person_id = int(input('Person ID: ')) resource_id = int(input('Resource ID: ')) role_id = int(input('Role ID: ')) date = datetime.date.fromisoformat(input('Date (YYYY-MM-DD): ')) user_account_model = UserAccountModel(username=username, idPerson=person_id, idResource=resource_id, idRole=role_id, date=date) print("Adding User Account...") db_add_user_account(user_account_model) print("User Account added") return None def list_user_account(): query_filter = input('Filter: ') if query_filter: user_account_list = db_list_user_account(query_filter) else: user_account_list = db_list_user_account() for user_account in user_account_list.tuples().iterator(): print(user_account) return None def edit_user_account(): user_account_id = int(input('User Account ID: ')) user_account = UserAccount.get(id=user_account_id) # Editing username username = input(f'User Account username [{user_account.username}]: ') if username == '': username = user_account.username # Editing person person_id = input(f'User Account person ID [{user_account.idPerson}]') if person_id == '': person_id = user_account.idPerson # Editing resource resource_id = input(f'User Account resource ID [{user_account.idResource}]') if resource_id == '': resource_id = user_account.idResource # Editing role role_id = input(f'User Account role ID [{user_account.idRole}]') if role_id == '': role_id = user_account.idRole # Editing date date = datetime.date.fromisoformat(input(f'User Account date [{datetime.date.isoformat(user_account.date)}]: ')) if date == '': date = user_account.date # Editing user account print('Editing User Account...') db_edit_user_account(user_account_id, user_account_model=UserAccountModel(username=username, idPerson=person_id, idResource=resource_id, idRole=role_id, date=date)) print('User Account edited') return None def delete_user_account(): user_account_id = int(input('User Account ID: ')) print('Deleting User Account...') db_delete_user_account(user_account_id) print('User Account deleted') return None