def single_item(itemID): if longView: data = core.get_by_id(datafile, itemID) else: raw = core.get_by_id(datafile, itemID)[itemID] data = {itemID: {"make": raw.get("make"), "model": raw.get("model")}} return util.pretty_data(data)
def item_adder(): print("ADDING NEW ITEM") item = {} item = basic_settings(item) if item.get("cat") not in core.nodefaults: for x in core.defaults: item.update(enter_data(x)) elif item.get("cat") == core.categories[1]: for x in core.lensdefaults: item.update(enter_data(x)) elif item.get("cat") == core.categories[8]: for x in core.bookdefaults: item.update(enter_data(x)) if core.is_multiple(item): item.update(enter_data("number")) item.update({"links": []}) print(util.pretty_data(item)) if input_yn("add this?"): new = core.new_entry(datafile, item) datafile.update(new) core.clean_item(datafile, next(iter(new))) print(short_data(new)) return ("sweet! new toys.") else: return ("chucking all that work out the window")
def short_data(data): ids = core.get_all_ids(data) shortdata = {} for x in ids: raw = core.get_by_id(datafile, x)[x] item = { x: { "make": raw.get("make"), "model": raw.get("model"), "name": raw.get("name"), "nick": raw.get("nick") } } shortdata.update(item) return util.pretty_data(shortdata)
def search_data(): global lastSearch print("SEARCH FILTERS") print("--------------") search = {} search = basic_settings(search) ## other field fields = sorted(core.get_all_fields(datafile)) key = pick_list(fields, "other field") if key: print("what's your search phrase? (im cap sensitive, sorry) ", end="") search.update({key: input()}) ## process results print("search terms: " + str(search)) lastSearch = core.multisearch(datafile, search) for x in lastSearch: print(util.pretty_data(core.get_by_id(datafile, x))) return "total found: " + str(len(lastSearch))
def data_menu(): global scratch dataOptions = [ "show dataset", "show scratchpad", "clear scratchpad", "show last search", "toggle view", "view detail", "count items", "search", "edit item", "add item", "back to main" ] print("") print("DATA BROWSING") print("-------------") util.print_menu(dataOptions) print("\ntell me your desires (q to cancel): ", end="") choice = input() if choice == "0": print(show_dataset(datafile)) elif choice == "1": for x in scratch: print(util.pretty_data(core.get_by_id(datafile, x))) elif choice == "2": scratch = [] elif choice == "3": for x in lastSearch: print(util.pretty_data(core.get_by_id(datafile, x))) print("total found: " + str(len(lastSearch))) elif choice == "4": print(toggle_view()) elif choice == "5": print(divider) itemID = pick_id() if itemID == quickrel: print(quickrel) else: print(view_detail(itemID)) elif choice == "6": print(divider) print(count_data()) elif choice == "7": print(divider) print(search_data()) elif choice == "8": print(divider) itemID = pick_id() if itemID == quickrel: print(quickrel) else: print(edit_item(itemID)) elif choice == "9": print(item_adder()) elif choice == "10": return divider elif choice == 'q': return quickrel else: print(invalid) autosave() return data_menu()
def show_dataset(data): if longView: return util.pretty_data(data) else: return short_data(data)