From ccc54fde2f8c9301962e9c6f464d5f2eacd5506a Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 21 Feb 2018 14:09:05 +0100 Subject: Not rendering phase/match links if they're not set Fixes #13 --- jfr_playoff/data.py | 5 +++-- jfr_playoff/generator.py | 35 +++++++++++++++++++++------------- jfr_playoff/matchinfo.py | 8 ++++++++ jfr_playoff/template.py | 44 ++++++++++++++++++++++++++++++++----------- jfr_playoff/tournamentinfo.py | 2 +- 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('
')]) + 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('
')]), - 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 = ''' ''' +MATCH_LINK = ''' + +%s + +''' + +MATCH_SCORE = ''' + %.1f  +''' + +MATCH_TEAM_LINK = ''' +%s +''' + +MATCH_TEAM_NON_LINK = ''' +%s +''' + MATCH_TEAM_ROW = ''' - %s  + %s  - - %.1f  - +%s ''' MATCH_RUNNING = ''' - -%d +%d - ''' MATCH_GRID = ''' @@ -37,18 +51,26 @@ MATCH_GRID = ''' ''' -MATCH_GRID_PHASE = ''' +MATCH_GRID_PHASE_LINK = ''' -%s +%s ''' +MATCH_GRID_PHASE_NON_LINK = ''' + +

%s

+
+''' + +MATCH_GRID_PHASE = ''' +%s +''' + MATCH_GRID_PHASE_RUNNING = ''' - %s - ''' 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) -- cgit v1.2.3