File tree Expand file tree Collapse file tree 3 files changed +46
-4
lines changed Expand file tree Collapse file tree 3 files changed +46
-4
lines changed Original file line number Diff line number Diff line change 123
123
{
124
124
"data" : {
125
125
"application/vnd.jupyter.widget-view+json" : {
126
- "model_id" : " 151698f5838c469eb93b412f8a70db7a " ,
126
+ "model_id" : " 59af9b5c3d89479f9f6b54f7f04379bd " ,
127
127
"version_major" : 2 ,
128
128
"version_minor" : 0
129
129
},
719
719
" )"
720
720
]
721
721
},
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
+ },
722
730
{
723
731
"cell_type" : " code" ,
724
732
"execution_count" : 19 ,
728
736
"source" : [
729
737
" timesheet_path = str(timesheet_dir / f\" Invoice-{my_timesheet.title}\" / f\" Timesheet-{my_timesheet.title}.html\" )"
730
738
]
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
+ ]
731
763
}
732
764
],
733
765
"metadata" : {
Original file line number Diff line number Diff line change 584
584
" invoice=my_invoice,\n " ,
585
585
" style=\" anvil\" ,\n " ,
586
586
" out_dir=invoice_dir,\n " ,
587
- " format =\" pdf\"\n " ,
587
+ " document_format =\" pdf\"\n " ,
588
588
" )"
589
589
]
590
590
},
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ def convert_html_to_pdf(
42
42
def render_invoice (
43
43
user : User ,
44
44
invoice : Invoice ,
45
- format : str = "html" ,
45
+ document_format : str = "html" ,
46
46
out_dir : str = None ,
47
47
style : str = None ,
48
48
) -> str :
@@ -108,7 +108,7 @@ def as_percentage(number):
108
108
invoice_dir / stylesheet_folder_path ,
109
109
dirs_exist_ok = True ,
110
110
)
111
- if format == "pdf" :
111
+ if document_format == "pdf" :
112
112
css_paths = [
113
113
path for path in glob .glob (f"{ invoice_dir } /**/*.css" , recursive = True )
114
114
]
@@ -122,6 +122,7 @@ def as_percentage(number):
122
122
def render_timesheet (
123
123
user : User ,
124
124
timesheet : Timesheet ,
125
+ document_format : str = "html" ,
125
126
out_dir : str = None ,
126
127
style : str = "anvil" ,
127
128
) -> str :
@@ -173,6 +174,15 @@ def render_timesheet(
173
174
timesheet_dir / stylesheet_folder_path ,
174
175
dirs_exist_ok = True ,
175
176
)
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
+ )
176
186
177
187
178
188
def render_timeline (
You can’t perform that action at this time.
0 commit comments