Added defaults

This commit is contained in:
Duradundi 2026-09-10 18:20:36 +05:30
parent 849a8c46e1
commit 8ac9bfb78a
4 changed files with 4622 additions and 4561 deletions

File diff suppressed because it is too large Load Diff

View File

@ -89,7 +89,8 @@ on_session_creation = "asset_lite.api.api.set_default_homepage"
# ------------
# 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
# ------------

60
asset_lite/install.py Normal file
View 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}")

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB