Added hospital image
This commit is contained in:
parent
bcdf8526d0
commit
67e63c3ad2
@ -15,7 +15,12 @@ DEFAULT_PRINT_FORMAT = "Service Report"
|
|||||||
DEFAULT_KK_PRINT_FORMAT = "Service Report(KK)"
|
DEFAULT_KK_PRINT_FORMAT = "Service Report(KK)"
|
||||||
|
|
||||||
# Naming Series Defaults
|
# Naming Series Defaults
|
||||||
DEFAULT_ASSET_NAMING_SERIES = "ASM-KFSH-.YYYY.-"
|
DEFAULT_ASSET_NAMING_SERIES = "ASM-HOSP-.YYYY.-"
|
||||||
|
|
||||||
|
|
||||||
|
# Logos
|
||||||
|
DEFAULT_HOSPITAL_LOGO = "/files/hospital.png"
|
||||||
|
DEFAULT_CLUSTER_LOGO = "/files/hospital.png"
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist(allow_guest=False)
|
@frappe.whitelist(allow_guest=False)
|
||||||
@ -39,4 +44,8 @@ def get_app_defaults():
|
|||||||
"DEFAULT_HOSPITAL_ABBR": DEFAULT_HOSPITAL_ABBR,
|
"DEFAULT_HOSPITAL_ABBR": DEFAULT_HOSPITAL_ABBR,
|
||||||
"DEFAULT_PRINT_FORMAT": DEFAULT_PRINT_FORMAT,
|
"DEFAULT_PRINT_FORMAT": DEFAULT_PRINT_FORMAT,
|
||||||
"DEFAULT_ASSET_NAMING_SERIES": DEFAULT_ASSET_NAMING_SERIES,
|
"DEFAULT_ASSET_NAMING_SERIES": DEFAULT_ASSET_NAMING_SERIES,
|
||||||
|
"DEFAULT_HOSPITAL_LOGO": DEFAULT_HOSPITAL_LOGO,
|
||||||
|
"DEFAULT_CLUSTER_LOGO": DEFAULT_CLUSTER_LOGO,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -89,7 +89,8 @@ on_session_creation = "asset_lite.api.api.set_default_homepage"
|
|||||||
# ------------
|
# ------------
|
||||||
|
|
||||||
# before_install = "asset_lite.install.before_install"
|
# before_install = "asset_lite.install.before_install"
|
||||||
# after_install = "asset_lite.install.after_install"
|
after_install = "asset_lite.install.after_install"
|
||||||
|
after_migrate = "asset_lite.install.after_migrate"
|
||||||
|
|
||||||
# Uninstallation
|
# Uninstallation
|
||||||
# ------------
|
# ------------
|
||||||
|
|||||||
60
asset_lite/install.py
Normal file
60
asset_lite/install.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import os
|
||||||
|
import frappe
|
||||||
|
|
||||||
|
|
||||||
|
def after_install():
|
||||||
|
"""Executed after the app is installed on a site."""
|
||||||
|
setup_default_files()
|
||||||
|
|
||||||
|
|
||||||
|
def after_migrate():
|
||||||
|
"""Executed after 'bench migrate' is run on a site."""
|
||||||
|
setup_default_files()
|
||||||
|
|
||||||
|
|
||||||
|
def setup_default_files():
|
||||||
|
"""Ensure default app assets (e.g., hospital.png) are added to the Frappe File DocType.
|
||||||
|
|
||||||
|
This makes the image available at '/files/hospital.png' and visible in Desk File List.
|
||||||
|
"""
|
||||||
|
files_to_setup = [
|
||||||
|
{
|
||||||
|
"file_name": "hospital.png",
|
||||||
|
"relative_path": ["public", "images", "hospital.png"],
|
||||||
|
"is_private": 0,
|
||||||
|
"folder": "Home",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
for item in files_to_setup:
|
||||||
|
file_name = item["file_name"]
|
||||||
|
|
||||||
|
# 1. Check if the file already exists in File DocType
|
||||||
|
if frappe.db.exists("File", {"file_name": file_name}) or frappe.db.exists("File", {"file_url": f"/files/{file_name}"}):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 2. Locate the source file in app directory
|
||||||
|
source_path = frappe.get_app_path("asset_lite", *item["relative_path"])
|
||||||
|
if not os.path.exists(source_path):
|
||||||
|
frappe.logger().warning(f"[asset_lite] Source file not found for default file setup: {source_path}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 3. Read binary content
|
||||||
|
with open(source_path, "rb") as f:
|
||||||
|
file_content = f.read()
|
||||||
|
|
||||||
|
# 4. Create Frappe File document
|
||||||
|
# Setting is_private=0 and providing content automatically writes to sites/<site>/public/files/<file_name>
|
||||||
|
try:
|
||||||
|
file_doc = frappe.get_doc({
|
||||||
|
"doctype": "File",
|
||||||
|
"file_name": file_name,
|
||||||
|
"content": file_content,
|
||||||
|
"is_private": item.get("is_private", 0),
|
||||||
|
"folder": item.get("folder", "Home"),
|
||||||
|
})
|
||||||
|
file_doc.insert(ignore_permissions=True)
|
||||||
|
frappe.db.commit()
|
||||||
|
frappe.logger().info(f"[asset_lite] Successfully added default file '{file_name}' to File DocType.")
|
||||||
|
except Exception as e:
|
||||||
|
frappe.logger().error(f"[asset_lite] Failed to add default file '{file_name}' to File DocType: {e}")
|
||||||
BIN
asset_lite/public/images/hospital.png
Normal file
BIN
asset_lite/public/images/hospital.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
Loading…
x
Reference in New Issue
Block a user