[Bf-extensions-cvs] [30660b7d] master: BlenderKit: upload reworked. Don't save .blend file , some users didn't like this. Re-upload enables only thumbnail updates. Mark for validation operator removed(was removed from UI several versions ago) ModelUploadOperator renamed to UploadOperator, since it's used for all asset types anyway. Skip .blend preparation in case of thumbnail reupload only

Vilém Duha noreply at git.blender.org
Mon Aug 12 16:05:28 CEST 2019


Commit: 30660b7d903a3fcd326c7238dced696e5029e500
Author: Vilém Duha
Date:   Sat Aug 10 23:37:57 2019 +0200
Branches: master
https://developer.blender.org/rBA30660b7d903a3fcd326c7238dced696e5029e500

BlenderKit: upload reworked.
Don't save .blend file , some users didn't like this.
Re-upload enables only thumbnail updates.
Mark for validation operator removed(was removed from UI several versions ago)
ModelUploadOperator renamed to UploadOperator, since it's used for all asset types anyway.
Skip .blend preparation in case of thumbnail reupload only

===================================================================

M	blenderkit/ui_panels.py
M	blenderkit/upload.py
M	blenderkit/upload_bg.py

===================================================================

diff --git a/blenderkit/ui_panels.py b/blenderkit/ui_panels.py
index ef95665b..c6ef9d29 100644
--- a/blenderkit/ui_panels.py
+++ b/blenderkit/ui_panels.py
@@ -110,27 +110,27 @@ def draw_upload_common(layout, props, asset_type, context):
 
     if props.asset_base_id == '':
         optext = 'Upload %s' % asset_type.lower()
-    else:
-        optext = 'Reupload %s (with thumbnail)' % asset_type.lower()
-
-    op = layout.operator("object.blenderkit_upload", text=optext, icon='EXPORT')
-    op.asset_type = asset_type
-    op.as_new = False
+        op = layout.operator("object.blenderkit_upload", text=optext, icon='EXPORT')
+        op.asset_type = asset_type
 
     if props.asset_base_id != '':
-        op = layout.operator("object.blenderkit_upload", text='Reupload only metadata', icon='EXPORT')
+
+        op = layout.operator("object.blenderkit_upload", text='Reupload asset', icon='EXPORT')
         op.asset_type = asset_type
-        op.metadata_only = True
+        op.reupload = True
+
 
         op = layout.operator("object.blenderkit_upload", text='Upload as new asset', icon='EXPORT')
         op.asset_type = asset_type
-        op.as_new = True
-        # layout.label(text = 'asset id, overwrite only for reuploading')
-        if props.asset_base_id != '':
-            row = layout.row()
+        op.reupload = False
 
-            row.prop(props, 'asset_base_id', icon='FILE_TICK')
-        # layout.operator("object.blenderkit_mark_for_validation", icon='EXPORT')
+        # layout.label(text = 'asset id, overwrite only for reuploading')
+        row = layout.row()
+        row.enabled = False
+        row.prop(props, 'asset_base_id', icon='FILE_TICK')
+        row = layout.row()
+        row.enabled = False
+        row.prop(props, 'id', icon='FILE_TICK')
 
     layout.prop(props, 'category')
     if asset_type == 'MODEL' and props.subcategory != '':  # by now block this for other asset types.
diff --git a/blenderkit/upload.py b/blenderkit/upload.py
index 9d338803..e8183684 100644
--- a/blenderkit/upload.py
+++ b/blenderkit/upload.py
@@ -537,7 +537,7 @@ def auto_fix(asset_type=''):
         asset.name = props.name
 
 
-def start_upload(self, context, asset_type, as_new, metadata_only):
+def start_upload(self, context, asset_type, reupload, upload_set):
     '''start upload process, by processing data'''
     props = utils.get_upload_props()
     storage_quota_ok = check_storage_quota(props)
@@ -569,7 +569,7 @@ def start_upload(self, context, asset_type, as_new, metadata_only):
         self.report({'ERROR_INVALID_INPUT'}, props.report)
         return {'CANCELLED'}
 
-    if as_new:
+    if not reupload:
         props.asset_base_id = ''
         props.id = ''
     export_data, upload_data, eval_path_computing, eval_path_state, eval_path, props = get_upload_data(self, context,
@@ -595,11 +595,12 @@ def start_upload(self, context, asset_type, as_new, metadata_only):
         'export_data': export_data,
         'upload_data': upload_data,
         'debug_value': bpy.app.debug_value,
+        'upload_set': upload_set,
     }
     datafile = os.path.join(tempdir, BLENDERKIT_EXPORT_DATA_FILE)
 
     # check if thumbnail exists:
-    if not metadata_only:
+    if 'THUMBNAIL' in upload_set:
         if not os.path.exists(export_data["thumbnail_path"]):
             props.upload_state = 'Thumbnail not found'
             props.uploading = False
@@ -616,7 +617,7 @@ def start_upload(self, context, asset_type, as_new, metadata_only):
     if props.asset_base_id == '':
         try:
             r = requests.post(url, json=json_metadata, headers=headers, verify=True)  # files = files,
-            props.upload_state = 'uploaded metadata'
+            ui.add_report('uploaded metadata')
             utils.p(r.text)
         except requests.exceptions.RequestException as e:
             print(e)
@@ -627,10 +628,10 @@ def start_upload(self, context, asset_type, as_new, metadata_only):
     else:
         url += props.id + '/'
         try:
