fix: distinguish task titles in client PDF
Build and publish Docker image / publish (push) Successful in 11s
Build and publish Docker image / publish (push) Successful in 11s
This commit is contained in:
+30
-12
@@ -12,16 +12,27 @@ from reportlab.pdfbase.ttfonts import TTFont
|
||||
from reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer, Table, TableStyle
|
||||
|
||||
|
||||
def _font_name():
|
||||
def _font_names():
|
||||
candidates = (
|
||||
Path("C:/Windows/Fonts/arial.ttf"),
|
||||
Path("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"),
|
||||
(Path("C:/Windows/Fonts/arial.ttf"), Path("C:/Windows/Fonts/arialbd.ttf")),
|
||||
(
|
||||
Path("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"),
|
||||
Path("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"),
|
||||
),
|
||||
)
|
||||
for path in candidates:
|
||||
if path.exists():
|
||||
pdfmetrics.registerFont(TTFont("TimerrFont", path))
|
||||
return "TimerrFont"
|
||||
return "Helvetica"
|
||||
for regular_path, bold_path in candidates:
|
||||
if regular_path.exists() and bold_path.exists():
|
||||
pdfmetrics.registerFont(TTFont("TimerrFont", regular_path))
|
||||
pdfmetrics.registerFont(TTFont("TimerrFont-Bold", bold_path))
|
||||
pdfmetrics.registerFontFamily(
|
||||
"TimerrFont",
|
||||
normal="TimerrFont",
|
||||
bold="TimerrFont-Bold",
|
||||
italic="TimerrFont",
|
||||
boldItalic="TimerrFont-Bold",
|
||||
)
|
||||
return "TimerrFont", "TimerrFont-Bold"
|
||||
return "Helvetica", "Helvetica-Bold"
|
||||
|
||||
|
||||
def _duration(minutes):
|
||||
@@ -31,11 +42,13 @@ def _duration(minutes):
|
||||
|
||||
def render_company_pdf(report, company):
|
||||
output = BytesIO()
|
||||
font = _font_name()
|
||||
font, bold_font = _font_names()
|
||||
styles = getSampleStyleSheet()
|
||||
normal = ParagraphStyle("TimerrNormal", parent=styles["Normal"], fontName=font, fontSize=9, leading=12)
|
||||
heading = ParagraphStyle("TimerrHeading", parent=styles["Heading1"], fontName=font, fontSize=18, leading=22)
|
||||
subheading = ParagraphStyle("TimerrSubheading", parent=styles["Heading2"], fontName=font, fontSize=13, leading=16)
|
||||
heading = ParagraphStyle("TimerrHeading", parent=styles["Heading1"], fontName=bold_font, fontSize=18, leading=22)
|
||||
subheading = ParagraphStyle("TimerrSubheading", parent=styles["Heading2"], fontName=bold_font, fontSize=13, leading=16)
|
||||
task_title = ParagraphStyle("TimerrTaskTitle", parent=normal, fontName=bold_font, fontSize=9, leading=11, textColor=colors.HexColor("#172033"))
|
||||
task_description = ParagraphStyle("TimerrTaskDescription", parent=normal, fontSize=8, leading=11, textColor=colors.HexColor("#5a6477"))
|
||||
total = ParagraphStyle("TimerrTotal", parent=normal, fontSize=12, alignment=TA_RIGHT)
|
||||
document = SimpleDocTemplate(output, pagesize=A4, rightMargin=15 * mm, leftMargin=15 * mm, topMargin=15 * mm, bottomMargin=15 * mm)
|
||||
story = [
|
||||
@@ -53,13 +66,18 @@ def render_company_pdf(report, company):
|
||||
for task in project_group["tasks"]:
|
||||
rows.append([
|
||||
task.work_date.strftime("%d.%m.%Y"),
|
||||
Paragraph(f"<b>{escape(task.title)}</b><br/>{escape(task.description)}", normal),
|
||||
[
|
||||
Paragraph(escape(task.title), task_title),
|
||||
Spacer(1, 1.5 * mm),
|
||||
Paragraph(escape(task.description), task_description),
|
||||
],
|
||||
_duration(task.duration_minutes), f"{task.hourly_rate} ₽", f"{task.amount} ₽",
|
||||
])
|
||||
rows.append(["", "Итого по проекту", _duration(project_group["minutes"]), "", f"{project_group['amount']} ₽"])
|
||||
table = Table(rows, colWidths=(22 * mm, 78 * mm, 25 * mm, 25 * mm, 25 * mm), repeatRows=1)
|
||||
table.setStyle(TableStyle([
|
||||
("FONTNAME", (0, 0), (-1, -1), font), ("FONTSIZE", (0, 0), (-1, -1), 8),
|
||||
("FONTNAME", (0, 0), (-1, 0), bold_font),
|
||||
("BACKGROUND", (0, 0), (-1, 0), colors.HexColor("#e9edf4")),
|
||||
("GRID", (0, 0), (-1, -1), .35, colors.HexColor("#aeb7c5")),
|
||||
("VALIGN", (0, 0), (-1, -1), "TOP"), ("FONTNAME", (0, -1), (-1, -1), font),
|
||||
|
||||
Reference in New Issue
Block a user