def print_multi_add(): print '''<div class="fixed">''' print '''<select class="multi_dist" id="multi_dist">''' for dist in db.get_distributors(): print '''<option class="%d_dist_option" value="%d"> %s </option>''' % (dist.get_id(),dist.get_id(),dist) print '''</select>''' print '''<button type="button" onClick="multiAddDist()">Add Dist</button>''' print '''<button type="button" onClick="multiRemoveDist()">Remove Dist</button>''' print '''<select class="multi_category" id="multi_category">''' for cat in db.get_categories(): print '''<option class="%d_cat_option" value="%d"> %s </option>''' % (cat.get_id(),cat.get_id(),cat) print '''</select>''' print '''<button type="button" onClick="multiAddCategory()">Add Category</button>''' print '''<button type="button" onClick="multiRemoveCategory()">Remove Category</button>''' print '''<select class="addTaxCat" id="multi_tax_category">''' for taxcat in db.get_tax_categories(): print '''<option class="%d_taxcat_option" value="%d"> %s </option>''' % (taxcat.get_id(),taxcat.get_id(),taxcat) print '''</select>''' print '''<button type="button" onClick="multiSetTaxCategory()">Set TaxCat</button>''' print '''<button type="button" onClick="uncheckAllMulti()">Uncheck All Items </button>''' print '''</div>'''
def print_categories(): print '''<br /> Select Categories to display:''' if "allCats" in input_form: print '''<input name="allCats" type="checkbox" onClick="allCategories(this)" value="True" checked>All </input> <br />''' else: print '''<input name="allCats" type="checkbox" onClick="allCategories(this)" value="True">All </input> <br />''' print''' <table cellspacing=0 cellpadding=2 style="border-top: 1px solid #999; border-left: 1px solid #999;">''' hide_categories = [] # switching to displaying categories # hide_categories = db.get_categories() for i,cat in enumerate(db.get_categories()): if i % 5 == 0: if i> 0: print '''</tr>''' print '''<tr>''' test_str = "cat_%s" % str(cat) if test_str in input_form: print '''<td>%s</td><td style="border-right: 1px solid #999"><input class="categorybox" type="checkbox" name="cat_%s" value="True" checked/></td>''' % (cat,cat) hide_categories.append(cat) else: print '''<td>%s</td><td style="border-right: 1px solid #999"><input class="categorybox" type="checkbox" name="cat_%s" value="True" /></td>''' % (cat, cat) if (i+1) % 5 == 0: print '''</tr><tr>''' if "cat_No Category" in input_form: print '''<td>%s</td> <td style="border-right: 1px solid #999"><input class="categorybox" type="checkbox" name="cat_%s" value="True" checked/></td>''' % ("No Category", "No Category") hide_categoryless = False else: print '''<td>%s</td> <td style="border-right: 1px solid #999"><input class="categorybox" type="checkbox" name="cat_%s" value="True"/></td>''' % ("No Category", "No Category") hide_categoryless = True print '''</tr></table>''' return hide_categories,hide_categoryless
def print_categories(item): print '<table id="categories">' print '''<thead> <th>Category</th> <th>Remove</th> </thead>''' for category_item in item.get_category_items(): category = db.get_category(category_item.get_cat_id()) print '''<tr id="%d_category_tr"><td><a href="%s">%s</a></td><td><button type="button" onClick="removeCategory(%d)"> remove </button> </td>''' % (category_item.get_id(),db.get_category_info_page_link(category.get_id()),category.get_name(),category_item.get_id()) print '''</table>''' print '<select id="new_category">' for cat in db.get_categories(): print '''<option value="%d"> %s </option>''' % (cat.get_id(), cat) print '</select>' print '''<button type="button" onClick="addCategory()"> Add Category </button>''' print '<br />'*2
} else{ alert('Error: no name provided'); } } </script> </head> ''' print '''<body> <table border=0 cellspacing=2 cellpadding=0> <thead><tr> <th>Category</th> <th>Remove</th> </thead> <tbody id="categories"> ''' for cat in db.get_categories(): print '''<tr class="%d_cat_tr" id="%d_cat_tr"><td>%s</td>''' % (cat.get_id(), cat.get_id(),cat.get_name()) print '''<td><input type="button" onClick="removeCategory(%d,'%s')" value="remove" /></td>''' % (cat.get_id(),cat.get_name()) print '''</tr>''' print '''</tbody></table>''' print '''<br /><div id="new"><tr><td><input id='newCatName' type="text" size="10" value="" /></td><td><input type="button" onClick="addCategory()" value="add new" /></td>''' print '''</div>''' print '''</body></html>'''
if db.is_category_byname(catname): raise Exception('category already exists') else: db.add_category(catname) cat = db.get_category_byname(catname) print '%d,%s' % (cat.get_id(), cat.get_name()) else: raise Exception('no name given to add') elif action == 'remove': catid = form.getvalue('catid') if not db.is_category(catid): raise Exception ('category not in database') else: cat = db.get_category(catid) db.remove_category(cat) print '' elif action == 'query': cat_list = [cat.get_name() for cat in db.get_categories()] print ','.join(cat_list) elif action == 'query-name': cat_list = [str(cat.get_id())+','+cat.get_name() for cat in db.get_categories()] print '\n'.join(cat_list) elif action == 'query-cat-id': if 'catname' in form: catname = form.getvalue('catname').strip() cat = db.get_category_byname(catname) print '%d,%s' % (cat.get_id(), cat.get_name()) else: raise Exception ('invalid action')