Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVilém Duha <vilda.novak@gmail.com>2020-12-30 16:23:06 +0300
committerVilém Duha <vilda.novak@gmail.com>2020-12-30 16:23:06 +0300
commit18b70f2fe4d06d52f8c1e7d35b272c52adea58aa (patch)
treec1b40060602c1475fd8e736b8c97a0fd224dae7b /blenderkit
parenteb514f2106defdccb0f6d4ce8ae8a254b23b844c (diff)
BlenderKit: upload displayName
This enables 2 names for assets - displayName is shown to user, but name is the one saved in the assets. 90% of time these will be the same, but when a user only updates the name of the asset, there is no more need to reupload because the name needed to be the same in the .blend file. also rename draw_callback_2d_search to draw_asset_bar
Diffstat (limited to 'blenderkit')
-rw-r--r--blenderkit/search.py2
-rw-r--r--blenderkit/tasks_queue.py4
-rw-r--r--blenderkit/ui.py6
-rw-r--r--blenderkit/ui_panels.py5
-rw-r--r--blenderkit/upload.py44
5 files changed, 43 insertions, 18 deletions
diff --git a/blenderkit/search.py b/blenderkit/search.py
index c24300ea..738582e6 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 b6f45f3e..3fd4d285 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 620df5f8..d2c28237 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 daa88f82..6cccf42a 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 fd17b7a5..9d9303a9 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: