Esempio n. 1
0
File: ti.py Progetto: Teifion/Rob3
def main(cursor):
	# Get team Id
	team_id		= int(common.get_val('team', 0))
	post_output = common.get_val('post_output', 0)
	auto_jump	= common.get_val('auto_jump', False)
	dev_mode	= common.get_val('dev_mode', 0)
	recache		= common.get_val('recache', False)
	ajax		= common.get_val('ajax', 0)
	
	output = []
	
	if not ajax:
		output.append("""<div style="padding: 5px;">
		<form style="padding: 5px;" action="web.py" method="get" accept-charset="utf-8">
			<input type="hidden" name="mode" id="mode" value="ti" />
			<table border="0" cellspacing="5" cellpadding="5">
				<tr>
					<td><label for="team">Team:</label></td>
					<td>%(team_option_box)s</td>
					<td><label for="post_output">Post ouput:</label></td>
					<td>%(post_output_checkbox)s</td>
					<td><label for="auto_jump">Auto-jump:</label></td>
					<td>%(auto_jump_checkbox)s</td>
					<td width="10">&nbsp;</td>
					<td><input type="submit" value="Get TI" /></td>
				</tr>
			</table>
		</form>
		<a href="web.py?mode=ti&amp;team=%(last_id)s&amp;post_output=1&amp;auto_jump=1" class="block_link">Update all</a>
		<br />
		
		<a href="web.py?mode=ti&amp;team=%(team_id)s&amp;recache=1" class="block_link">Recache</a>
		<br />""" % {
			"team_option_box":		team_f.structured_list(cursor, default=team_id),
			"post_output_checkbox":	common.check_box('post_output', post_output),
			"auto_jump_checkbox":	common.check_box('auto_jump', auto_jump),
			"last_id":				team_q.get_latest_active_team_id(cursor, skip_irs = True),
			"team_id":				team_id,
		})
	
	
	if team_id < 1:
		return "".join(output)
	
	if post_output:
		output.append(get_bbcode_core(cursor, team_id))
	else:
		output.append(get_ti_core(cursor, team_id, recache, ajax))
	
	if auto_jump:
		new_location = "web.py?mode=ti&post_output=%s&auto_jump=1&team=%d" % (post_output, team_q.get_next_active_team_id(cursor, team_id, skip_irs = True))
		
		if post_output:
			output.append(common.redirect(new_location, 2000))
		else:
			output.append(common.redirect(new_location))
	
	output.append("</div>")
	
	return "".join(output)
Esempio n. 2
0
def print_form_element(resource_id, current_value):
	"""Prints the relevant form element for a given type of resource"""
	this_type = resource_list.data_dict[resource_id].type
	
	# We don't want a 10.0, we want 10
	if current_value == int(current_value):
		current_value = int(current_value)
	
	output = ''
	
	if this_type == 'discrete':
		return common.text_box("res_%s" % resource_list.data_dict[resource_id].name, current_value, size=6)
	
	elif this_type == 'boolean':
		return common.check_box("res_%s" % resource_list.data_dict[resource_id].name, current_value)
	
	return output

# def all_supplies():
# 	"""docstring for all_supplies"""
# 	res_dict = resource.get_resources_dict_c()
# 	d = Res_dict()
# 	
# 	for k, v in res_dict.items():
# 		if v.type == "boolean":
# 			d.value[k] = 1
# 	
# 	return d

