diff --git a/blender_cloud/pillar.py b/blender_cloud/pillar.py index cb8e741..8a13620 100644 --- a/blender_cloud/pillar.py +++ b/blender_cloud/pillar.py @@ -17,6 +17,7 @@ # ##### END GPL LICENSE BLOCK ##### import asyncio +import datetime import json import os import functools @@ -37,6 +38,8 @@ from . import cache SUBCLIENT_ID = 'PILLAR' TEXTURE_NODE_TYPES = {'texture', 'hdri', 'HDRI_FILE'} +RFC1123_DATE_FORMAT = '%a, %d %b %Y %H:%M:%S GMT' + _pillar_api = {} # will become a mapping from bool (cached/non-cached) to pillarsdk.Api objects. log = logging.getLogger(__name__) uncached_session = requests.session() @@ -856,3 +859,21 @@ async def attach_file_to_group(file_path: pathlib.Path, extra_where=user_id and {'user': user_id}) return node + + +def node_to_id(node: pillarsdk.Node) -> dict: + """Converts a Node to a dict we can store in an ID property. + + ID properties only support a handful of Python classes, so we have + to convert datetime.datetime to a string and remove None values. + """ + + def to_rna(value): + if isinstance(value, dict): + return {k: to_rna(v) for k, v in value.items()} + if isinstance(value, datetime.datetime): + return value.strftime(RFC1123_DATE_FORMAT) + return value + + as_dict = to_rna(node.to_dict()) + return pillarsdk.utils.remove_none_attributes(as_dict) diff --git a/blender_cloud/texture_browser.py b/blender_cloud/texture_browser.py index 760136a..4759752 100644 --- a/blender_cloud/texture_browser.py +++ b/blender_cloud/texture_browser.py @@ -816,10 +816,17 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin, def texture_downloaded(file_path, file_desc, *args): nonlocal select_dblock + node = item.node + if isinstance(node, HdriFileNode): + # We want to obtain the real node, not the fake one. + node = self.menu_item_stack[-1].node + self.log.info('Texture downloaded to %r.', file_path) image_dblock = bpy.data.images.load(filepath=file_path) image_dblock['bcloud_file_uuid'] = file_desc['_id'] - image_dblock['bcloud_texture_node_uuid'] = item.node_uuid + image_dblock['bcloud_node_uuid'] = node['_id'] + image_dblock['bcloud_node_type'] = node.node_type + image_dblock['bcloud_node'] = pillar.node_to_id(node) # Select the image in the image editor (if the context is right). # Just set the first image we download,