sys.excepthook = log_exception form = cgi.FieldStorage() print "Content-type: text/plain\n" action = form.getvalue("action") if action == "count": if "id" in form and "count" in form: item = db.get_item(int(form.getvalue("id"))) item.set_count(int(form.getvalue("count"))) if "exp_date" in form: speculate_date = datetime.datetime.strptime(form.getvalue("exp_date"), "%A %m/%d/%y") days_to_speculate = (speculate_date - datetime.datetime.now()).days count = item.get_count() day14 = db.get_sales_in_range(int(form.getvalue("id")), 14) speculated = count - day14 / 14 * days_to_speculate # days_to_speculate determined outside of loop print "%d,%d" % (speculated, count) else: print item.get_count() elif action == "status": if "id" in form and "stocked" in form: item = db.get_item(int(form.getvalue("id"))) if form.getvalue("stocked") == "true": db.set_item_discontinued(item, 0) else: db.set_item_discontinued(item, 1) elif action == "delivery": if "id" in form and "amt" in form and "dist" in form: itemid = int(form.getvalue("id")) db.add_delivery(itemid, int(form.getvalue("amt")), form.getvalue("dist"))
def main(): form = cgi.FieldStorage() idf.init(form,discontinued=True,distributors=True,categories=True) print_headers() print ''' <body>''' print ''' <div class="key"> Key: <span class="na"> very negative (produce, etc.) </span> <span class="bad"> slightly negative (counting error?) </span> <span class="out"> out (0 in stock) </span> <span class="low"> <14 day supply in stock </span> </div> <div>Click table headers to sort</div> <div>Click distributor to change info there. + or - signs add or remove the distributor respectively. To change any of the other columns make your modifications and click the word update at the end of the row.</div> <div>Note that this currently only supports SINGLE barcodes, and needs to be redone (probably in a similar manner to categories etc) to support multiple </div> <div>The M-Edit checkbox allows you to add/remove things to multiple items at once </div> <div style="clear: both; height: 15px;"> </div>''' print '''</body></html>''' print_multi_add() print '''<form name="options" action="manage_items.py" method="get">''' options = idf.print_form() print '''<input type="submit" value="Change options" /> </form>''' print '''<br> <br>''' print '''<table border=0 id="main" class="sortable" cellspacing=0 cellpadding=0> <thead class="col-header"> <th class="th">M-Edit</th> <th class="th">Name</th> <th class="th">Dist Info</th> <th class="th">OP SKU</th> <th class="th">Barcodes</th> <th class="th">Category</th> <th class="th">Tax Category</th> <th class="th">Stocked</th> </thead><tbody id=\"item-stats\">\n''' for i,item in enumerate(db.get_items(**options)): count = item.get_count() item_id = item.get_id() day14 = db.get_sales_in_range(item_id,14) if count < -10.0: print '''<tr id="tr_%d" class="na" title="%d">''' % (item_id,day14) elif count < 0.0: print '''<tr id="tr_%d" class="bad" title="%d">''' % (item_id,day14) elif count < 1.0: print '''<tr id="tr_%d" class="out" title="%d">''' % (item_id,day14) elif count < day14: print '''<tr id="tr_%d" class="low" title="%d">''' % (item_id,day14) else: print '<tr id="tr_%d" title="%d">' % (item_id,day14) print '''<div class='div_%d'>''' % (item_id) print '''<td> <input class="multi" type="checkbox" id="%d" /></td>''' % (item_id,) print '''<td><input type="text" class="itemname" id="%d_name" value="%s" />[%s]''' % (item.get_id(), item.get_name(),item.get_size_str()) print '''<td id="%d_dist" style='border-left: 1px solid #999; border-right: 1px solid #999; padding-left: 1em;'> %s </td>''' % (item_id, item.get_distributors_str()) print '''<td style='text-align: center;'> <a href="%s" onclick="window.open(this.href,'_blank'); return false;">%d </a></td>''' % (db.get_item_info_page_link(item_id),item_id) barcode = item.get_first_barcode() if barcode != None: print '''<td> <input size="16" type="text" class="itembarcode" id="%d_%s_bc" value="%s" /> </td>''' % (item_id,barcode.get_barcode(), barcode.get_barcode()) else: print '''<td> <input size="16" type="text" class="itembarcode" id="%d_%s_bc" value="%s" /> </td>''' % (item_id, 'None', 'None') print '''<td style='border-left: 1px solid #999; border-right: 1px solid #999;' id='%d_cat'> %s </td>''' % (item_id, item.get_categories_str(), ) print '''<td style='border-right: 1px solid #999;' id='%d_tax'> %s </td>''' % (item_id, str(item.get_tax_category()), ) if not item.get_is_discontinued(): print '''<td><input type="checkbox" id="%d_isStocked" onClick="discontinueItem(this)" checked /> </td>''' % (item_id,) else: print '''<td><input type="checkbox" id="%d_isStocked" onClick="discontinueItem(this)"/> </td>''' % (item_id,) print '''</div>''' print '''</tr>\n''' print '''</tbody></table>\n''' print '''</body></html>'''