summaryrefslogtreecommitdiff
path: root/jfr_playoff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2018-02-21 14:09:05 +0100
committeremkael <emkael@tlen.pl>2018-02-21 14:09:05 +0100
commitccc54fde2f8c9301962e9c6f464d5f2eacd5506a (patch)
tree21a2f05ea664065d1aa98a3c69d58d6c14afdf59 /jfr_playoff
parent415748f29a6b3048bef08703a93c4f441f67d1eb (diff)
Not rendering phase/match links if they're not set
Fixes #13
Diffstat (limited to 'jfr_playoff')
-rw-r--r--jfr_playoff/data.py5
-rw-r--r--jfr_playoff/generator.py35
-rw-r--r--jfr_playoff/matchinfo.py8
-rw-r--r--jfr_playoff/template.py44
-rw-r--r--jfr_playoff/tournamentinfo.py2
5 files changed, 67 insertions, 27 deletions
diff --git a/jfr_playoff/data.py b/jfr_playoff/data.py
index 7f29bb2..c588610 100644
--- a/jfr_playoff/data.py
+++ b/jfr_playoff/data.py
@@ -36,7 +36,7 @@ class PlayoffData(object):
phase_count += len(phase['dummies'])
phase_object = Phase()
phase_object.title = phase['title']
- phase_object.link = phase['link']
+ phase_object.link = phase['link'] if 'link' in phase else None
phase_object.matches = [None] * phase_count
phase_pos = 0
for match in phase['matches']:
@@ -53,7 +53,8 @@ class PlayoffData(object):
for phase in self.phases:
for match in phase['matches']:
match_info = MatchInfo(match, self.teams, self.database)
- match_info.set_phase_link(phase['link'])
+ if 'link' in phase:
+ match_info.set_phase_link(phase['link'])
self.match_info[match['id']] = match_info.get_info()
if self.match_info[match['id']].running > 0:
for phase_obj in self.grid:
diff --git a/jfr_playoff/generator.py b/jfr_playoff/generator.py
index 49ae3a4..06234fb 100644
--- a/jfr_playoff/generator.py
+++ b/jfr_playoff/generator.py
@@ -33,24 +33,28 @@ class PlayoffGenerator(object):
def get_match_table(self, match):
rows = ''
for team in match.teams:
+ score_html = p_temp.MATCH_SCORE % (team.score)
+ team_label = ' / '.join([
+ self.data.get_shortname(name) for name in
+ team.name.split('<br />')])
+ team_html = p_temp.MATCH_TEAM_LINK % (
+ match.link, team.name, team_label) if match.link is not None \
+ else p_temp.MATCH_TEAM_NON_LINK % (
+ team.name, team_label)
rows += p_temp.MATCH_TEAM_ROW % (
' '.join([
'winner' if team.name == match.winner else '',
'loser' if team.name == match.loser else ''
]).strip(),
- match.link,
- team.name,
- ' / '.join([
- self.data.get_shortname(name) for name in
- team.name.split('<br />')]),
- match.link,
- team.score)
+ team_html,
+ p_temp.MATCH_LINK % (match.link, score_html) if match.link is not None else score_html)
html = p_temp.MATCH_TABLE.decode('utf8') % (
int(self.page['width'] * 0.75),
int(self.page['width'] * 0.25),
rows)
if match.running > 0:
- html += p_temp.MATCH_RUNNING % (match.link, match.running)
+ running_html = p_temp.MATCH_RUNNING % (match.running)
+ html += p_temp.MATCH_LINK % (match.link, running_html) if match.link is not None else running_html
return html
def get_phase_header(self, phase, position):
@@ -58,11 +62,16 @@ class PlayoffGenerator(object):
grid_header = p_temp.MATCH_GRID_PHASE_RUNNING
else:
grid_header = p_temp.MATCH_GRID_PHASE
- return grid_header % (
- phase.link,
- self.page['width'],
- position,
- phase.title)
+ grid_header = grid_header % (phase.title)
+ if phase.link is not None:
+ return p_temp.MATCH_GRID_PHASE_LINK % (
+ phase.link,
+ self.page['width'], position,
+ grid_header)
+ else:
+ return p_temp.MATCH_GRID_PHASE_NON_LINK % (
+ self.page['width'], position,
+ grid_header)
def get_match_box(self, match, position):
if match is not None:
diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py
index ebae673..1f6446e 100644
--- a/jfr_playoff/matchinfo.py
+++ b/jfr_playoff/matchinfo.py
@@ -90,6 +90,8 @@ class MatchInfo:
return None
def __get_html_teams(self, teams, fetch_score):
+ if self.info.link is None:
+ raise ValueError('link not set')
row = self.__find_table_row(self.info.link)
if row is None:
raise ValueError('table row not found')
@@ -205,6 +207,8 @@ class MatchInfo:
return 0, False
def __get_html_board_count(self):
+ if self.info.link is None:
+ raise ValueError('link not set')
row = self.__find_table_row(self.info.link)
if row is None:
raise ValueError('table row not found')
@@ -265,6 +269,8 @@ class MatchInfo:
prefix, round_no, self.config['table'], current_segment)
def __get_html_running_link(self):
+ if self.info.link is None:
+ raise ValueError('link not set')
row = self.__find_table_row(self.info.link)
running_link = row.select('td.bdcg a[href]')
if len(running_link) == 0:
@@ -272,6 +278,8 @@ class MatchInfo:
return urljoin(self.info.link, running_link[0]['href'])
def __determine_running_link(self):
+ if self.info.link is None:
+ return
link_match = re.match(r'^(.*)runda(\d+)\.html$', self.info.link)
if link_match:
try:
diff --git a/jfr_playoff/template.py b/jfr_playoff/template.py
index b814026..8e2d207 100644
--- a/jfr_playoff/template.py
+++ b/jfr_playoff/template.py
@@ -10,23 +10,37 @@ MATCH_TABLE = '''
</table>
'''
+MATCH_LINK = '''
+<a href="%s" target="_top">
+%s
+</a>
+'''
+
+MATCH_SCORE = '''
+&nbsp;%.1f&nbsp;
+'''
+
+MATCH_TEAM_LINK = '''
+<a href="%s" onmouseover="Tip('%s')" onmouseout="UnTip()">%s</a>
+'''
+
+MATCH_TEAM_NON_LINK = '''
+<a onmouseover="Tip('%s')" onmouseout="UnTip()">%s</a>
+'''
+
MATCH_TEAM_ROW = '''
<tr class="%s">
-<td class="bd1">&nbsp;<a href="%s" onmouseover="Tip('%s')" onmouseout="UnTip()">%s</a>&nbsp;</td>
+<td class="bd1">&nbsp;%s&nbsp;</td>
<td class="bdc">
-<a href="%s" target="_top">
-&nbsp;%.1f&nbsp;
-</a>
+%s
</td>
</tr>
'''
MATCH_RUNNING = '''
-<a href="%s" target="_top">
<img src="images/A.gif" />
-%d
+<span style="font-size: 10pt">%d</span>
<img src="images/A.gif" />
-</a>
'''
MATCH_GRID = '''
@@ -37,18 +51,26 @@ MATCH_GRID = '''
</div>
'''
-MATCH_GRID_PHASE = '''
+MATCH_GRID_PHASE_LINK = '''
<a href="%s" target="_top" style="display: inline-block; width: %dpx; text-align: center; position: absolute; top: 0; left: %dpx">
-<font size="4">%s</font>
+%s
</a>
'''
+MATCH_GRID_PHASE_NON_LINK = '''
+<span class="phase_header" style="display: inline-block; width: %dpx; text-align: center; position: absolute; top: 0; left: %dpx">
+<p style="margin: 0">%s</p>
+</span>
+'''
+
+MATCH_GRID_PHASE = '''
+<font size="4">%s</font>
+'''
+
MATCH_GRID_PHASE_RUNNING = '''
-<a href="%s" target="_top" style="display: inline-block; width: %dpx; text-align: center; position: absolute; top: 0; left: %dpx">
<img src="images/A.gif" />
<font size="4">%s</font>
<img src="images/A.gif" />
-</a>
'''
MATCH_BOX = '''
diff --git a/jfr_playoff/tournamentinfo.py b/jfr_playoff/tournamentinfo.py
index dee34f3..90637bc 100644
--- a/jfr_playoff/tournamentinfo.py
+++ b/jfr_playoff/tournamentinfo.py
@@ -123,7 +123,7 @@ class TournamentInfo:
teams = self.__get_html_results()
except (TypeError, IndexError, KeyError, IOError, ValueError):
pass
- if 'final_positions' in self.settings:
+ if self.is_finished() and 'final_positions' in self.settings:
for position in self.settings['final_positions']:
if len(teams) >= position:
teams[position-1].append(position)