def new_club(self, club): """ Add a club on a new page :param club: Club to print :type club: Club """ logging.debug("New club: " + club.nom) if not self.story: # For the first page self.club = club else: self.story.append(NextPageTemplate(club)) self.story.append(PageBreak()) table_style = header_table_style["Club"] table = Table([[club.nom]], [self.page_width], 2 * cm, style=table_style) table.link_object = (club, club.nom) self.story.append(table) table_style = header_table_style["Content"] for departemental in (True, False): total = 0 if departemental: competitions = [c for c in club.competitions if c.departemental() and c.competition_link is None] self.story.append(Paragraph("Compétitions départementales", sHeading2)) bonus = self.bonus["Départemental"] else: competitions = [c for c in club.competitions if not c.departemental() and c.competition_link is None] self.story.append(Paragraph("Compétitions régionales et plus", sHeading2)) bonus = self.bonus["Régional"] table_data = [["Compétition", "Réunions", "Points"]] for competition in sorted(competitions, key=lambda c: c.startdate): description = [Paragraph("{} - {}".format(competition.date_str(), competition.titre()), sNormal)] for c in competition.linked: description.append(Paragraph("{} - {}".format(c.date_str(), c.titre()), sNormal)) row = [description, [], []] for reunion in competition.reunions: pts = reunion.points(club) total += pts row[1].append(Paragraph("<a href='#{}'>{}</a>".format(reunion.link(), reunion.titre), sNormal)) row[2].append(Paragraph("{} points".format(pts), sNormal)) table_data.append(row) table = Table(table_data, [self.page_width * x for x in (0.70, 0.15, 0.15)], style=table_style) self.story.append(table) self.story.append(Paragraph("<br/>Total des points: {}".format(total), sNormal)) if total < 0: self.story.append(Paragraph("Valeur du malus: {:.2f} €".format(total * 10), sNormal)) else: self.story.append(Paragraph("Valeur du bonus (Estimation): {:.2f} €" .format(total * bonus), sNormal))
def competition_header(self, competition): """ Add header for the competition :param competition: New competition :type competition: Competition """ if competition.departemental(): table_style = header_table_style["Départemental"] else: table_style = header_table_style["Régional"] table_data = [[competition.titre()], [competition.type], [competition.date_str()]] table = Table(table_data, [self.page_width], [cm, 0.5 * cm, 0.5 * cm], style=table_style) table.link_object = (competition, competition.titre()) self.story.append(table) self.story.append(Paragraph("Lien WebFFN: <a href='{}'>{}</a>" .format(competition.weblink(), competition.weblink()), sNormal))
def new_club(self, club): """ Add a club on a new page :param club: Club to print :type club: Club """ logging.debug("New club: " + club.nom) if not self.story: # For the first page self.club = club else: self.story.append(NextPageTemplate(club)) self.story.append(PageBreak()) table_style = header_table_style["Club"] table = Table([[club.nom]], [self.page_width], 2 * cm, style=table_style) table.link_object = (club, club.nom) self.story.append(table) table_style = header_table_style["Content"] for departemental in (True, False): total = 0 if departemental: competitions = [c for c in club.competitions if c.departemental() and c.competition_link is None] self.story.append(Paragraph("Compétitions départementales", sHeading2)) bonus = self.bonus[club.departement_name()] else: competitions = [c for c in club.competitions if not c.departemental() and c.competition_link is None] self.story.append(Paragraph("Compétitions régionales et plus", sHeading2)) bonus = self.bonus["Régional"] # TODO: Remove clubs with departement != 06 if departemental and club.departement != "06": self.story.append(Paragraph("Pas d'information départementale", sNormal)) continue table_data = [["Compétition", "Réunion", "Points"]] for competition in sorted(competitions, key=lambda c: c.startdate): description = [Paragraph("{} - {}".format(competition.date_str(), competition.titre()), sNormal)] for c in competition.linked: description.append(Paragraph("{} - {}".format(c.date_str(), c.titre()), sNormal)) row = [description, [], []] for reunion in competition.reunions: pts = reunion.points(club) total += pts row[1].append(Paragraph("<a href='#{}'>{}</a>".format(reunion.link(), reunion.titre), sNormal)) row[2].append(Paragraph("{} points".format(pts), sNormal)) table_data.append(row) table = Table(table_data, [self.page_width * x for x in (0.70, 0.15, 0.15)], style=table_style) self.story.append(table) self.story.append(Paragraph("<br/>Total des points: {}".format(total), sNormal)) if total < 0: self.story.append(Paragraph("Valeur du malus: {:.2f} €".format(total * 10), sNormal)) else: self.story.append(Paragraph("Valeur du bonus (Estimation): {:.2f} €" .format(total * bonus), sNormal)) self.story.append(Paragraph("Liste des officiels", sHeading2)) if len(club.officiels.keys()) == 0: self.story.append(Paragraph("Pas d'officiel pour le club", sNormal)) else: self.story.append(Paragraph("Lorsqu'un officiel est inscrit pour plusieurs poste, un seul est retenu.", sNormal)) officiels = sorted(club.officiels.keys(), key=lambda o: o.nom) for officiel in officiels: table_data = [["{} {} ({}) - {} participations".format(officiel.prenom, officiel.nom, officiel.niveau, len(club.officiels[officiel].values())), "Réunion", "Rôle"]] competitions = dict() for reunion, poste in club.officiels[officiel].items(): if reunion.competition not in competitions: competitions[reunion.competition] = [] competitions[reunion.competition].append((reunion, poste)) for competition in sorted(competitions.keys(), key=lambda c: c.startdate): description = [Paragraph("{} - {}".format(competition.date_str(), competition.titre()), sNormal)] row = [description, [], []] for c in competition.linked: description.append(Paragraph("{} - {}".format(c.date_str(), c.titre()), sNormal)) for reunion, poste in competitions[competition]: row[1].append(Paragraph("<a href='#{}'>{}</a>".format(reunion.link(), reunion.titre), sNormal)) row[2].append(Paragraph(poste, sNormal)) table_data.append(row) table_style = header_table_style["Content"] table = Table(table_data, [self.page_width * x for x in (0.65, 0.15, 0.20)], style=table_style) self.story.append(Paragraph(" ", sNormal)) self.story.append(table)