예제 #1
0
def main(cursor):
	turn = int(common.get_val("turn", -1))
	
	if turn < 1:
		turn = common.current_turn()
	
	battle_dict	= battle_q.get_battles_from_turn(cursor, turn)
	teams_dict	= team_q.get_all_teams(cursor)
	
	output = []
	
	output.append("""
	<div style="padding: 5px;">
	
	<form action="web.py" method="get" accept-charset="utf-8">
		<a href="list_battles" style="text-align:left;" class="block_link">This turn's battles</a>
		<br />
		<input type="hidden" name="mode" id="mode" value="list_battles" />
		Turn: <input type="text" name="turn" value="%s" />
		&nbsp;&nbsp;&nbsp; <input type="submit" value="Show" />
	</form>
	<br /><br />""" % (turn))
	
	output.append("""<table border="0" cellspacing="0" cellpadding="5">
		<tr class="row2">
			<th>Turn</th>
			<th>Battle name</th>
			<th>Participants</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
		</tr>
	""")
	
	count = -1
	for b, the_battle in battle_dict.items():
		participants = the_battle.get_participants(cursor)
		
		participants_list = []
		for t, s in participants.items():
			if s:
				participants_list.append("<em style='color:#555;'>%s</em>" % teams_dict[t].name)
			else:
				participants_list.append(teams_dict[t].name)
		
		count += 1
		
		output.append("""
		<tr class="row%(count)s">
			<td>%(turn)s</td>
			<td>%(name)s</td>
			<td>%(participants)s</td>
			<td style="padding:0px;"><a href="web.py?mode=edit_battle&amp;battle=%(battle_id)s" class="block_link">Edit</a></td>
			<td style="padding:0px;"><a href="view_battle&amp;battle=%(battle_id)s" class="block_link">View</a></td>
		</tr>
		""" % {
			"count":		count%2,
			"turn":			turn,
			"name":	the_battle.name,
			"participants":	", ".join(participants_list),
			"battle_id":	the_battle.id,
		})
	
	count += 1
	output.append("""
	<tr class="row%(count)s">
		<form action="exec.py" id="add_battle_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="add_battle" />
		<td style="padding: 1px;"><input type="text" name="battle_turn" value="%(turn)s" size="5"/></td>
		<td style="padding: 1px;"><input type="text" name="name" id="name" value="" /></td>
		<td>&nbsp;</td>
		<td style="padding: 0px;" colspan="2"><a class="block_link" href="#" onclick="$('#add_battle_form').submit();">Add</a></td>
		</form>
		%(onload)s
	</tr>
	""" % {
		"turn":			turn,
		"count":		count%2,
		"onload":		common.onload("$('#name').focus();"),
	})
	
	output.append("</table></div>")
	
	return "".join(output)
예제 #2
0
파일: turn_info.py 프로젝트: Teifion/Rob3
def main(cursor):
	return ""
	
	output = ["""<div style="padding: 5px;">"""]
	
	ajax = common.get_val('ajax', 0)
	
	if not ajax:
		page_data['Headers'] = False
	
	battle_dict		= battle_q.get_battles_from_turn(cursor, common.current_turn())
	team_dict		= team_q.get_all_teams(cursor)
	city_dict		= city_q.get_all_cities(cursor)
	
	output.append("""<table border="0" cellspacing="0" cellpadding="5">
		<tr class="row2">
			<th>Battle</th>
			<th>Time</th>
			<th>Location</th>
		</tr>""")
	
	# Display battles
	i = -1
	for battle_id, the_battle in battle_dict.items():
		i += 1
		
		location = "%d, %d" % (the_battle.x, the_battle.y)
		
		if i == 0:
			days_since = ""
			time_taken = ""
			distance = ""
		else:
			waypoints = ((last_battle.x, last_battle.y), (the_battle.x, the_battle.y))
			b_path = path_f.path(cursor, waypoints, move_speed="Marching", move_type="Medium foot")
			
			
			days_since = "Days since last battle: {0}".format(the_battle.start - last_battle.ended)
			time_taken = "Time taken to travel: {0} days".format(b_path.time_cost)
			distance = "Distance from last battle: {0}km".format(format(b_path.walk_distance, ','))
		
		output.append("""
		<tr class="row0">
			<td><strong>{name}</strong></td>
			<td>{start} : {ended}</td>
			<td>{location}</td>
		</tr>
		<tr class="row1">
			<td colspan="3">
				{days_since}<br />
				{time_taken}<br />
				{distance}<br />
			</td>
		</tr>
		""".format(
			i=i%2,
			
			name=the_battle.name,
			start=the_battle.start,
			ended=the_battle.ended,
			location=location,
			
			days_since = days_since,
			time_taken = time_taken,
			distance = distance,
			
			id=battle_id,
		))
		
		
		# Use this to record stuff for the next battle
		last_battle = the_battle
	
	
	
	
	output.append("</table></div>")
	
	return "".join(output)