# def resource_grep_list(tradable_only=False):
# 	"""Returns order-grep lists"""
# 	if tradable_only:
# 		query = """SELECT id, resource_name FROM resource_list WHERE tradable = True ORDER BY id DESC"""
# 	else:
# 		query = """SELECT id, resource_name FROM resource_list ORDER BY id DESC"""
# 	
# 	resource_id_list = []
# 	resource_name_list = []
# 	try:
# 		database.cursor.execute(query)#TODO Use new method
# 	except Exception as e:
# 		print("Query: %s\n" % query)
# 		raise e
# 	while (1):
# 		row = database.cursor.fetchone()
# 		if row == None: break
# 		resource_id_list.append(row['id'])
# 		resource_name_list.append(row['resource_name'])
# 	
# 	return resource_id_list, resource_name_list
Esempio n. 3
0
def main(cursor):
	# Get team Id
	team_id = int(common.get_val('team', 0))
	if team_id < 1: return "No team selected"
	
	# Build team item
	the_team = team_q.get_one_team(cursor, team_id)
	
	# Get some properties
	the_team.get_population(cursor)
	
	# Lists
	trait_dict = trait_q.get_all_traits(cursor)
	deity_dict = deity_q.get_all_deities(cursor)
	evolution_dict = evolution_q.get_all_evolutions(cursor)
	
	# Is the join turn set?
	if the_team.join_turn == 0:
		the_team.join_turn = common.current_turn()
	
	# First row of check_boxes
	output = ["<div style='padding: 5px;'>"]

	output.append("""
	<span class="stitle">%(name)s</span>
	&nbsp;&nbsp;&nbsp;
	Population: %(team_population)s

	<br /><br />
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_team_commit" />
		<input type="hidden" name="id" id="id" value="%(team_id)d" />
	
		<input type="hidden" name="requestTime" id="requestTime" value="' . $the_team->requestTime . '" />
	
		<label for="active">Active:</label>&nbsp;&nbsp;
		%(active_check_box)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

		<label for="ir">IR:</label>&nbsp;&nbsp;
		%(ir_check_box)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

		<label for="hidden">Hidden:</label>&nbsp;&nbsp;
		%(hidden_check_box)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	
		<label for="not_a_team">Not a team:</label>&nbsp;&nbsp;
		%(not_a_team_check_box)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

		<label for="dead">Dead:</label>&nbsp;&nbsp;
		%(dead_check_box)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

		<label for="not_in_queue">Not in queue:</label>&nbsp;&nbsp;
		%(not_in_queue_check_box)s
		<br />
		""" % {	'team_id':					team_id,
				'name':				the_team.name,
				'team_population':			common.number_format(the_team.population),
				'active_check_box':			common.check_box('active', the_team.active),
				'ir_check_box':				common.check_box('ir', the_team.ir),
				'hidden_check_box':			common.check_box('hidden', the_team.hidden),
				'not_a_team_check_box':		common.check_box('not_a_team', the_team.not_a_team),
				'dead_check_box':			common.check_box('dead', the_team.dead),
				'not_in_queue_check_box':	common.check_box('not_in_queue', the_team.not_in_queue),
				})

	# Row 1
	output.append("""
		<table border="0" cellspacing="5" cellpadding="5" style="width:100%%;">
			<tr>
				<td><label for="forum_url_id">Forum URL id:</label></td>
				<td>%(forum_text_box)s</td>
		
				<td width="5">&nbsp;</td>
		
				<td><label for="orders_topic">Orders topic:</label></td>
				<td>%(orders_text_box)s</td>
		
				<td width="5">&nbsp;</td>
		
				<td><label for="intorders_topic">Int Orders topic:</label></td>
				<td>%(intorders_text_box)s</td>
			</tr>""" % {'forum_text_box':		common.text_box('forum_url_id', the_team.forum_url_id, warn_on = lambda x:(True if x < 0 else False)),
						'orders_text_box':		common.text_box('orders_topic', the_team.orders_topic, warn_on = lambda x:(True if x < 0 else False)),
						'intorders_text_box':	common.text_box('intorders_topic', the_team.intorders_topic, warn_on = lambda x:(True if x < 0 else False)),
						})


	# Row 2
	output.append("""
			<tr>
				<td><label for="results_topic">Results topic:</label></td>
				<td>{results_topic}</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="teaminfo_topic">Team info topic:</label></td>
				<td>{teaminfo_topic}</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="team_info_first_post">Team info first post:</label></td>
				<td>{team_info_first_post}</td>
			</tr>""".format(
			results_topic			= common.text_box('results_topic', the_team.results_topic, warn_on = lambda x:(True if x < 0 else False)),
			teaminfo_topic			= common.text_box('teaminfo_topic', the_team.teaminfo_topic, warn_on = lambda x:(True if x < 0 else False)),
			team_info_first_post	= common.text_box('team_info_first_post', the_team.team_info_first_post, warn_on = lambda x:(True if x < 0 else False)),
			))

	# Row 3
	output.append("""
			<tr>
				<td><label for="request_topic">Request topic:</label></td>
				<td>%(request_topic)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="leader_id">Leader:</label></td>
				<td>%(leader_id)s</td>
			
				<td width="5">&nbsp;</td>
		
				<td>Culture topic:</td>
				<td>%(culture_topic)s</td>
			</tr>""" % {'leader_id':		common.text_box('leader_id', the_team.leader_id, warn_on = lambda x:(True if x < 1 else False)),
						'request_topic':	common.text_box('request_topic', the_team.request_topic, warn_on = lambda x:(True if x < 1 else False)),
						'culture_topic':	common.text_box('culture_topic', the_team.culture_topic, warn_on = lambda x:(True if x < 1 else False)),
					})
	
	output.append("""
	<tr>
		<td><label for="default_borders">Default borders:</label></td>
		<td>%(default_borders)s</td>
		
		<td width="5">&nbsp;</td>
		
		<td><label for="default_taxes">Default taxes:</label></td>
		<td>%(default_taxes)s</td>
		
		<td width="5">&nbsp;</td>
		
		<td><label for="evo_points">Evo points:</label></td>
		<td>%(evo_points)s</td>
	</tr>
	<tr>
		<td colspan="8" style="padding:0px;border-bottom:3px #EEE double;"></td>
	</tr>
	""" % {
		"default_borders":		common.option_box("default_borders", elements=team.border_states, selected=team.border_states[the_team.default_borders]),
		"default_taxes":		common.text_box('default_taxes', the_team.default_taxes, warn_on = lambda x:(True if int(x) < 0 else False), size=4),
		"evo_points":			common.text_box('evo_points', the_team.evo_points, warn_on = lambda x:(True if int(x) < 0 else False)),
	})
	
	output.append("""
			<!--
			<tr>
				<td>Previous resources:</td>
				<td>%(previous_resources)s</td>
			</tr>
			-->
	""" % {
		"previous_resources":	the_team.previous_resources,
		})
	
	# End row
	output.append("""
			<tr>
				<td>Join turn:</td>
				<td>%(join_turn)s</td>

				<td width="5">&nbsp;</td>

				<td>Primary:</td>
				<td>%(primary_colour)s</td>
			
				<td width="5">&nbsp;</td>

				<td>Secondary:</td>
				<td>%(secondary_colour)s</td>
			</tr>
		</table>
		<br />
	
		<input type="submit" value="Perform edit" />
		<input style="float:right; margin-right:100px;" type="button" value="Purge team" onclick="setTimeout('document.location=\\'web.py?mode=purge_team&team=%(team_id)s\\'', 0);"/>
	<a class="block_link" href="web.py?mode=ti&amp;post_output=1&amp;team=%(team_id)s">Update my TI</a>

	<br />""" % {
		"team_id":				team_id,
		'join_turn':			common.text_box('join_turn', the_team.join_turn),
		'previous_resources':	common.text_box('previous_resources', the_team.previous_resources, size=56),
	
		"primary_colour":		common.text_box('primary_colour', the_team.primary_colour),
		"secondary_colour":		common.text_box('secondary_colour', the_team.secondary_colour),
		})
		
	#	Resources
	#------------------------
	the_team.get_resources(cursor)
	
	output.append("""
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Resource</th>
		<th>Amount</th>
	</tr>
	""")
	
	counter = -1
	for res_id, the_res in resource_list.data_dict.items():
		if the_res.category == resource_list.category['Map terrain feature']:
			continue
		
		# If it's not set then we need to give it a default
		if not res_id in the_team.resources.value:
			the_team.resources.value[res_id] = 0
		
		counter += 1
		
		output.append("""
		<tr class="row%(row)d">
			<td><label for="res_%(res_name)s">%(res_name)s</label></td>
			<td style="padding:1px;">%(res_amount)s</td>
		</tr>""" % {'row':			(counter % 2),
					'res_name':		the_res.name,
					'res_amount':	resource_f.print_form_element(res_id, the_team.resources[res_id])
					})
	
	output.append("</table></form>")# Subsequent forms are for other stuff
	
	#	Deities
	#----------------------
	the_team.get_deities(cursor)
	
	output.append("""
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Deity</th>
		<th>&nbsp;</th>
	</tr>
	""")
	
	counter = -1
	for deity_id, team_favour in the_team.deities.items():
		counter += 1
		
		output.append("""
		<tr class="row%(row)d">
			<td><label for="%(name)s">%(name)s</label></td>
			<td style="padding: 0px;">
				<a class="block_link" href="exec.py?mode=remove_deity&amp;deity=%(deity_id)d&amp;team=%(team_id)d">Remove</a>
			</td>
		</tr>""" % {'row':			(counter % 2),
					'name':	deity_dict[deity_id].name,
					'deity_id':		deity_id,
					'team_id':		team_id
					})
	
	output.append("""
		<tr class="row%(row)d">
		<form id="team_add_deity_form" action="exec.py?mode=add_deity" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="add_deity" />
			<input type="hidden" name="team" value="%(team_id)s" />
			<td style="padding:1px;">
				<select name="deity">
					%(deity_option_box)s
				</select>
			</td>
			<td style="padding: 2px;">
				<input type="submit" value="Add" />
				<!--<a href="#" onclick="$('#team_add_deity_form').submit(); return false;" class="block_link">Add</a>-->
			</td>
		</tr>
		</form>
	</table>
	""" % {	'row':				((counter+1) % 2),
			'team_id':			the_team.id,
			'deity_option_box': deity_f.deity_option_list(cursor, the_team.deities)})
	
	
	#	Evolutions
	#-------------------
	the_team.get_evolutions(cursor)
	
	output.append("""
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Evolution</th>
		<th>&nbsp;</th>
		<th>&nbsp;</th>
	</tr>
	""")
	
	counter = -1
	for evo_id, evo_level in the_team.evolutions.items():
		counter += 1
		
		output.append("""
		<tr class="row%(row)d">
			<form id="edit_evo_%(evolution_id)s" action="exec.py" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="set_evolution" />
			<input type="hidden" name="team" value="%(team_id)s" />
			<input type="hidden" name="evolution" value="%(evolution_id)s" />
			<td><label for="%(name)s">%(name)s</label></td>
			<td style="padding:1px;">
				%(text_box)s
			</td>
			</form>
			<td style="padding: 0px;">
				<a class="block_link" href="exec.py?mode=set_evolution&amp;evolution=%(evolution_id)d&amp;team=%(team_id)d">Remove</a>
			</td>
		</tr>""" % {'row':				(counter % 2),
					'name':				evolution_dict[evo_id].name,
					'evolution_level':	evo_level,
					'evolution_id':		evo_id,
					'team_id':			team_id,
					
					"text_box": common.text_box("evolution_level", evo_level, custom_id="", size=3,
						warn_on = lambda e: (True if evolution_dict[evo_id].min_level > e or e > evolution_dict[evo_id].max_level else False)),
					})
	
	output.append("""
		<tr class="row%(row)d">
		<form id="team_add_evolution_form" action="exec.py" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="set_evolution" />
			<input type="hidden" name="team" value="%(team_id)d" />
			<td style="padding:1px;">
				<select name="evolution">
					%(evolution_option_box)s
				</select>
			</td>
			<td style="padding:1px;">
				%(evolution_level)s
			</td>
			<td style="padding: 0px;">
				<a href="#" onclick="$('#team_add_evolution_form').submit();" class="block_link">Add</a>
			</td>
		</tr>
		</form>
	</table>
	""" % {	'row':				((counter+1) % 2),
			'team_id':			the_team.id,
			'evolution_level':	common.text_box('evolution_level', 0, 4),
			'evolution_option_box': evolution_f.evolution_option_list(cursor, the_team.evolutions)})
	
	
	#	Traits
	#----------------------
	the_team.get_traits(cursor)
	
	output.append("""
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Trait</th>
		<th>&nbsp;</th>
	</tr>
	""")
	
	counter = -1
	for trait_id in the_team.traits:
		counter += 1
		
		output.append("""
		<tr class="row%(row)d">
			<td><label for="%(name)s">%(name)s</label></td>
			<td style="padding: 0px;">
				<a class="block_link" href="exec.py?mode=remove_trait&amp;trait=%(trait_id)d&amp;team=%(team_id)d">Remove</a>
			</td>
		</tr>""" % {'row':			(counter % 2),
					'name':			trait_dict[trait_id].name,
					'trait_id':		trait_id,
					'team_id':		team_id
					})
	
	output.append("""
		<tr class="row%(row)d">
		<form id="team_add_trait_form" action="exec.py?mode=add_trait" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="add_trait" />
			<input type="hidden" name="team" value="%(team_id)s" />
			<td style="padding:1px;">
				<select name="trait">
					%(trait_option_box)s
				</select>
			</td>
			<td style="padding: 2px;">
				<input type="submit" value="Add" />
				<!--<a href="#" onclick="$('#team_add_trait_form').submit(); return false;" class="block_link">Add</a>-->
			</td>
		</tr>
		</form>
	</table>
	""" % {	'row':				((counter+1) % 2),
			'team_id':			the_team.id,
			'trait_option_box': trait_f.trait_option_list(cursor, the_team.traits)})
	
	
	# Hashes
	output.append("""
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Turn</th>
		<th>Hash</th>
	</tr>
	""")

	for i, t in enumerate(range(common.current_turn(), common.current_turn()-5, -1)):
		output.append("""
		<tr class="row{i}">
			<td>{t}</td>
			<td>{hash}</td>
		</tr>""".format(
			i = i % 2,
			t = t,
			hash = team_f.team_hash(the_team.name, turn=t),
	))
	
	output.append("</table>")
	
	
	

	
	output.append("</div>")
	page_data['Title'] = "Edit team (%s)" % the_team.name
	return "".join(output)