-            if not metadata_only:
+            if upload_set != ['METADATA']:
                 json_metadata["verificationStatus"] = "uploading"
             r = requests.put(url, json=json_metadata, headers=headers, verify=True)  # files = files,
-            props.upload_state = 'uploaded metadata'
+            ui.add_report('uploaded metadata')
             # parse the request
             # print('uploaded metadata')
             # print(r.text)
@@ -641,7 +642,7 @@ def start_upload(self, context, asset_type, as_new, metadata_only):
             return {'CANCELLED'}
 
     # props.upload_state = 'step 1'
-    if metadata_only:
+    if upload_set == ['METADATA']:
         props.uploading = False
 
         return {'FINISHED'}
@@ -658,7 +659,9 @@ def start_upload(self, context, asset_type, as_new, metadata_only):
         upload_data['assetBaseId'] = props.asset_base_id
         upload_data['id'] = props.id
 
-        bpy.ops.wm.save_mainfile()
+        # bpy.ops.wm.save_mainfile()
+        # bpy.ops.wm.save_as_mainfile(filepath=filepath, compress=False, copy=True)
+
         props.uploading = True
         # save a copy of actual scene but don't interfere with the users models
         bpy.ops.wm.save_as_mainfile(filepath=source_filepath, compress=False, copy=True)
@@ -697,7 +700,7 @@ asset_types = (
 )
 
 
-class ModelUploadOperator(Operator):
+class UploadOperator(Operator):
     """Tooltip"""
     bl_idname = "object.blenderkit_upload"
     bl_description = "Upload or re-upload asset + thumbnail + metadata"
@@ -712,16 +715,27 @@ class ModelUploadOperator(Operator):
         default="MODEL",
     )
 
-    as_new: BoolProperty(
-        name="upload as new",
-        description="deletes asset id and uploads as new file",
+    reupload: BoolProperty(
+        name="reupload",
+        description="reupload but also draw so that it asks what to reupload",
+        default=False,
+        options={'SKIP_SAVE'}
+    )
+
+    metadata: BoolProperty(
+        name="metadata",
+        default=True,
+        options={'SKIP_SAVE'}
+    )
+
+    thumbnail: BoolProperty(
+        name="thumbnail",
         default=False,
         options={'SKIP_SAVE'}
     )
 
-    metadata_only: BoolProperty(
-        name="upload metadata",
-        description="update only metadata",
+    main_file: BoolProperty(
+        name="main file",
         default=False,
         options={'SKIP_SAVE'}
     )
@@ -736,13 +750,24 @@ class ModelUploadOperator(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
-        metadata_only = self.metadata_only
         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.metadata_only = False
+            self.main_file = True
             props.name_changed = False
 
-        result = start_upload(self, context, self.asset_type, self.as_new, self.metadata_only)
+        upload_set = []
+        if not self.reupload:
+            upload_set = ['METADATA', 'THUMBNAIL', 'MAINFILE']
+        else:
+            if self.metadata:
+                upload_set.append('METADATA')
+            if self.thumbnail:
+                upload_set.append('THUMBNAIL')
+            if self.main_file:
+                upload_set.append('MAINFILE')
+
+        result = start_upload(self, context, self.asset_type, self.reupload, upload_set)
 
         return result
 
@@ -750,84 +775,32 @@ class ModelUploadOperator(Operator):
         props = utils.get_upload_props()
         layout = self.layout
 
-        if self.as_new:
+        if self.reupload:
+            # layout.prop(self, 'metadata')
+            layout.prop(self, 'main_file')
+            layout.prop(self, 'thumbnail')
+
+        if props.asset_base_id != '' and not self.reupload:
             layout.label(text="Really upload as new? ")
             layout.label(text="Do this only when you create a new asset from an old one.")
             layout.label(text="For updates of thumbnail or model use reupload.")
 
         if props.is_private == 'PUBLIC':
-            ui_panels.label_multiline(layout, text='Since version 1.0.24: '
-                                                   'PUBLIC ASSETS ARE VALIDATED AUTOMATICALLY '
-                                                   ' after upload. '
-                                                   'Click Ok to proceed.')
+            ui_panels.label_multiline(layout, text='public assets are validated several hours'
+                                                   ' or days after upload. ', width = 300)
 
     def invoke(self, context, event):
         props = utils.get_upload_props()
 
-        if self.as_new or props.is_private == 'PUBLIC':
+        if props.is_private == 'PUBLIC':
             return context.window_manager.invoke_props_dialog(self)
         else:
             return self.execute(context)
 
 
-class ModelMarkForValidation(Operator):
-    """Tooltip"""
-    bl_idname = "object.blenderkit_mark_for_validation"
-    bl_description = "After this, model can be validated by our validators and \n then be part of the public database"
-
-    bl_label = "Mark for validation"
-
-    # type of upload - model, material, textures, e.t.c.
-    asset_type: EnumProperty(
-        name="type",
-        items=asset_types,
-        description="Type of upload",
-        default="MODEL",
-    )
-
-    @classmethod
-    def poll(cls, context):
-        props = utils.get_upload_props()
-        return bpy.context.active_object is not None and props.asset_base_id != ''
-
-    def execute(self, context):
-        result = mark_for_validation(self, context, self.asset_type)
-
-        return result
-
-
-# TODO this is for upldating by creators, if they edit metadata on server or want to upload from older file version.
-# class GetMetadataFromServer(Operator):
-#     """Tooltip"""
-#     bl_idname = "object.blenderkit_get_from_server"
-#     bl_description ="After this, model can be validated by our validators and \n then be part of the public database"
-#
-#     

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list