def match_equipment_from_string(cursor, equipment_string, equipment_dict={}): equipment_string = ". %s" % equipment_string.lower() origional_equipment_string = equipment_string if equipment_dict == {}: equipment_dict = equipment_q.get_all_equipment(cursor) grep_string = equipment_grep_string(cursor) e_list = [] mapping = { "untrained": "no training", "low training": "basic training", "normal training": "standard training", "high training": "good training", } for k, v in mapping.items(): equipment_string = equipment_string.replace(k, v) # Case sensetivity equipment_dict_new = {} for k, e in equipment_dict.items(): equipment_dict_new[e.name.lower()] = k equipment_string = equipment_string.replace('. transport.', '. transport ship.') equipment_string = equipment_string.replace('. 160kg.', '. 160kg balloon.') equipment_string = equipment_string.replace('. 350kg.', '. 350kg balloon.') equipment_string = equipment_string.replace('. 650kg.', '. 650kg balloon.') equipment_string = equipment_string.replace('. 1000kg.', '. 1000kg balloon.') equipment_string = equipment_string.replace('. 1800kg.', '. 1800kg balloon.') equipment_string = equipment_string.replace('. 100 tonnes.', '. 100 tonne hull.') equipment_string = equipment_string.replace('. 250 tonnes.', '. 250 tonne hull.') equipment_string = equipment_string.replace('. 400 tonnes.', '. 400 tonne hull.') equipment_string = equipment_string.replace('. 600 tonnes.', '. 600 tonne hull.') equipment_string = equipment_string.replace('. 800 tonnes.', '. 800 tonne hull.') equipment_string = equipment_string.replace('. flat bottom boat.', '. landing craft.') training_exists = False results = re.findall(grep_string.lower(), equipment_string)#, re.IGNORECASE) set_list = [] for r in results: if equipment_dict_new[r] in (1,2,3,4,5, 6): training_exists = True if r in set_list: continue e_list.append(equipment_dict_new[r]) set_list.append(r) equipment_string = equipment_string.replace(r, '') if training_exists == False: e_list.append(3)# Standard training return e_list
def equipment_option_list(cursor, remove_list=[], default=0): output = [] equipment_dict = equipment_q.get_all_equipment(cursor) for current_equipment, the_equip in equipment_dict.items(): if current_equipment in remove_list: continue if current_equipment == default: output.append("<option value='%s' selected='selected'>%s</option>" % (current_equipment, the_equip.name)) else: output.append("<option value='%s'>%s</option>" % (current_equipment, the_equip.name)) return "".join(output)
def equipment(cursor): output = {} equipment_dict = equipment_q.get_all_equipment(cursor) for e, the_eq in equipment_dict.items(): if not the_eq.public: continue output[e] = { "equipment_id": e, "name": the_eq.name, "cost": res_dict.Res_dict(the_eq.cost).value, "cost_raw": the_eq.cost, "cost_multiplier": res_dict.Res_dict(the_eq.cost_multiplier).value, "cost_multiplier_raw": the_eq.cost_multiplier, "crew": the_eq.crew, "transport": the_eq.transport, } return json.dumps(output)
def main(cursor): team = int(common.get_val("team", -1)) uname = common.get_val("name", "") total_string = common.get_val("equipment_string", "") equipment_dict = equipment_q.get_all_equipment(cursor) if uname == "": uname = re.search(r"^([A-Za-z' ]*)", total_string.strip()).groups()[0].strip() total_string = total_string.replace(uname, "") # Get the size size_match = re.search(r'(size: ?([0-9]*))', total_string, re.IGNORECASE) if size_match != None: size = int(size_match.groups()[1]) temp_string = total_string.replace(size_match.groups()[0], '') else: size = 100 temp_string = total_string # Description desc_match = re.search(r'(description: ?(.*))$', temp_string, re.IGNORECASE) if desc_match != None: description = desc_match.groups()[1] temp_string = total_string.replace(desc_match.groups()[0], '') else: description = "" # And now equipment e_list = equipment_f.match_equipment_from_string(cursor, temp_string) # print("") # print("Team: %d<br />" % team) # print("Unit name: %s<br />" % uname) # print("Equ: %s<br />" % [equipment_dict[e].name for e in e_list]) # print("Size: %s<br />" % size) # print("Desc: %s<br />" % description) # exit() unit_f.new_unit(cursor, team, uname, description, size, e_list) # Redirect page_data['Redirect'] = 'list_units&team={0:d}'.format(team) return ""
def rebuild_units(cursor): output = [] unit_dict = unit_q.get_all_units(cursor) equipment_dict = equipment_q.get_all_equipment(cursor) for unit_id, the_unit in unit_dict.items(): equipment_string = the_unit.equipment_string if equipment_string == "": continue equipment_list = equipment_f.match_equipment_from_string(cursor, equipment_string, equipment_dict) # print the_unit.unit_name, ", ", unit_id, ' ' equipment_q.replace_unit_equipment(cursor, unit_id, equipment_list) # print "<br />" output.append(the_unit.name) return "<br />".join(output)
def test_costs(self): cursor = database.get_test_cursor() # Build lookup dict equipment_lookup = {} equipment_dict = equipment_q.get_all_equipment(cursor) for e, eq in equipment_dict.items(): equipment_lookup[eq.name.lower()] = eq.id # Test costs for unit_name, equipment_strings, expected_costs in self.unit_lists: the_unit = unit.Unit() the_unit.name = unit_name the_unit.equipment = [] for e in equipment_strings: the_unit.equipment.append(equipment_lookup[e.lower()]) actual_costs = the_unit.get_cost(cursor=cursor, equipment_dict=equipment_dict) try: self.assertEqual(expected_costs[0], actual_costs['material_cost'].get("Materials")) self.assertEqual(expected_costs[1], actual_costs['iron_cost'].get("Materials")) self.assertAlmostEqual(expected_costs[2], actual_costs['material_upkeep'].get("Materials"), places=1) self.assertAlmostEqual(expected_costs[3], actual_costs['iron_upkeep'].get("Materials"), places=1) except Exception as e: print("\nFailed with unit: %s" % the_unit.name) print("Expected cost: %s" % str(expected_costs)) print("Actual costs: %s, %s, %s, %s" % (actual_costs['material_cost'], actual_costs['iron_cost'], actual_costs['material_upkeep'], actual_costs['iron_upkeep'])) breakdown = the_unit.get_cost(cursor=cursor, equipment_dict=equipment_dict, breakdown_mode=True) print(" - Breakdown - ") print("Cost:\n", "\n".join(breakdown['cost'])) print("") print("Upkeep:\n", "\n".join(breakdown['upkeep'])) raise
def main(cursor): equipment_dict = equipment_q.get_all_equipment(cursor) output = [] count = -1 weapons, weapons_dict = ["0:0:"], {"0:0:":""} armour, armour_dict = ["0:0:"], {"0:0:":""} shields, shields_dict = ["0:0:"], {"0:0:":""} mounts, mounts_dict = ["0:0:"], {"0:0:":""} beasts, beasts_dict = ["0:0:"], {"0:0:":""} boats, boats_dict = [], {} training, training_dict = [], {} for e, the_equipment in equipment_dict.items(): if the_equipment.public == False: continue cat = equipment.cat_list[the_equipment.category] line = equipment_line(the_equipment) if cat in ('Sword','Axe','Hammer','Flail','Polearm','Dagger','Bow','Crossbow','Thrown','Gunpowder',): weapons_dict[line] = the_equipment.name weapons.append(line) elif cat == 'Armour': armour_dict[line] = the_equipment.name armour.append(line) elif cat == 'Shield': shields_dict[line] = the_equipment.name shields.append(line) elif cat == 'Mount': mounts_dict[line] = the_equipment.name mounts.append(line) elif cat == 'Beast': beasts_dict[line] = the_equipment.name beasts.append(line) elif cat == 'Boat hull': boats_dict[line] = the_equipment.name boats.append(line) elif cat == 'Training': line = """%(material)s:%(name)s""" % { "material": res_dict.Res_dict(the_equipment.cost_multiplier).get("Materials"), "name": the_equipment.name, } training_dict[line] = the_equipment.name training.append(line) elif cat in ('Custom','Balloon','Siege engine','Seabourne mount'): pass else: raise Exception("No handler for type %s" % cat) # Army stuff output.append(""" <table border="0" cellspacing="5" cellpadding="5"> <tr> <td>Unit name:</td> <td><input type="text" id="name" value="" onkeyup="calc_army();"/></td> <td> </td> <td>Training:</td> <td>%(training)s</td> </tr> <tr> <td>Weapon 1:</td> <td>%(first_weapon)s</td> <td> </td> <td>Weapon 2:</td> <td>%(second_weapon)s</td> </tr> <tr> <td>Armour 1:</td> <td>%(first_armour)s</td> <td> </td> <td>Armour 2:</td> <td>%(second_armour)s</td> </tr> <tr> <td>Shield:</td> <td>%(shield)s</td> <td> </td> <td>Beast:</td> <td>%(beast)s</td> </tr> <tr> <td>Mount:</td> <td colspan="4">%(mount)s</td> </tr> </table> <div class="armyblock" id="army_bbcode"> Awaiting your input </div> """ % { "training": common.option_box("", elements=training_dict, element_order=training, onchange="calc_army();", custom_id="army_training", selected="1:1:Standard training"), "first_weapon": common.option_box("", elements=weapons_dict, element_order=weapons, onchange="calc_army();", custom_id="first_weapon"), "second_weapon": common.option_box("", elements=weapons_dict, element_order=weapons, onchange="calc_army();", custom_id="second_weapon"), "first_armour": common.option_box("", elements=armour_dict, element_order=armour, onchange="calc_army();", custom_id="first_armour"), "second_armour": common.option_box("", elements=armour_dict, element_order=armour, onchange="calc_army();", custom_id="second_armour"), "shield": common.option_box("", elements=shields_dict, element_order=shields, onchange="calc_army();", custom_id="shield"), "mount": common.option_box("", elements=mounts_dict, element_order=mounts, onchange="calc_army();", custom_id="mount"), "beast": common.option_box("", elements=beasts_dict, element_order=beasts, onchange="calc_army();", custom_id="beast"), }) # Navy stuff output.append(""" <table border="0" cellspacing="5" cellpadding="5"> <tr> <td>Ship name:</td> <td><input type="text" id="navy_name" value="" onkeyup="calc_navy();"/></td> <td> </td> <td>Training:</td> <td> <select id="navy_training" onchange="calc_navy();"> <option value="1:Standard training">Standard training</option> <option value="1.5:Good training">Good training</option> </select> </td> </tr> <tr> <td>Hull 1:</td> <td>%(hull)s</td> </tr> </table> <div class="navyblock" id="navy_bbcode"> Awaiting your input </div> """ % { "hull": common.option_box("", elements=boats_dict, element_order=boats, onchange="calc_navy();", custom_id="hull"), }) return "".join(output)
def _get_cost_with_cursor(self, cursor, breakdown_mode): if self.equipment == []: self.get_equipment(cursor) return self._get_cost(equipment_q.get_all_equipment(cursor), breakdown_mode)
def main(cursor): # Get team Id team_id = int(common.get_val('team', 0)) # Build team the_team = team_q.get_one_team(cursor, team_id) if team_id < 1: return "<div style='padding: 5px;'>%s</div>" % common.select_team_form(cursor, 'list_units') unit_dict = unit_q.get_units_from_team(cursor, team=team_id) equipment_dict = equipment_q.get_all_equipment(cursor) the_team.get_units(cursor) output = [] output.append(""" <table border="0" cellspacing="0" cellpadding="5" style="width: 100%;"> <tr class="row2"> <th>Icon</th> <th>Amount</th> <th>Name</th> <th>Cost</th> <th colspan='4'>Categories</th> <th>Equipment</th> <th style="width:70px;">Edit</th> <!-- <th colspan="2">Add</th> --> </tr>""") names = {} count = -1 if len(unit_dict) > 0: # for team_id, team in team_dict.items(): for unit_id, the_unit in unit_dict.items(): if unit_id not in the_team.units: the_team.units[unit_id] = 0 names[unit_id] = the_unit.name count += 1 output.append(""" <tr class="row%(row)d" id="%(unit_id)d"> <td>%(icon)s</td> <td>%(count)s</td> <td>%(name)s</td> <td>%(cost)s</td> <td>%(weapon_cat)s</td> <td>%(armour_cat)s</td> <td>%(move_cat)s</td> <td>%(training_cat)s</td> <td>%(equipment)s</td> <td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_unit&unit=%(unit_id)d">Edit unit</a></td> <!-- <td style="padding: 1px;"> <form action="exec.py" method="post" accept-charset="utf-8"> <input type="text" name="amount" value="" size="8"/> <input type="hidden" name="mode" value="alter_unit_count" /> <input type="hidden" name="team" value="%(team_id)s" /> <input type="hidden" name="unit" value="%(unit_id)s" /> </form> </td> <td style="padding: 0px;"> <a class="block_link" href="#" onclick="$('#form_add_%(unit_id)s').submit();">Add unit</a> </td> --> </tr> """ % { 'row': (count % 2), "team_id": team_id, 'unit_id': unit_id, 'name': common.doubleclick_text("units", "name", unit_id, the_unit.name, "font-weight:bold"), 'icon': "", 'count': common.number_format(the_team.units[unit_id]), 'weapon_cat': unit.weapon_categories[the_unit.weapon_cat], 'armour_cat': unit.armour_categories[the_unit.armour_cat], 'move_cat': unit.move_categories[the_unit.move_cat], 'training_cat': unit.training_categories[the_unit.training_cat], "cost": unit_rules.print_unit_cost(the_unit, cursor=cursor, equipment_dict=equipment_dict), "equipment": the_unit.equipment_string, }) # Add unit type # armies_dict = army_q.get_armies_from_team(cursor, team=team_id, include_garrisons=1) count += 1 # armies_names = {} # has_non_garrison = False # for k, v in armies_dict.items(): # armies_names[k] = v.name # if v.garrison < 0: has_non_garrison = True # # armies_order.reverse() # armies_order.append("disabled") # armies_order.append("XYZ_all_garrisons") # if has_non_garrison == True: # armies_order.append("XYZ_all_non_garrisons") # armies_order.append("XYZ_all_armies") # armies_order.reverse() # # if has_non_garrison == True: # armies_names["XYZ_all_armies"] = "All armies" # armies_names["XYZ_all_non_garrisons"] = "All non garrisons" # armies_names["XYZ_all_garrisons"] = "All garrisons" output.append(""" <tr class="row%(row)d"> <form action="exec.py" method="post" id="new_unit_form" accept-charset="utf-8"> <input type="hidden" name="mode" value="create_new_unit" /> <input type="hidden" name="team" value="%(team_id)s" /> <td> </td> <td style="padding: 1px;"> </td> <td style="padding: 1px;"><input type="text" name="name" id="name" value="" size="13"/></td> <td colspan='4'> </td> <td style="padding: 1px;"> </td> <td style="padding: 2px;"> <textarea name="equipment_string" id="equipment_string" rows="1" cols="30"></textarea> </td> <td style="padding: 0px;"><a class="block_link" onclick="$('#new_unit_form').submit();" href="#">Add</a></td> %(onload)s </form> </tr> """ % { 'row': (count % 2), "team_id": team_id, 'onload': common.onload("$('#name').focus();"), }) # Now for solo units unit_dict = unit_q.get_units_from_team(cursor, team=0) if len(unit_dict) > 0: # for team_id, team in team_dict.items(): for unit_id, the_unit in unit_dict.items(): if unit_id not in the_team.units: the_team.units[unit_id] = 0 names[unit_id] = the_unit.name count += 1 output.append(""" <tr class="row%(row)d" id="%(unit_id)d"> <td>%(icon)s</td> <td>%(count)s</td> <td>%(name)s</td> <td>%(cost)s</td> <td colspan='4'> </td> <td>%(equipment)s</td> <td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_unit&unit=%(unit_id)d">Edit unit</a></td> <!-- <td style="padding: 1px;"> <form action="exec.py" method="post" accept-charset="utf-8"> <input type="text" name="amount" value="" size="8"/> <input type="hidden" name="mode" value="alter_unit_count" /> <input type="hidden" name="team" value="%(team_id)s" /> <input type="hidden" name="unit" value="%(unit_id)s" /> </form> </td> <td style="padding: 0px;"> <a class="block_link" href="#" onclick="$('#form_add_%(unit_id)s').submit();">Add unit</a> </td> --> </tr> """ % { 'row': (count % 2), "team_id": team_id, 'unit_id': unit_id, 'name': common.doubleclick_text("units", "name", unit_id, the_unit.name, "font-weight:bold"), 'icon': "", 'count': common.number_format(the_team.units[unit_id]), "cost": unit_rules.print_unit_cost(the_unit, cursor=cursor, equipment_dict=equipment_dict), "equipment": the_unit.equipment_string, }) output.append("</table>") page_data['Title'] = "%s unit list" % the_team.name return "".join(output)
def check_unit_categories(cursor, verbose): queries = [] unit_dict = unit_q.get_all_live_units(cursor) equipment_dict = equipment_q.get_all_equipment(cursor) unit_q.mass_get_unit_equipment(cursor, unit_dict) # Default query = """UPDATE units SET crew = 1;""" try: cursor.execute(query) except Exception as e: raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query)) if verbose: it = cli_f.progressbar(unit_dict.items(), "military_check.check_unit_categories: ", 40, with_eta = True) else: it = unit_dict.items() for unit_id, the_unit in it: the_unit.transport = 0 the_unit.move_type = 0 the_unit.move_speed = 0 the_unit.crew = 1 the_unit.weapon_cat = 0 the_unit.armour_cat = 0 the_unit.move_cat = 0 the_unit.training_cat = 0 ranged = False melee = False # Loop through all it's equipment for e in the_unit.equipment: the_e = equipment_dict[e] if the_e.range > 2: ranged = True elif the_e.range == 0: melee = True the_unit.transport = max(the_e.transport, the_unit.transport) the_unit.crew = max(the_unit.crew, the_e.crew) # the_unit.move_type = 0 # the_unit.move_speed = 0 # the_unit.type_cat = 0 the_unit.armour_cat = max(the_unit.armour_cat, the_e.armour_cat) the_unit.move_cat = max(the_unit.move_cat, the_e.move_cat) the_unit.training_cat = max(the_unit.training_cat, the_e.training_cat) if the_e.category == equipment.cat_list.index("Boat hull"): the_unit.type_cat = unit.categories.index("Ship") elif the_e.category == equipment.cat_list.index("Balloon"): the_unit.type_cat = unit.categories.index("Airship") else: pass # Work out categories if ranged and melee: the_unit.weapon_cat = unit.weapon_categories.index("Melee and Ranged") elif ranged and not melee: the_unit.weapon_cat = unit.weapon_categories.index("Ranged") elif melee and not ranged: the_unit.weapon_cat = unit.weapon_categories.index("Melee") else: the_unit.weapon_cat = unit.weapon_categories.index("Neither") # Query queries.append("""UPDATE units SET transport = {transport}, move_type = {move_type}, move_speed = {move_speed}, crew = {crew}, type_cat = {type_cat}, weapon_cat = {weapon_cat}, armour_cat = {armour_cat}, move_cat = {move_cat}, training_cat = {training_cat} WHERE id = {id};""".format( transport = the_unit.transport, move_type = the_unit.move_type, move_speed = the_unit.move_speed, crew = the_unit.crew, type_cat = the_unit.type_cat, weapon_cat = the_unit.weapon_cat, armour_cat = the_unit.armour_cat, move_cat = the_unit.move_cat, training_cat = the_unit.training_cat, id = the_unit.id, )) database.query(cursor, queries)
def main(cursor): # Get team Id unit_id = int(common.get_val('unit', 0)) if unit_id < 1: return "No unit selected" the_unit = unit_q.get_one_unit(cursor, unit_id) army_dict = army_q.get_all_armies(cursor)#get_armies_from_team(cursor, the_unit.team, include_garrisons=True) squad_dict = squad_q.get_squads_from_team_of_type(cursor, the_unit.team, unit_id) equipment_dict = equipment_q.get_all_equipment(cursor) page_data['Title'] = "Edit unit: %s" % the_unit.name output = ["<div style='padding: 5px;'>"] # Unit cost breakdown unit_cost_breakdown = unit_rules.print_unit_cost(the_unit, cursor=cursor, breakdown_mode=True) w = world.World(cursor) real_cost = "Post override: %s/%s" % ( unit_rules.unit_cost_override(w, the_unit, the_unit.costs['material_cost'], w.teams()[the_unit.team]), unit_rules.unit_cost_override(w, the_unit, the_unit.costs['iron_cost'], w.teams()[the_unit.team]), ) real_upkeep = "Post override: %s/%s" % ( unit_rules.unit_upkeep_override(w, the_unit, the_unit.costs['material_cost'], w.teams()[the_unit.team]), unit_rules.unit_upkeep_override(w, the_unit, the_unit.costs['iron_cost'], w.teams()[the_unit.team]), ) # real_cost = 0 # real_upkeep = 0 output.append(""" <div style="float: right; width: 50%;"> <strong>Unit cost breakdown</strong><br /> {cost_breakdown}<br /> {real_cost} <br /><br /> <strong>Unit upkeep breakdown</strong><br /> {upkeep_breakdown}<br /> {real_upkeep} <br /><br /> <strong>Unit categories</strong><br /> Type category: {type_cat}<br /> Weapon category: {weapon_cat}<br /> <br /> <form id="delete_form" action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="unit" id="unit" value="{unit_id}" /> <input type="hidden" name="mode" id="mode" value="remove_unit" /> <input style="float:right; margin-right:100px;" type="button" value="Delete unit" onclick="var answer = confirm('Delete {name}?') if (answer) $('#delete_form').submit();" /> </form> </div> """.format( cost_breakdown = "<br />".join(unit_cost_breakdown['cost']), upkeep_breakdown = "<br />".join(unit_cost_breakdown['upkeep']), real_cost = real_cost, real_upkeep = real_upkeep, unit_id = unit_id, name = the_unit.name, type_cat = unit.categories[the_unit.type_cat], weapon_cat = unit.weapon_categories[the_unit.weapon_cat], )) # Main unit stuff output.append(""" <form action="exec.py" id="the_unit_form" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="edit_unit_commit" /> <input type="hidden" name="id" value="%(unit_id)s" /> <table border="0" cellspacing="5" cellpadding="5"> <tr> <td><label for="name">Unit:</label></td> <td>%(name_text)s</td> <td> </td> <td><label for="team">Team:</label></td> <td> <select name="team" id="team"> <option value="0">No team</option> %(team_option_box)s </select> </td> </tr> <tr> <td colspan="5" style="padding: 0px;"><a class="block_link" href="#" onclick="$('#the_unit_form').submit();">Apply changes</a></td> </tr> </table> </form> <br /> """ % { "unit_id": unit_id, "name_text": common.text_box("name", the_unit.name), "team_option_box": team_f.structured_list(cursor, default=the_unit.team), }) # Unit equipment output.append(""" <span class="stitle" id="equipment">Equipment</span> <table border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Item</th> <th> </th> </tr>""") the_unit.get_equipment(cursor) counter = -1 for e in the_unit.equipment: counter += 1 output.append(""" <tr class="row%(row)s"> <td>%(item_name)s</td> <td style="padding: 0px;"> <form action="exec.py" id="form_%(item_id)s" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="remove_equipment" /> <input type="hidden" name="unit" value="%(unit_id)s" /> <input type="hidden" name="item" value="%(item_id)s" /> <a href="#" class="block_link" onclick="$('#form_%(item_id)s').submit();">Remove</a> </form> </td> </tr>""" % { "row": counter%2, "item_name": equipment_dict[e].name, "unit_id": unit_id, "item_id": e, }) counter += 1 output.append(""" <tr class="row%(row)s"> <form action="exec.py" id="new_equipment_form" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="add_equipment" /> <input type="hidden" name="unit" value="%(unit_id)s" /> <td> <select name="item"> %(equipment_list)s </select> </td> <td> <input type="submit" value="Apply" /> </td> </form> </tr> """ % { "row": counter%2, "unit_id": unit_id, "equipment_list": equipment_f.equipment_option_list(cursor, remove_list=the_unit.equipment), }) output.append("</table>") # What squads does the unit appear in? output.append(""" <br /><br /> <span class="stitle" id="squads">Squads</span> <table border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Army</th> <th>Squad</th> <th>Size</th> <th> </th> <th> </th> </tr>""") the_unit.get_equipment(cursor) counter = -1 for s, the_squad in squad_dict.items(): counter += 1 output.append(""" <tr class="row%(row)s"> <td>%(army_name)s</td> <td>%(name)s</td> <td>%(squad_size)s</td> <td style="padding: 0px;"> <a href="web.py?mode=edit_army&army=%(army_id)s" class="block_link">Edit army</a> </td> <td style="padding: 0px;"> <a href="web.py?mode=edit_squad&squad=%(squad_id)s" class="block_link">Edit squad</a> </td> </tr>""" % { "row": counter%2, "army_name": army_dict[the_squad.army].name, "army_id": the_squad.army, "squad_id": s, "name": the_squad.name, "squad_size": the_squad.amount, }) output.append("</table>") output.append("</div>") return "".join(output)
import database from classes import world, res_dict from classes import team, city, squad, army, unit from queries import equipment_q, building_q, deity_q, evolution_q, tech_q, spell_q, artefact_q, wonder_q # Need some live data for things like buildings etc temp_cursor = database.get_cursor() equipment_dict = equipment_q.get_all_equipment(temp_cursor) building_dict = building_q.get_all_buildings(temp_cursor) deity_dict = deity_q.get_all_deities(temp_cursor) evolution_dict = evolution_q.get_all_evolutions(temp_cursor) spell_dict = spell_q.get_all_spells(temp_cursor) tech_dict = tech_q.get_all_techs(temp_cursor) artefact_dict = artefact_q.get_all_artefacts(temp_cursor) wonder_dict = wonder_q.get_all_wonders(temp_cursor) def dummy_world(): w = world.World(Dead_cursor()) # LISTS #------------------------ w._equipment = equipment_dict w._buildings = building_dict w._deities = deity_dict w._evolutions = evolution_dict w._spells = spell_dict w._techs = tech_dict w._artefacts = artefact_dict # TEAMS #------------------------