diff --git a/blenderkit/search.py b/blenderkit/search.py index c24300ead45803028b8b114991b94ca2e1a67536..738582e66445541320e5a7309fcd7e0eefcb37ed 100644 --- a/blenderkit/search.py +++ b/blenderkit/search.py @@ -562,7 +562,7 @@ def generate_tooltip(mdata): else: mparams = mdata['parameters'] t = '' - t = writeblock(t, mdata['name'], width=col_w) + t = writeblock(t, mdata['displayName'], width=col_w) t += '\n' t = writeblockm(t, mdata, key='description', pretext='', width=col_w) diff --git a/blenderkit/tasks_queue.py b/blenderkit/tasks_queue.py index b6f45f3e5d776ebc3f36de0321efea971e814c29..3fd4d285f4252857bfac274561b46a7bde14d5df 100644 --- a/blenderkit/tasks_queue.py +++ b/blenderkit/tasks_queue.py @@ -108,7 +108,9 @@ def queue_worker(): else: task.command(*task.arguments) except Exception as e: - bk_logger.error('task queue failed task:'+ str(e)) + bk_logger.error('task queue failed task:'+ str(task.command)+str(task.arguments)+ str(e)) + # bk_logger.exception('Got exception on main handler') + # raise # print('queue while 2') for task in back_to_queue: q.put(task) diff --git a/blenderkit/ui.py b/blenderkit/ui.py index 620df5f867bec066eae8ffce6da35837552e1205..d2c282370e384c703de0af6a9ee97b50e6371e87 100644 --- a/blenderkit/ui.py +++ b/blenderkit/ui.py @@ -566,7 +566,7 @@ def draw_callback_2d(self, context): props = context.scene.blenderkitUI if props.down_up == 'SEARCH': draw_ratings_bgl() - draw_callback_2d_search(self, context) + draw_asset_bar(self, context) elif props.down_up == 'UPLOAD': draw_callback_2d_upload_preview(self, context) @@ -693,7 +693,7 @@ def is_upload_old(asset_data): return 0 -def draw_callback_2d_search(self, context): +def draw_asset_bar(self, context): s = bpy.context.scene ui_props = context.scene.blenderkitUI user_preferences = bpy.context.preferences.addons['blenderkit'].preferences @@ -1330,7 +1330,7 @@ class AssetBarOperator(bpy.types.Operator): or ui_props.asset_type == 'MATERIAL' and ao != None and ao.active_material != None \ or ui_props.asset_type == 'BRUSH' and utils.get_active_brush() is not None \ or ui_props.asset_type == 'SCENE' or ui_props.asset_type == 'HDR': - export_data, upload_data = upload.get_upload_data(self, context, ui_props.asset_type) + export_data, upload_data = upload.get_upload_data(context=context, asset_type=ui_props.asset_type) if upload_data: ui_props.tooltip = search.generate_tooltip(upload_data) diff --git a/blenderkit/ui_panels.py b/blenderkit/ui_panels.py index daa88f82ffc24a3c44329fd520c31897bd94a6d5..6cccf42ad9053ee7cd9ac52bc8f05b49b8190de5 100644 --- a/blenderkit/ui_panels.py +++ b/blenderkit/ui_panels.py @@ -122,6 +122,11 @@ def draw_upload_common(layout, props, asset_type, context): optext = 'Upload %s' % asset_type.lower() op = layout.operator("object.blenderkit_upload", text=optext, icon='EXPORT') op.asset_type = asset_type + op.reupload = False + #make sure everything gets uploaded. + op.main_file = True + op.metadata = True + op.thumbnail = True if props.asset_base_id != '': op = layout.operator("object.blenderkit_upload", text='Reupload asset', icon='EXPORT') diff --git a/blenderkit/upload.py b/blenderkit/upload.py index fd17b7a505602eb57b834c50f7a57fdc3d10a724..9d9303a9f8b9dc4d3cf99fb088c29beb070ee0c6 100644 --- a/blenderkit/upload.py +++ b/blenderkit/upload.py @@ -161,14 +161,14 @@ def camel_to_sub(content): return replaced -def get_upload_data(self, context, asset_type): +def get_upload_data(caller = None, context = None, asset_type = None): ''' works though metadata from addom props and prepares it for upload to dicts. Parameters ---------- - self - context - asset_type + caller - upload operator or none + context - context + asset_type - asset type in capitals (blender enum) Returns ------- @@ -482,7 +482,13 @@ def get_upload_data(self, context, asset_type): add_version(upload_data) - upload_data["name"] = props.name + # caller can be upload operator, but also asset bar called from tooltip generator + if caller and caller.main_file == True: + upload_data["name"] = props.name + upload_data["displayName"] = props.name + else: + upload_data["displayName"] = props.name + upload_data["description"] = props.description upload_data["tags"] = comma2array(props.tags) #category is always only one value by a slug, that's why we go down to the lowest level and overwrite. @@ -511,6 +517,16 @@ def get_upload_data(self, context, asset_type): return export_data, upload_data +def patch_individual_metadata(asset_id, metadata_dict, api_key): + upload_data = metadata_dict + url = paths.get_api_url() + 'assets/' + str(asset_id) + '/' + headers = utils.get_headers(api_key) + try: + r = rerequests.patch(url, json=upload_data, headers=headers, verify=True) # files = files, + except requests.exceptions.RequestException as e: + print(e) + return {'CANCELLED'} + return {'FINISHED'} def category_change_thread(asset_id, category, api_key): upload_data = { @@ -964,7 +980,6 @@ def start_upload(self, context, asset_type, reupload, upload_set): # do this for fixing long tags in some upload cases props.tags = props.tags[:] - props.name = props.name.strip() # check for missing metadata check_missing_data(asset_type, props) @@ -977,7 +992,7 @@ def start_upload(self, context, asset_type, reupload, upload_set): props.asset_base_id = '' props.id = '' - export_data, upload_data = get_upload_data(self, context, asset_type) + export_data, upload_data = get_upload_data(caller = self, context = context, asset_type = asset_type) # print(export_data) # print(upload_data) # check if thumbnail exists, generate for HDR: @@ -989,7 +1004,10 @@ def start_upload(self, context, asset_type, reupload, upload_set): props.uploading = False return {'CANCELLED'} - props.upload_state = "Starting upload. Please don't close Blender until upload finishes" + if upload_set == {'METADATA'}: + props.upload_state = "Updating metadata. Please don't close Blender until upload finishes" + else: + props.upload_state = "Starting upload. Please don't close Blender until upload finishes" props.uploading = True @@ -1075,11 +1093,11 @@ class UploadOperator(Operator): # in case of name change, we have to reupload everything, since the name is stored in blender file, # and is used for linking to scene - if props.name_changed: - # TODO: this needs to be replaced with new double naming scheme (metadata vs blend data) - # print('has to reupload whole data, name has changed.') - self.main_file = True - props.name_changed = False + # if props.name_changed: + # # TODO: this needs to be replaced with new double naming scheme (metadata vs blend data) + # # print('has to reupload whole data, name has changed.') + # self.main_file = True + # props.name_changed = False upload_set = [] if not self.reupload: