fix: Load and save base64 image in publish
This commit is contained in:
parent
5689494f9c
commit
811a2deb0f
@ -81,13 +81,14 @@ def publish_selected_items(items_to_publish):
|
|||||||
'item_code': item_code,
|
'item_code': item_code,
|
||||||
'hub_category': item.get('hub_category'),
|
'hub_category': item.get('hub_category'),
|
||||||
'image_list': item.get('image_list')
|
'image_list': item.get('image_list')
|
||||||
}).insert()
|
}).insert(ignore_if_duplicate=True)
|
||||||
|
|
||||||
|
|
||||||
items = map_fields(items_to_publish)
|
items = map_fields(items_to_publish)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
item_sync_preprocess()
|
item_sync_preprocess()
|
||||||
|
load_base64_image_from_items(items)
|
||||||
|
|
||||||
# TODO: Publish Progress
|
# TODO: Publish Progress
|
||||||
connection = get_hub_connection()
|
connection = get_hub_connection()
|
||||||
@ -97,10 +98,8 @@ def publish_selected_items(items_to_publish):
|
|||||||
'status': 'Success',
|
'status': 'Success',
|
||||||
'stats': len(items)
|
'stats': len(items)
|
||||||
})
|
})
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
frappe.db.set_value("Hub Settings", "Hub Settings", "sync_in_progress", 0)
|
frappe.log_error(title='Hub Sync Error')
|
||||||
frappe.throw(e)
|
|
||||||
|
|
||||||
def item_sync_preprocess():
|
def item_sync_preprocess():
|
||||||
hub_seller = frappe.db.get_value("Hub Settings", "Hub Settings", "company_email")
|
hub_seller = frappe.db.get_value("Hub Settings", "Hub Settings", "company_email")
|
||||||
@ -137,6 +136,31 @@ def item_sync_postprocess(sync_details):
|
|||||||
|
|
||||||
frappe.db.set_value('Hub Settings', 'Hub Settings', 'sync_in_progress', 0)
|
frappe.db.set_value('Hub Settings', 'Hub Settings', 'sync_in_progress', 0)
|
||||||
|
|
||||||
|
|
||||||
|
def load_base64_image_from_items(items):
|
||||||
|
import io, base64, urllib, os
|
||||||
|
from frappe.utils.file_manager import get_file_path
|
||||||
|
|
||||||
|
for item in items:
|
||||||
|
file_path = item['image']
|
||||||
|
file_name = os.path.basename(file_path)
|
||||||
|
|
||||||
|
if file_path.startswith('http'):
|
||||||
|
url = file_path
|
||||||
|
file_path = os.path.join('/tmp', file_name)
|
||||||
|
urllib.urlretrieve(url, file_path)
|
||||||
|
else:
|
||||||
|
file_path = os.path.abspath(get_file_path(file_path))
|
||||||
|
|
||||||
|
with io.open(file_path, 'rb') as f:
|
||||||
|
image_data = json.dumps({
|
||||||
|
'file_name': file_name,
|
||||||
|
'base64': base64.b64encode(f.read())
|
||||||
|
})
|
||||||
|
|
||||||
|
item['image'] = image_data
|
||||||
|
|
||||||
|
|
||||||
def get_hub_connection():
|
def get_hub_connection():
|
||||||
if frappe.db.exists('Data Migration Connector', 'Hub Connector'):
|
if frappe.db.exists('Data Migration Connector', 'Hub Connector'):
|
||||||
hub_connector = frappe.get_doc('Data Migration Connector', 'Hub Connector')
|
hub_connector = frappe.get_doc('Data Migration Connector', 'Hub Connector')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user