Skip to content

Commit 4ec3a0e

Browse files
committed
timesheet to pdf
1 parent 72e7f40 commit 4ec3a0e

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

notebooks/walkthrough/03-timetracking.ipynb

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
{
124124
"data": {
125125
"application/vnd.jupyter.widget-view+json": {
126-
"model_id": "151698f5838c469eb93b412f8a70db7a",
126+
"model_id": "59af9b5c3d89479f9f6b54f7f04379bd",
127127
"version_major": 2,
128128
"version_minor": 0
129129
},
@@ -719,6 +719,14 @@
719719
")"
720720
]
721721
},
722+
{
723+
"cell_type": "markdown",
724+
"id": "8a73369f-e18c-4475-b870-f313abf98124",
725+
"metadata": {},
726+
"source": [
727+
"This will create a folder named with the timesheet title, containing the timesheet as an HTML document."
728+
]
729+
},
722730
{
723731
"cell_type": "code",
724732
"execution_count": 19,
@@ -728,6 +736,30 @@
728736
"source": [
729737
"timesheet_path = str(timesheet_dir / f\"Invoice-{my_timesheet.title}\" / f\"Timesheet-{my_timesheet.title}.html\")"
730738
]
739+
},
740+
{
741+
"cell_type": "markdown",
742+
"id": "92ef3025-2a90-4d59-88fe-01a750c3a2f7",
743+
"metadata": {},
744+
"source": [
745+
"You can also render the timesheet to PDF. For now, this requires the native [wkhtmltopdf](https://wkhtmltopdf.org) tool to be installed."
746+
]
747+
},
748+
{
749+
"cell_type": "code",
750+
"execution_count": 20,
751+
"id": "4e7234aa-92fe-4c45-93b6-51f02de7c69f",
752+
"metadata": {},
753+
"outputs": [],
754+
"source": [
755+
"tuttle.rendering.render_timesheet(\n",
756+
" user=app.user,\n",
757+
" timesheet=my_timesheet,\n",
758+
" style=\"anvil\",\n",
759+
" out_dir=timesheet_dir,\n",
760+
" document_format=\"pdf\",\n",
761+
")"
762+
]
731763
}
732764
],
733765
"metadata": {

notebooks/walkthrough/04-invoicing.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@
584584
" invoice=my_invoice,\n",
585585
" style=\"anvil\",\n",
586586
" out_dir=invoice_dir,\n",
587-
" format=\"pdf\"\n",
587+
" document_format=\"pdf\"\n",
588588
")"
589589
]
590590
},

tuttle/rendering.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def convert_html_to_pdf(
4242
def render_invoice(
4343
user: User,
4444
invoice: Invoice,
45-
format: str = "html",
45+
document_format: str = "html",
4646
out_dir: str = None,
4747
style: str = None,
4848
) -> str:
@@ -108,7 +108,7 @@ def as_percentage(number):
108108
invoice_dir / stylesheet_folder_path,
109109
dirs_exist_ok=True,
110110
)
111-
if format == "pdf":
111+
if document_format == "pdf":
112112
css_paths = [
113113
path for path in glob.glob(f"{invoice_dir}/**/*.css", recursive=True)
114114
]
@@ -122,6 +122,7 @@ def as_percentage(number):
122122
def render_timesheet(
123123
user: User,
124124
timesheet: Timesheet,
125+
document_format: str = "html",
125126
out_dir: str = None,
126127
style: str = "anvil",
127128
) -> str:
@@ -173,6 +174,15 @@ def render_timesheet(
173174
timesheet_dir / stylesheet_folder_path,
174175
dirs_exist_ok=True,
175176
)
177+
if document_format == "pdf":
178+
css_paths = [
179+
path for path in glob.glob(f"{timesheet_dir}/**/*.css", recursive=True)
180+
]
181+
convert_html_to_pdf(
182+
in_path=str(timesheet_path),
183+
css_paths=css_paths,
184+
out_path=timesheet_dir / Path(f"{prefix}.pdf"),
185+
)
176186

177187

178188
def render_timeline(

0 commit comments

Comments
 (0)