From 51edd1bdc1f802fd09d37b727ce83d1726a597e6 Mon Sep 17 00:00:00 2001 From: Jan-Pieter Baert Date: Sat, 7 Sep 2019 15:05:24 +0200 Subject: [PATCH] Add typing to database files --- app/database/add_admins.py | 2 +- app/database/add_fitchen.py | 2 +- app/database/add_oceans_garden.py | 6 +++--- app/database/add_primadonna.py | 4 ++-- app/database/add_simpizza.py | 2 +- app/database/add_stefanos.py | 6 +++--- app/database/create_database.py | 24 ++++++++++++------------ 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/database/add_admins.py b/app/database/add_admins.py index c3dff1f..cb385c7 100644 --- a/app/database/add_admins.py +++ b/app/database/add_admins.py @@ -2,7 +2,7 @@ from app import db from models import User -def add(): +def add() -> None: feli = User() feli.configure("feliciaan", True, 0) db.session.add(feli) diff --git a/app/database/add_fitchen.py b/app/database/add_fitchen.py index 8e7ff9b..ab05012 100644 --- a/app/database/add_fitchen.py +++ b/app/database/add_fitchen.py @@ -23,7 +23,7 @@ menuitems = [ pricedict = {"Small": 799, "Medium": 999, "Large": 1199} -def add(): +def add() -> None: simpizza = Location() simpizza.configure("Fitchen", "?", "?", "https://www.fitchen.be/") db.session.add(simpizza) diff --git a/app/database/add_oceans_garden.py b/app/database/add_oceans_garden.py index 0954fc5..8c2b87a 100644 --- a/app/database/add_oceans_garden.py +++ b/app/database/add_oceans_garden.py @@ -29,7 +29,7 @@ specials = [ ] -def add(): +def add() -> None: chinees = Location() chinees.configure( "Oceans's Garden", @@ -39,12 +39,12 @@ def add(): ) db.session.add(chinees) - def chinees_create_entry(name): + def chinees_create_entry(name) -> None: entry = Product() entry.configure(chinees, name, 550) db.session.add(entry) - def chinees_create_regulat(zetmeel, vlees="", saus=""): + def chinees_create_regulat(zetmeel, vlees="", saus="") -> None: chinees_create_entry("{} {} {}".format(zetmeel, vlees, saus).rstrip()) for z, v, s in product(zetmelen, vlezen, sauzen): diff --git a/app/database/add_primadonna.py b/app/database/add_primadonna.py index 28aa564..3140742 100644 --- a/app/database/add_primadonna.py +++ b/app/database/add_primadonna.py @@ -46,7 +46,7 @@ pizzasTA = { } -def addTA(): +def addTA() -> None: primadonna_takeaway = Location() primadonna_takeaway.configure( "Primadonna (takeaway laten bezorgen)", @@ -101,7 +101,7 @@ pizzasAfhalen = { } -def addAfhalen(): +def addAfhalen() -> None: primadonna_afhalen = Location() primadonna_afhalen.configure( "Primadonna (bellen en afhalen)", diff --git a/app/database/add_simpizza.py b/app/database/add_simpizza.py index e653195..5f5f169 100644 --- a/app/database/add_simpizza.py +++ b/app/database/add_simpizza.py @@ -33,7 +33,7 @@ pizzas = [ ] -def add(): +def add() -> None: simpizza = Location() simpizza.configure( "Sim-pizza", diff --git a/app/database/add_stefanos.py b/app/database/add_stefanos.py index 35f7a38..b3b8f45 100644 --- a/app/database/add_stefanos.py +++ b/app/database/add_stefanos.py @@ -11,7 +11,7 @@ bickies = { "Bicky Veggie": 350, } -saus = { +sauskes = { "american": 70, "andalouse": 70, "bicky saus": 70, @@ -100,7 +100,7 @@ friet = {"Klein pak": 200, "Midden pak": 250, "Groot pak": 300} data = [special_bickies, specials, vlezekes, friet] -def add(): +def add() -> None: stefanos = Location() stefanos.configure( "Stefano's Place", @@ -127,7 +127,7 @@ def add(): db.session.add(item) # saus in een potteke bestellen is 10 cent extra - for name, price in saus.items(): + for name, price in sauskes.items(): saus = Product() saus.configure(stefanos, name, price) db.session.add(saus) diff --git a/app/database/create_database.py b/app/database/create_database.py index 244e212..59178cd 100644 --- a/app/database/create_database.py +++ b/app/database/create_database.py @@ -15,23 +15,23 @@ no = ["no", "n", "N"] # Commit all the things -def commit(): +def commit() -> None: db.session.commit() print("Committing successful") -def check_if_overwrite(): +def check_if_overwrite() -> bool: answer = input("Do you want to overwrite the previous database? (y/N) ") return answer in yes -def add_all(): +def add_all() -> None: for entry_set in entry_sets.keys(): print("Adding {}.".format(entry_set)) entry_sets[entry_set]() -def recreate_from_scratch(): +def recreate_from_scratch() -> None: confirmation = "Are you very very sure? (Will delete previous entries!) (y/N) " check = "I acknowledge any repercussions!" if input(confirmation) in yes and input("Type: '{}' ".format(check)) == check: @@ -41,10 +41,10 @@ def recreate_from_scratch(): add_to_current() -def add_to_current(): +def add_to_current() -> None: available = [entry_set for entry_set in entry_sets] - def add_numbers(): + def add_numbers() -> str: return " ".join( ["{}({}), ".format(loc, i) for i, loc in enumerate(available)] ).rstrip(", ") @@ -59,17 +59,17 @@ def add_to_current(): available = [] elif answer == "C": pass - elif answer in [str(x) for x in range(len(available))]: - answer = int(answer) - print("Adding {}.".format(available[answer])) - entry_sets[str(available[answer])]() - del available[answer] + elif answer.isnumeric() and answer in [str(x) for x in range(len(available))]: + answer_index = int(answer) + print("Adding {}.".format(available[answer_index])) + entry_sets[str(available[answer_index])]() + del available[answer_index] else: print("Not a valid answer.") print("Thank you for adding, come again!") -def init(): +def init() -> None: print("Database modification script!") print("=============================\n\n") if check_if_overwrite():