FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
fe-builder/builder/html_preview_image.py at develop · NREADY-RnD/fe-builder · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
NREADY-RnD
/
fe-builder
Public
forked from
frappe/builder
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
fe-builder
/
builder
/
html_preview_image.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
24 lines (20 loc) · 887 Bytes
Breadcrumbs
fe-builder
/
builder
/
html_preview_image.py
Copy path
File metadata and controls
24 lines (20 loc) · 887 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import
html
as
html_parser
import
frappe
import
requests
# TODO: Find better alternative
# Note: while working locally, "preview.frappe.cloud" won't be able to generate preview properly since it can't access local server for assets
# So, for local development, better to use local server for preview generation
# (https://github.com/frappe/preview_generator)
PREVIEW_GENERATOR_URL
=
(
frappe
.
conf
.
preview_generator_url
or
"https://preview.frappe.cloud/api/method/preview_generator.api.generate_preview"
)
def
generate_preview
(
html
,
output_path
):
escaped_html
=
html_parser
.
escape
(
html
)
response
=
requests
.
post
(
PREVIEW_GENERATOR_URL
,
json
=
{
"html"
:
escaped_html
,
"format"
:
"webp"
})
if
response
.
status_code
==
200
:
with
open
(
output_path
,
"wb"
)
as
f
:
f
.
write
(
response
.
content
)
else
:
exception
=
response
.
json
().
get
(
"exc"
)
raise
Exception
(
frappe
.
parse_json
(
exception
)[
0
])
Back
|
FazBrowse Home
|
New Git URL