Esempio n. 4
0
def main(cursor):
	player_id	= int(common.get_val('player', 0))
	
	if player_id < 1:
		return "No player selected"
	
	the_player = player_q.get_one_player(cursor, player_id)
	
	output = ["<div style='padding: 5px;'>"]
	
	output.append("""
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_player_commit" />
		<input type="hidden" name="id" id="id" value="%(player_id)s" />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="name">Name:</label></td>
				<td>%(name_text)s</td>
				
				<td colspan="3">&nbsp;</td>
			</tr>
			<tr>
				<td><label for="team">Team:</label></td>
				<td>%(team)s</td>
				
				<td>&nbsp;</td>
				
				<td><label for="ir">IR:</label></td>
				<td>%(ir)s</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				
				<td colspan="3">&nbsp;</td>
			</tr>	
			<tr>
				<td><label for="last_posted">Last posted:</label></td>
				<td>%(last_posted_text)s</td>
				
				<td colspan="3">&nbsp;</td>
			</tr>
			<tr>
				<td><label for="daemon_type">Daemon type:</label></td>
				<td>%(daemon_type)s</td>
				
				<td colspan="3">&nbsp;</td>
			</tr>
			<tr>
				<td><label for="progression">Progression:</label></td>
				<td>%(progression)s</td>
				
				<td colspan="3">&nbsp;</td>
			</tr>
			<tr>
				<td><label for="not_a_player">Not a player:</label></td>
				<td>%(not_a_player)s</td>
				
				<td>&nbsp;</td>
				
				<td><label for="not_surplus">Not surplus:</label></td>
				<td>%(not_surplus)s</td>
			</tr>
		</table>
		<br />
		<input type="submit" value="Perform edit" />
	</form>
	<br /><br />""" % {
		"player_id":		player_id,
		"name":				the_player.name,
		"team":				team_f.structured_list(cursor, default=the_player.team, field_name="team"),
		"name_text":	common.text_box("name", the_player.name, size=20),
		"last_posted_text":	common.text_box("last_posted", the_player.last_posted),
		"not_a_player":		common.check_box("not_a_player", the_player.not_a_player),
	
		"daemon_type":		common.option_box("daemon_type", elements=player.daemon_types, selected=player.daemon_types[the_player.daemon_type]),
		"progression":		common.option_box("progression", elements=player.progressions, selected=player.progressions[the_player.progression]),
		
		"not_surplus":		common.check_box("not_surplus", the_player.not_surplus),
		"ir":				common.check_box("ir", the_player.ir),
		
		# option_box(name, elements = {}, element_order = [], tab_index = -1, onchange="", custom_id = "<>", selected=""):
	})
	
	# This get's ajax'd
	output.append("""
	<div style="clear: left;">
		<br /><br />
		<span class="stitle">Player powers</span>
		<div id="player_powers">
			
		</div>
		<br /><br />
		<span class="stitle">Player kills/deaths</span><br />
		<div id="player_kills" style="float:left; width:49%; border: 0px solid #000;">
			&nbsp;
		</div>
		<div id="player_deaths" style="float:right; width:49%; border: 0px solid #000;">
			&nbsp;
		</div>
		<br /><br />
	</div>""")
	
	# End of padding
	output.append("</div>")
	
	# Load in the player powers
	output.append(common.onload("""
		$('#player_powers').load('web.py', {'mode':'list_powers','player':'%d', 'ajax':'True'});
		$('#player_kills').load('web.py', {'mode':'player_kills','killer':'%d', 'player':'%d', 'ajax':'True'});
		$('#player_deaths').load('web.py', {'mode':'player_kills','victim':'%d', 'player':'%d', 'ajax':'True'});
	""" % (player_id, player_id, player_id, player_id, player_id)))
	
	return "".join(output)
