fix: Asset URLs
Helpers to get asset path Python: frappe.utils.jinja_globals.bundled_asset JS: frappe.assets.bundled_asset
This commit is contained in:
parent
9a00ce43ea
commit
e72bb135e1
14 changed files with 41 additions and 35 deletions
|
|
@ -203,7 +203,7 @@ frappe.ui.form.on('Data Import', {
|
|||
},
|
||||
|
||||
download_template(frm) {
|
||||
frappe.require('/assets/frappe/dist/js/data_import_tools.bundle.js', () => {
|
||||
frappe.require('data_import_tools.bundle.js', () => {
|
||||
frm.data_exporter = new frappe.data_import.DataExporter(
|
||||
frm.doc.reference_doctype,
|
||||
frm.doc.import_type
|
||||
|
|
@ -287,7 +287,7 @@ frappe.ui.form.on('Data Import', {
|
|||
return;
|
||||
}
|
||||
|
||||
frappe.require('/assets/frappe/dist/js/data_import_tools.bundle.js', () => {
|
||||
frappe.require('data_import_tools.bundle.js', () => {
|
||||
frm.import_preview = new frappe.data_import.ImportPreview({
|
||||
wrapper: frm.get_field('import_preview').$wrapper,
|
||||
doctype: frm.doc.reference_doctype,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ frappe.pages['recorder'].on_page_load = function(wrapper) {
|
|||
frappe.recorder.show();
|
||||
});
|
||||
|
||||
frappe.require('/assets/frappe/dist/js/recorder.bundle.js');
|
||||
frappe.require('recorder.bundle.js');
|
||||
};
|
||||
|
||||
class Recorder {
|
||||
|
|
|
|||
|
|
@ -408,14 +408,17 @@ frappe.ui.form.PrintView = class {
|
|||
|
||||
setup_print_format_dom(out, $print_format) {
|
||||
this.print_wrapper.find('.print-format-skeleton').remove();
|
||||
let base_url = frappe.urllib.get_base_url()
|
||||
let print_css = frappe.assets.bundled_asset('print.bundle.css');
|
||||
this.$print_format_body.find('head').html(
|
||||
`<style type="text/css">${out.style}</style>
|
||||
<link href="${frappe.urllib.get_base_url()}/assets/frappe/dist/css/print.bundle.css" rel="stylesheet">`
|
||||
<link href="${base_url}${print_css}" rel="stylesheet">`
|
||||
);
|
||||
|
||||
if (frappe.utils.is_rtl(this.lang_code)) {
|
||||
let rtl_css = frappe.assets.bundled_asset('frappe-rtl.bundle.css');
|
||||
this.$print_format_body.find('head').append(
|
||||
`<link type="text/css" rel="stylesheet" href="${frappe.urllib.get_base_url()}/assets/frappe/dist/css/frappe-rtl.bundle.css"></link>`
|
||||
`<link type="text/css" rel="stylesheet" href="${base_url}${rtl_css}"></link>`
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
<title>{{ title }}</title>
|
||||
<link href="{{ base_url }}/assets/frappe/dist/css/print.bundle.css" rel="stylesheet">
|
||||
<link href="{{ base_url }}{{ frappe.assets.bundled_asset('print.bundle.css') }}" rel="stylesheet">
|
||||
<style>
|
||||
{{ print_css }}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ import "./frappe/utils/user.js";
|
|||
import "./frappe/utils/common.js";
|
||||
import "./frappe/utils/urllib.js";
|
||||
import "./frappe/utils/pretty_date.js";
|
||||
import "./frappe/utils/test_utils.js";
|
||||
import "./frappe/utils/tools.js";
|
||||
import "./frappe/utils/datetime.js";
|
||||
import "./frappe/utils/number_format.js";
|
||||
|
|
|
|||
|
|
@ -9,12 +9,7 @@ frappe.require = function(items, callback) {
|
|||
if(typeof items === "string") {
|
||||
items = [items];
|
||||
}
|
||||
items = items.map(item => {
|
||||
if (!item.startsWith('/assets') && item.includes('.bundle.')) {
|
||||
return frappe.boot.assets_json[item] || item;
|
||||
}
|
||||
return item;
|
||||
});
|
||||
items = items.map(item => frappe.assets.bundled_asset(item));
|
||||
|
||||
return new Promise(resolve => {
|
||||
frappe.assets.execute(items, () => {
|
||||
|
|
@ -172,4 +167,11 @@ frappe.assets = {
|
|||
frappe.dom.set_style(txt);
|
||||
}
|
||||
},
|
||||
|
||||
bundled_asset(path) {
|
||||
if (!path.startsWith('/assets') && path.includes('.bundle.')) {
|
||||
return frappe.boot.assets_json[path] || path;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ frappe.barcode.scan_barcode = function() {
|
|||
}
|
||||
}, reject);
|
||||
} else {
|
||||
frappe.require('/assets/frappe/dist/js/barcode_scanner.bundle.js', () => {
|
||||
frappe.require('barcode_scanner.bundle.js', () => {
|
||||
frappe.barcode.get_barcode().then(barcode => {
|
||||
resolve(barcode);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -491,7 +491,7 @@ frappe.Application = class Application {
|
|||
var ls = document.createElement('link');
|
||||
ls.rel="stylesheet";
|
||||
ls.type = "text/css";
|
||||
ls.href= "/assets/frappe/dist/css/frappe-rtl.bundle.css";
|
||||
ls.href= frappe.assets.bundled_asset("frappe-rtl.bundle.css");
|
||||
document.getElementsByTagName('head')[0].appendChild(ls);
|
||||
$('body').addClass('frappe-rtl');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Razorpay Payment
|
||||
|
||||
1. Include checkout script in your code
|
||||
<script type="text/javascript" src="/assets/frappe/dist/js/checkout.bundle.js"></script>
|
||||
{{ include_script('checkout.bundle.js) }}
|
||||
|
||||
2. Create the Order controller in your backend
|
||||
def get_razorpay_order(self):
|
||||
|
|
|
|||
|
|
@ -71,19 +71,20 @@ def web_blocks(blocks):
|
|||
|
||||
|
||||
def include_script(path):
|
||||
if not path.startswith("/assets") and ".bundle." in path:
|
||||
path = bundled_asset_path(path)
|
||||
path = bundled_asset(path)
|
||||
return f'<script type="text/javascript" src="{path}"></script>'
|
||||
|
||||
|
||||
def include_style(path):
|
||||
if not path.startswith("/assets") and ".bundle." in path:
|
||||
path = bundled_asset_path(path)
|
||||
path = bundled_asset(path)
|
||||
return f'<link type="text/css" rel="stylesheet" href="{path}">'
|
||||
|
||||
|
||||
def bundled_asset_path(path):
|
||||
def bundled_asset(path):
|
||||
from frappe.utils import get_assets_json
|
||||
|
||||
if path.startswith("/assets") and ".bundle." not in path:
|
||||
return path
|
||||
|
||||
bundled_assets = get_assets_json()
|
||||
return bundled_assets.get(path)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ from PyPDF2 import PdfFileReader, PdfFileWriter
|
|||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import scrub_urls
|
||||
|
||||
from frappe.utils.jinja_globals import bundled_asset
|
||||
|
||||
PDF_CONTENT_ERRORS = ["ContentNotFoundError", "ContentOperationNotPermittedError",
|
||||
"UnknownContentError", "RemoteHostClosedError"]
|
||||
|
|
@ -164,7 +164,8 @@ def prepare_header_footer(soup):
|
|||
head = soup.find("head").contents
|
||||
styles = soup.find_all("style")
|
||||
|
||||
css = frappe.read_file(os.path.join(frappe.local.sites_path, "assets/frappe/dist/css/print.bundle.css"))
|
||||
print_css = bundled_asset('print.bundle.css').lstrip('/')
|
||||
css = frappe.read_file(os.path.join(frappe.local.sites_path, print_css))
|
||||
|
||||
# extract header and footer
|
||||
for html_id in ("header-html", "footer-html"):
|
||||
|
|
|
|||
|
|
@ -87,17 +87,17 @@ $(".file-size").each(function() {
|
|||
$(this).text(frappe.form.formatters.FileSize($(this).text()));
|
||||
});
|
||||
</script>
|
||||
<script type="text/javascript" src="/assets/frappe/dist/js/controls.bundle.js"></script>
|
||||
{{ include_script("controls.bundle.js") }}
|
||||
{% if is_list %}
|
||||
{# web form list #}
|
||||
<script type="text/javascript" src="/assets/frappe/node_modules/moment/min/moment-with-locales.min.js"></script>
|
||||
<script type="text/javascript" src="/assets/frappe/node_modules/moment-timezone/builds/moment-timezone-with-data.min.js"></script>
|
||||
<script type="text/javascript" src="/assets/frappe/dist/js/dialog.bundle.js"></script>
|
||||
<script type="text/javascript" src="/assets/frappe/dist/js/web_form.bundle.js"></script>
|
||||
<script type="text/javascript" src="/assets/frappe/dist/js/bootstrap-4-web.bundle.js"></script>
|
||||
{{ include_script("dialog.bundle.js") }}
|
||||
{{ include_script("web_form.bundle.js") }}
|
||||
{{ include_script("bootstrap-4-web.bundle.js") }}
|
||||
{% else %}
|
||||
{# web form #}
|
||||
<script type="text/javascript" src="/assets/frappe/dist/js/dialog.bundle.js"></script>
|
||||
{{ include_script("dialog.bundle.js") }}
|
||||
<script type="text/javascript" src="/assets/frappe/node_modules/moment/min/moment-with-locales.min.js"></script>
|
||||
<script type="text/javascript" src="/assets/frappe/node_modules/moment-timezone/builds/moment-timezone-with-data.min.js"></script>
|
||||
<script type="text/javascript" src="/assets/frappe/node_modules/vue/dist/vue.js"></script>
|
||||
|
|
@ -105,8 +105,8 @@ $(".file-size").each(function() {
|
|||
Vue.prototype.__ = window.__;
|
||||
Vue.prototype.frappe = window.frappe;
|
||||
</script>
|
||||
<script type="text/javascript" src="/assets/frappe/dist/js/web_form.bundle.js"></script>
|
||||
<script type="text/javascript" src="/assets/frappe/dist/js/bootstrap-4-web.bundle.js"></script>
|
||||
{{ include_script("web_form.bundle.js") }}
|
||||
{{ include_script("bootstrap-4-web.bundle.js") }}
|
||||
<script>
|
||||
|
||||
{% if client_script %}
|
||||
|
|
@ -129,7 +129,7 @@ frappe.init_client_script = () => {
|
|||
|
||||
{% block style %}
|
||||
{% if not is_list %}
|
||||
<link type="text/css" rel="stylesheet" href="/assets/frappe/dist/css/web_form.bundle.css">
|
||||
{{ include_style('web_form.bundle.css') }}
|
||||
{% endif %}
|
||||
|
||||
<style>
|
||||
|
|
|
|||
|
|
@ -637,10 +637,10 @@ frappe.ready(function() {
|
|||
frappe.require([
|
||||
"/assets/frappe/node_modules/moment/min/moment-with-locales.min.js",
|
||||
"/assets/frappe/node_modules/moment-timezone/builds/moment-timezone-with-data.min.js",
|
||||
"/assets/frappe/dist/less/chat.bundle.css",
|
||||
"chat.bundle.css",
|
||||
"/assets/frappe/js/lib/socket.io.min.js"
|
||||
], () => {
|
||||
frappe.require('/assets/frappe/dist/js/chat.bundle.js', () => {
|
||||
frappe.require('chat.bundle.js', () => {
|
||||
frappe.chat.setup();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{ title }}</title>
|
||||
<meta name="generator" content="frappe">
|
||||
<link type="text/css" rel="stylesheet" href="/assets/frappe/dist/css/print.bundle.css">
|
||||
{{ include_style('print.bundle.css') }}
|
||||
{%- if has_rtl -%}
|
||||
<link type="text/css" rel="stylesheet" href="/assets/frappe/dist/css/frappe-rtl.bundle.css">
|
||||
{{ include_style('frappe-rtl.bundle.css') }}
|
||||
{%- endif -%}
|
||||
<style>
|
||||
{{ css }}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue