def main(cursor): # Get squad Id army_id = int(common.get_val('army', 0)) if army_id < 1: exit() the_army = army_q.get_one_army(cursor, army_id) squads_dict = squad_q.get_squads_from_army(cursor, army=army_id) monster_dict = monster_q.get_all_monsters(cursor) army_monsters_dict = monster_q.get_monsters_from_army(cursor, army_id) unit_dict = unit_q.get_units_from_team(cursor, the_army.team, special_units=True) output = [] output.append(""" <table border="0" cellspacing="0" cellpadding="5" style="width: 100%;"> <tr class="row2"> <th>Name</th> <th>Unit type</th> <th>Size</th> <th>Exp</th> <th> </th> </tr>""") count = -1 if len(squads_dict) > 0: for squad_id, the_squad in squads_dict.items(): if the_squad.unit not in unit_dict: continue count += 1 output.append(""" <tr class="row%(row)d" id="%(squad_id)d"> <td>%(name)s</td> <td>%(unit_type)s</td> <td>%(size)s</td> <td>%(exp)s</td> <td style="padding: 0px;"><a href="web.py?mode=edit_squad&squad=%(squad_id)d" class="block_link">Edit</a></td> </tr> """ % { 'row': (count % 2), "squad_id": squad_id, "name": common.doubleclick_text("squads", "name", squad_id, the_squad.name, "font-weight:bold", size=18), "unit_type": unit_dict[the_squad.unit].name, "size": common.doubleclick_text("squads", "amount", squad_id, the_squad.amount, size=7), "exp": common.doubleclick_text("squads", "experience", squad_id, the_squad.experience, size=7), }) else: output.append(""" <tr class="row0"> <td colspan="5">No squads in this army</td> </tr>""") count += 1 if len(army_monsters_dict) > 0: for monster_id, amount in army_monsters_dict.items(): if amount < 1: continue the_monster = monster_dict[monster_id] count += 1 output.append(""" <tr class="row{row}"> <td>{name}</td> <td><em>Monster</em></td> <td>{amount}</td> <td> </td> <td style="padding: 0px;"><a href="web.py?mode=edit_army_monster&army={army_id}&monster={monster_id}" class="block_link">Edit</a></td> </tr> """.format( row = (count % 2), army_id = army_id, monster_id = monster_id, name = the_monster.name, amount = common.doubleclick_text_full("army_monsters", "amount", "army = %d AND monster = %d" % (army_id, monster_id), amount, size=5), )) # Add new squad to army thingie names = {} for u, the_unit in unit_dict.items(): names[u] = the_unit.name count += 1 output.append(""" <tr class="row%(row)d"> <form action="exec.py" id="add_squad_form_%(army_id)d" method="post" accept-charset="utf-8"> <td style="padding: 1px;"> <input type="text" name="name" value=""/> <input type="hidden" name="team" value="%(team_id)s" /> <input type="hidden" name="mode" value="add_squad" /> <input type="hidden" name="army" value="%(army_id)s" /> </td> <td style="padding: 1px;">%(unit_type)s</td> <td style="padding: 1px;"><input type="text" name="size" value="" size="5"/></td> <td style="padding: 1px;"><input type="text" name="experience" value="" size="5"/></td> <td style="padding: 0px;"> <a class="block_link" href="#" onclick="$('#add_squad_form_%(army_id)d').submit();">Add</a> </td> </form> </tr> """ % { 'row': (count % 2), "army_id": army_id, "team_id": the_army.team, 'unit_type': common.option_box( name='unit_type', elements=names, element_order=unit_dict.keys(), custom_id="", ), }) output.append('</table>') return "".join(output)
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)