Esempio n. 5
0
def main(cursor):
    # Get city Id
    city_id = int(common.get_val("city", 1))
    if city_id < 1:
        return "No city selected"

    # Build city item
    the_city = city_q.get_one_city(cursor, city_id)

    # Get buildings list
    building_dict = building_q.get_all_buildings(cursor)

    # If we're being sent the info from the view_map page then this is the new location we need
    new_location = common.get_val("location", "")

    if new_location == "":
        new_location = "%s,%s" % (the_city.x, the_city.y)  # default value

    output = []

    output.append(
        """<div style="float: right; width: 50%;">
		<strong>Happiness</strong>
		<div id="happiness">
			
		</div>
	</div>"""
    )

    output.append(
        """<div style='padding: 5px;'>
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_city_commit" />
		<input type="hidden" name="id" id="id" value="%(city_id)s" />
		
		Editing: %(name_text)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="web.py?mode=edit_army&amp;garrison=%(city_id)s">Edit garrison</a>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="web.py?mode=list_operatives&amp;city=%(city_id)s">Operatives</a>
		<br /><br />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="team">Team:</label></td>
				<td colspan="4" style="padding: 1px;">%(owner_select)s</td>
				
				<td width="5">&nbsp;</td>
				
				<td>&nbsp;</td>
				<td colspan="6">&nbsp;</td>
			</tr>
			<tr>
				<td><label for="size">Size:</label></td>
				<td style="padding: 1px;">%(city_population_text)s</td>
				
				<td width="5">&nbsp;</td>
				
				<td><label for="slaves">Slaves:</label></td>
				<td style="padding: 1px;">%(city_slaves_text)s</td>
				
				<td width="5">&nbsp;</td>
				<td style="padding: 0px;">
					<a class="block_link" href="web.py?mode=view_map&amp;new_mode=edit_city&amp;city=%(city_id)s"">Location:</a>
				</td>
				<td style="padding: 1px;">%(city_location_text)s</td>
				
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><label for="port">Port:</label></td>
				<td>%(city_port_checkbox)s</td>
				
				<td><label for="nomadic">Nomadic:</label></td>
				<td>%(city_nomadic_checkbox)s</td>
				
				<td><label for="dead">Dead:</label></td>
				<td>%(city_dead)s</td>
				
				<td><label for="secret">Secret:</label></td>
				<td>%(city_secret_checkbox)s</td>
				
				<td><label for="founded">Founded:</label></td>
				<td>%(founded_text)s</td>
			</tr>
			<tr>
				<td colspan="10">&nbsp;&nbsp;&nbsp;Description:<br />
					%(city_description_textarea)s
				</td>
			</tr>
		</table>
		<br />
		<input type="submit" value="Perform edit" />
	</form>
	<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="city" id="city" value="%(city_id)s" />
		<input type="hidden" name="mode" id="mode" value="remove_city" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete city" onclick="var answer = confirm('Delete %(name_safe)s?')
		if (answer) $('#delete_form').submit();" />
	</form>
	<br /><br />"""
        % {
            "city_id": city_id,
            "name": the_city.name,
            "name_text": common.text_box("name", the_city.name, size=20),
            "owner_select": team_f.structured_list(cursor, default=the_city.team, field_name="team"),
            # "city_location_text":			common.text_box("location", "%s,%s" % (the_city.x, the_city.y), 10),
            "city_location_text": common.text_box("location", new_location, 10),
            "city_population_text": common.text_box("population", the_city.population, 10),
            "city_slaves_text": common.text_box(
                "slaves", the_city.slaves, 10, warn_on=lambda x: (True if int(x) < 0 else False)
            ),
            "city_port_checkbox": common.check_box("port", the_city.port),
            "city_dead": common.text_box("dead", the_city.dead, 5),
            "city_nomadic_checkbox": common.check_box("nomadic", the_city.nomadic),
            "city_secret_checkbox": common.check_box("secret", the_city.secret),
            "city_description_textarea": '<textarea name="description" id="description" rows="4" cols="40">%s</textarea>'
            % the_city.description,
            "founded_text": the_city.founded,
            "name_safe": common.js_name(the_city.name),
        }
    )

    # 	Buildings
    # ----------------------
    the_city.get_buildings(cursor)

    output.append(
        """
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Building</th>
		<th>Progress</th>
		<th>Amount</th>
		<th>&nbsp;</th>
		<th>&nbsp;</th>
	</tr>
	"""
    )

    counter = -1
    building_remove_list = []
    for building_id, completion in the_city.buildings.items():
        counter += 1

        building_remove_list.append(building_id)

        output.append(
            """
		<tr class="row%(row)d">
			<form id="b_%(building_id)s" action="exec.py" method="get" accept-charset="utf-8">
				<input type="hidden" name="mode" value="set_building" />
				<input type="hidden" name="city" value="%(city_id)s" />
				<input type="hidden" name="building" value="%(building_id)s" />
				<td><label for="%(building_name)s">%(building_name)s</label></td>
				<td style="padding: 1px;">
					%(building_completion_text)s/%(building_build_time)s
				</td>
				<td style="padding: 1px;">
					%(building_amount_text)s
				</td>
				<td style="padding: 0px;">
					<!--<a class="block_link" href="#" onclick="$('#b_%(building_id)s').submit();">Edit</a>-->
					<input type="submit" value="Edit" />
				</td>
				<td style="padding: 0px;">
					<a class="block_link" href="exec.py?mode=set_building&amp;building=%(building_id)d&amp;city=%(city_id)d&amp;completion=0&amp;amount=0">Remove</a>
				</td>
			</form>
		</tr>"""
            % {
                "row": (counter % 2),
                "building_name": building_dict[building_id].name,
                "building_id": building_id,
                "building_build_time": building_dict[building_id].build_time,
                "city_id": city_id,
                "building_completion_text": common.text_box("completion", the_city.buildings[building_id], size=4),
                "building_amount_text": common.text_box("amount", the_city.buildings_amount[building_id], size=3),
            }
        )

    output.append(
        """
		<tr class="row%(row)d">
		<form id="city_add_building_form" action="exec.py" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="set_building" />
			<input type="hidden" name="city" value="%(city_id)s" />
			<td style="padding:1px;">
				<select id="new_building" name="building" onchange="$('#building_completion_span').load('web.py', {mode: 'get_building_build_time', building: document.getElementById('new_building').value, ajax:'True'});">
					%(building_option_box)s
				</select>
			</td>
			<td style="padding:1px;">
				%(building_completion_text)s/<span id="building_completion_span">000</span>
			</td>
			<td style="padding:1px;">
				%(building_amount_text)s
			</td>
			<td style="padding: 0px;" colspan="2">
				<input type="submit" value="Add" />
				<!--<a href="#" onclick="$('#city_add_building_form').submit();" class="block_link">Add</a>-->
			</td>
		</tr>
		</form>
	</table>
	%(onload)s
	"""
        % {
            "row": ((counter + 1) % 2),
            "city_id": the_city.id,
            "building_option_box": building_f.building_option_list(cursor, building_remove_list),
            "building_completion_text": common.text_box("completion", 0, size=4),
            "building_amount_text": common.text_box("amount", 0, size=3),
            "onload": common.onload("$('#new_building').focus();"),
        }
    )

    output.append(
        common.onload(
            "$('#building_completion_span').load('web.py', {mode: 'get_building_build_time', building: document.getElementById('new_building').value, 'ajax':1});"
        )
    )

    output.append("<strong>Wonder construction speed</strong>")
    output.append("<ul>")

    # Work out city points
    cities_dict = city_q.get_cities_from_team(cursor, the_city.team)
    total_points = 0
    for city_id2, city2 in cities_dict.items():
        if city2.team != the_city.team:
            continue
        if city2.dead == True:
            continue

        points = city_rules.wonder_build_rate(city2, the_city)
        if points > 0:
            output.append("<li>%s: %s</li>" % (city2.name, points))
            total_points += points

    output.append("<li><em>Total: %s</em></li>" % total_points)
    output.append("</ul>")

    output.append(
        common.onload(
            "$('#happiness').load('web.py', {'mode':'happiness_breakdown','city':'%d', 'ajax':'True'});"
            % int(the_city.id)
        )
    )

    # output.append('''<img src="%simages/grid_25.png" width="0" height="0" onload="">''' % common.data['media_path'])
    output.append("</div>")

    page_data["Title"] = "Edit city (%s)" % the_city.name
    return "".join(output)
