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 pretty_data(data)
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 html_one(datafile, itemID): unit = [] item = core.get_by_id(datafile, itemID)[itemID] links = item.get("links") subclass = item.get("subcat") if subclass == "35mm": subclass = "thirtyfive" unit.append("<div class=\"item\"><div class=\""+subclass+"\"><a name=\""+itemID+"\"></a>") unit.append("\n\t<p><b>"+core.display_name(item)+"</b></p>") unit.append("\n\t<p><small><i>"+core.display_cat(item)+"</i></small></p>") if links: linktext = "\n\t<p>bundled with: " if item.get("cat") == core.categories[9]: linktext = "\n\t<p>kit contents: " #unit.append("\n\t<p>bundled with: ") unit.append(linktext) for x in links: unit.append("<a href=\"#"+x+"\">"+core.display_name(core.get_by_id(datafile, x)[x])+"</a> ") unit.append("</p>") unit.append("\n\t<p align=\"right\"><small>"+colored_status(item)+"</small></p>") unit.append("\n\t<div class=\"meta\"><p><small>"+itemID+" "+str(item)+"</small></p></div>") unit.append("\n</div></div>\n") return "".join(unit)
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("-------------") 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(pretty_data(core.get_by_id(datafile, x))) elif choice == "2": scratch = [] elif choice == "3": for x in lastSearch: print(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 change_status(itemID): status = pick_list(core.statuses, "set status") links = get_links(itemID) for x in links: raw = core.get_by_id(datafile, x)[x] raw.update({"status": status}) return "status updated!"
def edit_item(itemID): raw = core.get_by_id(datafile, itemID)[itemID] fields = [] print("") print(single_item(itemID)) print("\nEDITING DEETS") i = 0 for x in sorted(raw.keys()): #for x in iter(raw): util.setrandcolor() print("\t[ ", end="") if i < 10: print(" ", end="") print(str(i)+" ] "+x+": "+str(raw.get(x))) i += 1 fields.append(x) util.resetcolor() print("\n\t[ a ] (add new field)") print("what do you want to edit? (q to cancel) ", end="") choice = input() if choice =='q': return quickrel if choice == "a": print("whatcha calling this new 'field'? ", end="") key = input() else: key = fields[int(choice)] raw.update(edit_field(key)) return edit_item(itemID)
def change_loc(itemID): loc = pick_list(core.locations, "set location") links = get_links(itemID) for x in links: raw = core.get_by_id(datafile, x)[x] raw.update({"loc":loc}) return "location updated!"
def change_status(itemID): status = pick_list(core.statuses, "set status") links = get_links(itemID) for x in links: raw = core.get_by_id(datafile, x)[x] raw.update({"status":status}) return "status updated!"
def change_loc(itemID): loc = pick_list(core.locations, "set location") links = get_links(itemID) for x in links: raw = core.get_by_id(datafile, x)[x] raw.update({"loc": loc}) return "location updated!"
def edit_item(itemID): raw = core.get_by_id(datafile, itemID)[itemID] fields = [] print("") print(single_item(itemID)) print("\nEDITING DEETS") i = 0 for x in sorted(raw.keys()): #for x in iter(raw): util.setrandcolor() print("\t[ ", end="") if i < 10: print(" ", end="") print(str(i) + " ] " + x + ": " + str(raw.get(x))) i += 1 fields.append(x) util.resetcolor() print("\n\t[ a ] (add new field)") print("what do you want to edit? (q to cancel) ", end="") choice = input() if choice == 'q': return quickrel if choice == "a": print("whatcha calling this new 'field'? ", end="") key = input() else: key = fields[int(choice)] raw.update(edit_field(key)) return edit_item(itemID)
def html_cat(datafile, category): # output everything of a certain category items = [] ids = core.get_all_ids(datafile) subcats = dict(zip(core.subcategories, [[],[],[],[],[]])) other = [] #print(category) for x in ids: item = core.get_by_id(datafile, x)[x] if item.get("cat") == category: subcat = item.get("subcat") if subcat and subcat != "none": subcats.get(subcat).append(x) else: other.append(x) for y in iter(subcats): for z in subcats.get(y): items.append(html_one(datafile, z)) for y in other: items.append(html_one(datafile, y)) return "".join(items)
def html_cat(datafile, category): # output everything of a certain category items = [] ids = core.get_all_ids(datafile) subcats = dict(zip(core.subcategories, [[], [], [], [], []])) other = [] #print(category) for x in ids: item = core.get_by_id(datafile, x)[x] if item.get("cat") == category: subcat = item.get("subcat") if subcat and subcat != "none": subcats.get(subcat).append(x) else: other.append(x) for y in iter(subcats): for z in subcats.get(y): items.append(html_one(datafile, z)) for y in other: items.append(html_one(datafile, y)) return "".join(items)
def get_links(itemID): links = [] target = core.get_by_id(datafile, itemID).get(itemID).get("links") if target: links.extend(target) links.append(itemID) return links
def update_time(itemID): # update itemID with current timestamp print("stamping " + itemID) item = { itemID: core.update_time(core.get_by_id(datafile, itemID).get(itemID)) } datafile.update(item)
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 pretty_data(shortdata)
def html_one(datafile, itemID): unit = [] item = core.get_by_id(datafile, itemID)[itemID] links = item.get("links") subclass = item.get("subcat") if subclass == "35mm": subclass = "thirtyfive" unit.append("<div class=\"item\"><div class=\"" + subclass + "\"><a name=\"" + itemID + "\"></a>") unit.append("\n\t<p><b>" + core.display_name(item) + "</b></p>") unit.append("\n\t<p><small><i>" + core.display_cat(item) + "</i></small></p>") if links: linktext = "\n\t<p>bundled with: " if item.get("cat") == core.categories[9]: linktext = "\n\t<p>kit contents: " #unit.append("\n\t<p>bundled with: ") unit.append(linktext) for x in links: unit.append("<a href=\"#" + x + "\">" + core.display_name(core.get_by_id(datafile, x)[x]) + "</a> ") unit.append("</p>") unit.append("\n\t<p align=\"right\"><small>" + colored_status(item) + "</small></p>") unit.append("\n\t<div class=\"meta\"><p><small>" + itemID + " " + str(item) + "</small></p></div>") unit.append("\n</div></div>\n") return "".join(unit)
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 link_item(itemID): print("what do you want to link this to? ", end="") target = pick_id() links = [itemID, target] for x in links: item = core.get_by_id(datafile, x) check = item.get(x).get("links") if check: for y in check: if y not in links: links.append(y) for x in links: print(single_item(x)) if input_yn("are you suuuuure you want to link them?"): core.link_ids(datafile, links) return "link successful" else: return "LINK ABORTED"
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(pretty_data(core.get_by_id(datafile, x))) return "total found: "+str(len(lastSearch))
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 sortable(datafile): outfile = open("/home/hvincent/projects/qmis/bin/www/test_sort.html", "w+") done = 0 total = 0 outfile.write("<html><head>\n<title>QMIS OUTPUT TEST</title>\n<script src=\"sorttable.js\"></script>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" /></link>\n</head>\n<body>") outfile.write("<p>this file is automatically generated from QMIS. do not take it too seriously right now.</p>\n\n") outfile.write("<p><i>last updated:<br>"+time.strftime("%d %b %Y, %H%M")+"</i></p>\n") outfile.write("<div class=\"dataset\">\n<table class=\"sortable\">") outfile.write("<th>Name</th><th>Make</th><th>Model</th><th>Category</th><th>S/N</th><th>CMU ID</th><th>Links</th><th>Last Updated</th><th>ID</th>\n") for itemID in datafile: total += 1 item = core.get_by_id(datafile, itemID)[itemID] outfile.write("<tr style=\"color:"+status_color(item)+"\"><td>") outfile.write(core.display_name(item)+"</td><td>") #outfile.write(str(item.get("name"))+"</td><td>") outfile.write(str(item.get("make"))+"</td><td>") outfile.write(str(item.get("model"))+"</td><td>") outfile.write(core.display_cat(item)+"</td><td>") #outfile.write(str(item.get("cat"))+"</td><td>") #outfile.write(str(item.get("subcat"))+"</td><td>") outfile.write(str(item.get("serial"))+"</td><td>") outfile.write(str(item.get("cmu"))+"</td><td>") links = item.get("links") if links: for ID in links: outfile.write("<a href=\"#"+ID+"\">"+core.display_name(core.get_by_id(datafile,ID)[ID])+"</a> ") else: outfile.write(" ") outfile.write("</td><td>") timestamp = item.get("last updated") color = "<font color=red>" if isinstance(timestamp, float): if timestamp > 1462398232: color = "<font color=green>" if item.get("status") not in nocount: done += 1 # comment this for closing check color = "" # if item.get("status") in nocount: total -= 1 #outfile.write(color+core.display_last_checked(item)+"</font></td><td>") outfile.write(color+str(timestamp)+"</font></td><td>") #outfile.write(str(item.get("last updated"))+"</td><td>") outfile.write("<font color=black>"+str(itemID)+"</font><a name=\""+itemID+"\"></a></td>") outfile.write("</tr>\n") outfile.write("</table>") completion = int(100*float(done)/float(total)) # (for closing check only # outfile.write("<div style=\"float:right; position:absolute;top:0em; right:.5em;\"><p>"+str(done)+"/"+str(total)+" ("+str(completion)+"%)</div>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("</body></html>") outfile.close()
def random_item(): ids = core.get_all_ids(datafile) return core.get_by_id(datafile, random.choice(ids))
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 sortable(datafile): outfile = open(BASEDIR + "/www/inventory.html", "w+") done = 0 total = 0 outfile.write( "<html><head>\n<title>QMIS OUTPUT TEST</title>\n<script src=\"sorttable.js\"></script>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" /></link>\n</head>\n<body>" ) outfile.write( "<p>this file is automatically generated from QMIS. do not take it too seriously right now.</p>\n\n" ) outfile.write("<p><i>last updated:<br>" + time.strftime("%d %b %Y, %H%M") + "</i></p>\n") outfile.write("<div class=\"dataset\">\n<table class=\"sortable\">") outfile.write( "<th>Name</th><th>Make</th><th>Model</th><th>Category</th><th>S/N</th><th>CMU ID</th><th>Links</th><th>Last Updated</th><th>ID</th>\n" ) for itemID in datafile: total += 1 item = core.get_by_id(datafile, itemID)[itemID] outfile.write("<tr style=\"color:" + status_color(item) + "\"><td>") outfile.write(core.display_name(item) + "</td><td>") #outfile.write(str(item.get("name"))+"</td><td>") outfile.write(str(item.get("make")) + "</td><td>") outfile.write(str(item.get("model")) + "</td><td>") outfile.write(core.display_cat(item) + "</td><td>") #outfile.write(str(item.get("cat"))+"</td><td>") #outfile.write(str(item.get("subcat"))+"</td><td>") outfile.write(str(item.get("serial")) + "</td><td>") outfile.write(str(item.get("cmu")) + "</td><td>") links = item.get("links") if links: for ID in links: outfile.write( "<a href=\"#" + ID + "\">" + core.display_name(core.get_by_id(datafile, ID)[ID]) + "</a> ") else: outfile.write(" ") outfile.write("</td><td>") timestamp = item.get("last updated") color = "<font color=red>" if isinstance(timestamp, float): ## set this for closing mode if timestamp > 1494350400: color = "<font color=green>" #if item.get("status") not in nocount: if item.get("status") in closing: done += 1 #timestamp = time.strftime("%Y-%m-%d:%H%M", time.localtime(timestamp)) # comment this for closing check color = "" # if item.get("status") not in closing: #if item.get("status") in nocount: total -= 1 outfile.write(color + str(timestamp) + "</font></td><td>") outfile.write("<font color=black>" + str(itemID) + "</font><a name=\"" + itemID + "\"></a></td>") outfile.write("</tr>\n") outfile.write("</table>") completion = int(100 * float(done) / float(total)) # (for closing check only #outfile.write("<div style=\"float:right; position:absolute;top:0em; right:.5em;\"><p>"+str(done)+"/"+str(total)+" ("+str(completion)+"%)</div>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("<p> </p>") outfile.write("</body></html>") outfile.close() print_status(done, total, completion)
def update_time(itemID): # update itemID with current timestamp print("stamping "+itemID) item = {itemID:core.update_time(core.get_by_id(datafile, itemID).get(itemID))} datafile.update(item)