Skip to content

Commit

Permalink
UI changes (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerlight071 authored Feb 7, 2024
2 parents 3c8259a + 171caed commit 581da1c
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 117 deletions.
5 changes: 4 additions & 1 deletion N_P_P.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from view_animals import view_animals
from common_functions import clear_screen, log_action, hash_password, get_mongodb_uri
from login import login
from client_database import client_database
from pymongo import MongoClient

get_mongodb_uri()
Expand Down Expand Up @@ -81,8 +82,10 @@ def main():
# Client Database
elif option == '2' and user_level >= 2:
log_action(current_user, "Entered 'Client Database'")
print("This feature is coming soon.")
time.sleep(2)
clear_screen()
client_database()


# Staff Portal
elif option == '3' and user_level == 3:
Expand Down
7 changes: 6 additions & 1 deletion add_animal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time
from colorama import Fore, Style
from common_functions import clear_screen, log_action, get_mongodb_uri
from common_functions import clear_screen, log_action, get_mongodb_uri, print_animal_table, load_animal_data
from sudo_user import sudo_user
from pymongo import MongoClient

Expand All @@ -12,6 +12,9 @@
animals_collection = db['animals']

def add_animal():

animals = load_animal_data(animals_collection)

# Continuous loop for adding animals
while True:
clear_screen()
Expand All @@ -30,6 +33,8 @@ def add_animal():
if name.lower() == 'exit':
print("\nExiting..." + Style.RESET_ALL)
time.sleep(2)
clear_screen()
print_animal_table(animals)
break

species = input(Fore.GREEN + "Species: " + Style.RESET_ALL).strip().capitalize() # Capitalize the first letter
Expand Down
12 changes: 6 additions & 6 deletions admin_dashboard.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import time
from colorama import Fore, Style
from common_functions import clear_screen, log_action
from register import register
from user_management import user_management

def admin_dashboard():
# Continuous loop for admin dashboard
while True:
clear_screen()
print(Fore.YELLOW + "\nADMIN Dashboard\n" + Style.RESET_ALL)
print("1. Register a new user")
print("2. User Management")
print(Fore.YELLOW + "\nADMIN Dashboard" + Style.RESET_ALL)
print("\n1. User Management")
print("2. Audit Logs")
print("3. Manage settings")
print("4. Logout")

option = input("\nPlease select an option: ")

# Check user input and perform corresponding action
if option == '1':
register()
elif option == '2':
user_management()
elif option == '2':
print("\nThis feature is under development.")
elif option == '3':
# ! Implement settings management
print("\nThis feature is under development.")
Expand Down
79 changes: 79 additions & 0 deletions client_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import time
from colorama import Fore, Style
from common_functions import clear_screen
from customer_adoption_form import view_available_animals

def modify_clint_database():
clear_screen()

print(Fore.CYAN + "\n📝 Modify Database 📝" + Style.RESET_ALL)
print("\n1. " + Fore.GREEN + "Add Client" + Style.RESET_ALL)
print("2. " + Fore.GREEN + "Modify Client" + Style.RESET_ALL)
print("3. " + Fore.GREEN + "Remove Client" + Style.RESET_ALL)
print("4. " + Fore.YELLOW + "Exit" + Style.RESET_ALL)

choice = input("\nPlease select an option: ")

if choice == '1':
print(Fore.GREEN + "\nOpening Customer Adoption Form..." + Style.RESET_ALL)
time.sleep(1)
clear_screen()
view_available_animals()

elif choice == '2':
print("\nThis feature is coming soon.")
time.sleep(2)
clear_screen()

elif choice == '3':
print("\nThis feature is coming soon.")
time.sleep(2)
clear_screen()

elif choice == '4':
print("\nExiting Modify Database...")
time.sleep(1)
clear_screen()
return

else:
print(Fore.RED + "Invalid input. Please try again." + Style.RESET_ALL)
time.sleep(2)
clear_screen()
modify_clint_database()

def client_database():
print(Fore.CYAN + "\n🧑 Client Database 🧑" + Style.RESET_ALL)
print("\n1. " + Fore.GREEN + "🔍 Search" + Style.RESET_ALL)
print("2. " + Fore.GREEN + "📝 Modify Database" + Style.RESET_ALL)
print("3. " + Fore.GREEN + "📁 Export Database" + Style.RESET_ALL)
print("4. " + Fore.YELLOW + "🔐 Exit" + Style.RESET_ALL)
choice = input("\nPlease select an option: ")

if choice == '1':
print("This feature is coming soon.")
time.sleep(2)
clear_screen()

elif choice == '2':
time.sleep(1)
clear_screen()
modify_clint_database()

elif choice == '3':
print("This feature is coming soon.")
time.sleep(2)
clear_screen()

elif choice == '4':
print("Exiting Client Database...")
time.sleep(1)
clear_screen()
return

else:
print(Fore.RED + "\nInvalid input. Please try again." + Style.RESET_ALL)
time.sleep(2)
clear_screen()
client_database()

6 changes: 1 addition & 5 deletions common_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ def get_mongodb_uri():
#! One time use until proper implementation
# Function to print the table of animals
def print_animal_table(animals):
"""
Print a formatted table of animals with their attributes.
Args:
animals (dict): Dictionary containing animal data.
"""

# Print table header
print("\n🐾 " + Fore.CYAN + "List of Animals" + Style.RESET_ALL + " 🐾")
print("+-------------------------------------------------------------------------------------------+")
Expand Down
16 changes: 4 additions & 12 deletions customer_adoption_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
customers_collection = db['customers']

def display_available_animals():
"""
Display a formatted table of available animals for adoption.
"""

clear_screen()
print("\n🐾 " + Fore.CYAN + "Available Animals for Adoption" + Style.RESET_ALL + " 🐾")
print("+------------------------------------------------------------------------------+")
Expand All @@ -30,9 +28,7 @@ def display_available_animals():
print("+------------------------------------------------------------------------------+")

def search_animals_by_name(name):
"""
Search for animals by name and display them with their original index numbers.
"""

clear_screen()
print("\n🐾 " + Fore.CYAN + "Available Animals for Adoption" + Style.RESET_ALL + " 🐾")
print("+------------------------------------------------------------------------------+")
Expand All @@ -57,9 +53,7 @@ def search_animals_by_name(name):
return animals

def adopt_animal(selected_animal):
"""
Allow staff to assist customers in adopting an available animal.
"""

if selected_animal:
print("\nPlease provide the following information for adoption:")
# Input validation loop
Expand Down Expand Up @@ -146,9 +140,7 @@ def adopt_animal(selected_animal):
clear_screen()

def view_available_animals():
"""
Display available animals and provide options to assist customers in adoption.
"""

clear_screen()
sudo_user()

Expand Down
17 changes: 15 additions & 2 deletions edit_animal_entries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from common_functions import clear_screen, get_mongodb_uri
from common_functions import clear_screen, get_mongodb_uri, print_animal_table, load_animal_data
from colorama import Fore, Style
from pymongo import MongoClient
from sudo_user import sudo_user
Expand All @@ -11,13 +11,24 @@
db = client['animal_rescue']
animals_collection = db['animals']


def modify_animal():

animals = load_animal_data(animals_collection)

clear_screen()
sudo_user()
print(Fore.CYAN + "\n🐾 Modify Animal 🐾\n" + Style.RESET_ALL)

# Input the name of the animal to modify
animal_name = input(Fore.CYAN + "Enter the name of the animal to modify: " + Style.RESET_ALL).strip().capitalize()
animal_name = input(Fore.CYAN + "Enter the name of the animal to modify (enter 'exit' to leave): " + Style.RESET_ALL).strip().capitalize()

if animal_name.lower() == 'exit':
print(Fore.YELLOW + "\nExiting..." + Style.RESET_ALL)
time.sleep(2)
clear_screen()
print_animal_table(animals)
return

# Search for the animal in the database
animal = animals_collection.find_one({'name': animal_name})
Expand Down Expand Up @@ -85,5 +96,7 @@ def modify_animal():
else:
print(Fore.RED + "Animal not found." + Style.RESET_ALL)
time.sleep(2)
clear_screen()
modify_animal()

input("Press Enter to continue...")
2 changes: 1 addition & 1 deletion sudo_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def sudo_admin():
# Continuous loop for sudo user authentication
attempts = 0
while attempts < MAX_ATTEMPTS:
print(Fore.LIGHTMAGENTA_EX + "\n👤 Sudo Login 👤" + Style.RESET_ALL)
print(Fore.LIGHTMAGENTA_EX + "\n👤 ADMIN Sudo Login 👤" + Style.RESET_ALL)
print("\nPlease enter your credentials")
username = input("\nEnter your username: ")
password = getpass.getpass("Enter your password: ")
Expand Down
39 changes: 24 additions & 15 deletions user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,27 @@ def user_management():
# Continuous loop for user management options
while True:
clear_screen()
print(Fore.YELLOW + "\nUser Management\n" + Style.RESET_ALL)
print("1. Change user password")
print("2. Update user information")
print("3. Delete user")
print("4. Back to admin dashboard")
print(Fore.YELLOW + "\nUser Management" + Style.RESET_ALL)
print("\n1. Update user information")
print("2. Delete user")
print("3. Back to ADMIN dashboard")
option = input("\nPlease select an option: ")

# Perform actions based on user input
if option == '1':
reset_user_password()
elif option == '2':
update_user_information()
elif option == '3':
elif option == '2':
delete_user()
elif option == '4':
print("\nReturning to admin dashboard...")
elif option == '3':
print("\nReturning to ADMIN dashboard...")
time.sleep(2)
return
else:
print(Fore.RED + "\nInvalid option. Please try again." + Style.RESET_ALL)
time.sleep(2)

def reset_user_password():
# Prompt for username and new password
username = input("\nEnter the username to change the password: ")
def reset_user_password(username):
# Check if the user is ADMIN
sudo_admin()

# Change password if the user exists and is not ADMIN
Expand Down Expand Up @@ -78,18 +74,21 @@ def update_user_information():
print("\nSelect the information you want to update:")
print("\n1. Username")
print("2. User Level")
print("3. Cancel")
print("3. Reset Password")
print("4. Cancel")

option = input("\nEnter your choice: ")

# Process user's choice and perform updates accordingly
# New Username
if option == '1':
new_username = input("Enter the new username: ")
if not users_collection.find_one({'username': new_username}):
users_collection.update_one({'username': username}, {'$set': {'username': new_username}})
print(Fore.GREEN + f"\nUsername updated successfully to '{new_username}'!" + Style.RESET_ALL)
else:
print(Fore.RED + f"\nUsername '{new_username}' already exists. Please choose a different username." + Style.RESET_ALL)

# New User Level
elif option == '2':
new_level = input("Enter the new user level: ")
if new_level.isdigit(): # Check if the input is a valid integer
Expand All @@ -98,12 +97,22 @@ def update_user_information():
print(Fore.GREEN + f"\nUser level updated successfully for '{username}'!" + Style.RESET_ALL)
else:
print(Fore.RED + "\nInvalid user level. Please enter a valid level." + Style.RESET_ALL)

# Reset Password
elif option == '3':
time.sleep(2)
reset_user_password(username)

# Cancel
elif option == '4':
print("\nOperation canceled.")
else:
print(Fore.RED + "\nInvalid option. Please try again." + Style.RESET_ALL)

# Throw error if user does not exist or is ADMIN
elif username == "ADMIN":
print(Fore.RED + "\nYou cannot update information for the ADMIN user." + Style.RESET_ALL)

else:
print(Fore.RED + f"\nUser '{username}' not found." + Style.RESET_ALL)

Expand Down
Loading

0 comments on commit 581da1c

Please sign in to comment.