Esempio n. 6
0
def main(cursor):
	wonder_id = int(common.get_val('wonder', 0))
	
	if wonder_id < 1: return "No wonder selected"
	
	the_wonder = wonder_q.get_one_wonder(cursor, wonder_id)
	cities_dict = city_q.get_live_cities(cursor)
	teams_dict = team_q.get_real_teams(cursor)
	
	names = {}
	for c, the_city in cities_dict.items():
		names[c] = the_city.name
	
	# TODO Make this do it properly
	tnames = {}
	for t, the_team in teams_dict.items():
		tnames[t] = the_team.name
	
	output = ["<div style='padding: 5px;'>"]
	
	output.append("""
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_wonder_commit" />
		<input type="hidden" name="id" id="id" value="%(wonder_id)s" />
	
		Editing: %(name_text)s
		<br /><br />
	
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="city">City:</label></td>
				<td>%(city_menu)s</td>
		
				<td width="5">&nbsp;</td>
			
				<td><label for="team">Team:</label></td>
				<td>%(team_menu)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="completed">Completed:</label></td>
				<td style="padding: 1px;">%(completed)s</td>
			</tr>
			<tr>
				<td><label for="completion">Completion:</label></td>
				<td style="padding: 1px;">%(completion)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="point_cost">Point cost:</label></td>
				<td style="padding: 1px;">%(point_cost)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="material_cost">Material cost:</label></td>
				<td style="padding: 1px;">%(material_cost)s</td>
			</tr>
			<tr>
				<td colspan="10">&nbsp;&nbsp;&nbsp;Description:<br />
					%(description)s
				</td>
			</tr>
		</table>
		<br />
		<input type="submit" value="Perform edit" />
	</form>
	<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="wonder" id="wonder" value="%(wonder_id)s" />
		<input type="hidden" name="mode" id="mode" value="remove_wonder" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete wonder" onclick="var answer = confirm('Delete %(name_safe)s?')
		if (answer) $('#delete_form').submit();" />
	</form>
	<br /><br />""" % {
		"wonder_id":					wonder_id,
		"name_text":				common.text_box("name", the_wonder.name),
		
		"city_menu":					common.option_box(
			name='city',
			elements=names,
			element_order=cities_dict.keys(),
			custom_id="",
			selected=the_wonder.city,
		),
		
		"team_menu":					common.option_box(
			name='team',
			elements=tnames,
			element_order=teams_dict.keys(),
			custom_id="",
			selected=the_wonder.team,
		),
		
		"completed":				common.check_box("completed", the_wonder.completed),
		"completion":				common.text_box("completion", the_wonder.completion, size=7),
		"point_cost":				common.text_box("point_cost", the_wonder.point_cost, size=7),
		"material_cost":			common.text_box("material_cost", the_wonder.material_cost, size=7),
		
		"description":	'<textarea name="description" id="description" rows="4" style="width:99%%;">%s</textarea>' % the_wonder.description,
		
		"name_safe":			common.js_name(the_wonder.name),
	})
	
	output.append("</div>")
	
	return "".join(output)