def main(cursor): army_id = int(common.get_val("army", -1)) the_army = army_q.get_one_army(cursor, army_id) database.query(cursor, army_f.make_delete_query(army_id)) # Redirect page_data["Redirect"] = "list_armies&team={0:d}".format(the_army.team)
def delete_army_order(the_line, groups, debug=False): results = order_block.default_line_results(the_line) army_dict = the_line.the_world.armies() armies_lookup = the_line.the_world.armies_lookup_from_team(the_line.block.team) # Can we find the army? if groups['army'].lower() not in armies_lookup: return order_block.fail(results, "there is no army by the name of '%s'" % groups['army']) else: the_army = army_dict[armies_lookup[groups['army'].lower()]] # Default result results = order_block.default_line_results(the_line, "%s could not be deleted because" % (the_army.name)) # More handles squad_dict = the_line.the_world.squads() squads_lookup = the_line.the_world.squads_lookup_from_army(the_army.id)# We're not gonna use this the normal way # Are the squads in it empty? for squad_name, squad_id in squads_lookup.items(): results['queries'].extend(squad_f.make_delete_query(squad_id)) if squad_dict[squad_id].amount > 0: return order_block.fail(results, "one of it's squads (%s) is not empty" % squad_dict[squad_id].name) results['queries'].extend(army_f.make_delete_query(the_army.id)) results['results'].append("The army '%s' was deleted" % the_army.name) return order_block.success(results)