[Bf-extensions-cvs] [168f1442] blender-v2.82-release: BlenderKit: Fix rating updates for panel.
Vilém Duha
noreply at git.blender.org
Thu Feb 6 11:26:12 CET 2020
Commit: 168f14425616fea37529e79e278b9b46b436adfc
Author: Vilém Duha
Date: Fri Jan 31 14:45:46 2020 +0100
Branches: blender-v2.82-release
https://developer.blender.org/rBA168f14425616fea37529e79e278b9b46b436adfc
BlenderKit: Fix rating updates for panel.
Fix a bug in upload when checking image /procedural assets
Fix oauth return values in case of error
Fix fetching of authors through search api instead of profiles.
Fix task_queue with multiple tasks of the same by enabling stashing
Fix selected asset panel, rename it to selected model by now (not supporting other assets now)
===================================================================
M blenderkit/__init__.py
M blenderkit/asset_inspector.py
M blenderkit/oauth.py
M blenderkit/ratings.py
M blenderkit/search.py
M blenderkit/tasks_queue.py
M blenderkit/ui_panels.py
===================================================================
diff --git a/blenderkit/__init__.py b/blenderkit/__init__.py
index bd9f7e3f..9db72bb0 100644
--- a/blenderkit/__init__.py
+++ b/blenderkit/__init__.py
@@ -385,11 +385,13 @@ class BlenderKitUIProps(PropertyGroup):
dragging_rating_work_hours: BoolProperty(name="Dragging Rating Work Hours", default=False)
last_rating_time: FloatProperty(name="Last Rating Time", default=0.0)
-def search_procedural_update(self,context):
+
+def search_procedural_update(self, context):
if self.search_procedural in ('PROCEDURAL', 'BOTH'):
self.search_texture_resolution = False
search.search_update(self, context)
+
class BlenderKitCommonSearchProps(object):
# STATES
is_searching: BoolProperty(name="Searching", description="search is currently running (internal)", default=False)
@@ -645,9 +647,16 @@ class BlenderKitCommonUploadProps(object):
class BlenderKitRatingProps(PropertyGroup):
- rating_quality: IntProperty(name="Quality", description="quality of the material", default=0, min=-1, max=10)
- rating_work_hours: FloatProperty(name="Work Hours", description="How many hours did this work take?", default=0.01,
- min=0.0, max=1000
+ rating_quality: IntProperty(name="Quality",
+ description="quality of the material",
+ default=0,
+ min=-1, max=10,
+ update=ratings.update_ratings_quality)
+
+ rating_work_hours: FloatProperty(name="Work Hours",
+ description="How many hours did this work take?",
+ default=0.01,
+ min=0.0, max=1000, update=ratings.update_ratings_work_hours
)
rating_complexity: IntProperty(name="Complexity",
description="Complexity is a number estimating how much work was spent on the asset.aaa",
diff --git a/blenderkit/asset_inspector.py b/blenderkit/asset_inspector.py
index e6fdc659..0e26479f 100644
--- a/blenderkit/asset_inspector.py
+++ b/blenderkit/asset_inspector.py
@@ -118,9 +118,12 @@ def check_render_engine(props, obs):
if n.type not in shaders:
shaders.append(n.type)
if n.type == 'TEX_IMAGE':
- mattype = 'image based'
- props.is_procedural = False
- if n.image not in textures:
+
+
+ if n.image is not None and n.image not in textures:
+ props.is_procedural = False
+ mattype = 'image based'
+
textures.append(n.image)
props.texture_count += 1
props.total_megapixels += (n.image.size[0] * n.image.size[1])
diff --git a/blenderkit/oauth.py b/blenderkit/oauth.py
index afbd8f65..95c6bae6 100644
--- a/blenderkit/oauth.py
+++ b/blenderkit/oauth.py
@@ -52,7 +52,7 @@ class SimpleOAuthAuthenticator(object):
if response.status_code != 200:
print("error retrieving refresh tokens %s" % response.status_code)
print(response.content)
- return None, None
+ return None, None, None
response_json = json.loads(response.content)
refresh_token = response_json ['refresh_token']
diff --git a/blenderkit/ratings.py b/blenderkit/ratings.py
index 96cbc01f..fdbdea79 100644
--- a/blenderkit/ratings.py
+++ b/blenderkit/ratings.py
@@ -22,8 +22,9 @@ if "bpy" in locals():
paths = reload(paths)
utils = reload(utils)
rerequests = reload(rerequests)
+ tasks_queue = reload(tasks_queue)
else:
- from blenderkit import paths, utils, rerequests
+ from blenderkit import paths, utils, rerequests, tasks_queue
import bpy
import requests, threading
@@ -44,12 +45,7 @@ from bpy.types import (
def pretty_print_POST(req):
"""
- At this point it is completely built and ready
- to be fired; it is "prepared".
-
- However pay attention at the formatting used in
- this function because it is programmed to be pretty
- printed and may differ from the actual request.
+ pretty print a request
"""
print('{}\n{}\n{}\n\n{}'.format(
'-----------START-----------',
@@ -60,6 +56,8 @@ def pretty_print_POST(req):
def uplaod_rating_thread(url, ratings, headers):
+ ''' Upload rating thread function / disconnected from blender data.'''
+ utils.p('upload rating', url, ratings)
for rating_name, score in ratings:
if (score != -1 and score != 0):
rating_url = url + rating_name + '/'
@@ -74,12 +72,26 @@ def uplaod_rating_thread(url, ratings, headers):
print('ratings upload failed: %s' % str(e))
+def send_rating_to_thread_quality(url, ratings, headers):
+ '''Sens rating into thread rating, main purpose is for tasks_queue.
+ One function per property to avoid lost data due to stashing.'''
+ thread = threading.Thread(target=uplaod_rating_thread, args=(url, ratings, headers))
+ thread.start()
+
+def send_rating_to_thread_work_hours(url, ratings, headers):
+ '''Sens rating into thread rating, main purpose is for tasks_queue.
+ One function per property to avoid lost data due to stashing.'''
+ thread = threading.Thread(target=uplaod_rating_thread, args=(url, ratings, headers))
+ thread.start()
+
+
def uplaod_review_thread(url, reviews, headers):
r = rerequests.put(url, data=reviews, verify=True, headers=headers)
# except requests.exceptions.RequestException as e:
# print('reviews upload failed: %s' % str(e))
+
def get_rating(asset_id):
user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
api_key = user_preferences.api_key
@@ -88,11 +100,38 @@ def get_rating(asset_id):
rtypes = ['quality', 'working_hours']
for rt in rtypes:
params = {
- 'rating_type' : rt
+ 'rating_type': rt
}
r = rerequests.get(r1, params=data, verify=True, headers=headers)
print(r.text)
+
+def update_ratings_quality(self, context):
+ user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
+ api_key = user_preferences.api_key
+ headers = utils.get_headers(api_key)
+ asset = self.id_data
+ bkit_ratings = asset.bkit_ratings
+ url = paths.get_api_url() + 'assets/' + asset['asset_data']['id'] + '/rating/'
+
+ if bkit_ratings.rating_quality > 0.1:
+ ratings = [('quality', bkit_ratings.rating_quality)]
+ tasks_queue.add_task((send_rating_to_thread_quality, (url, ratings, headers)), wait=1, only_last=True)
+
+
+def update_ratings_work_hours(self, context):
+ user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
+ api_key = user_preferences.api_key
+ headers = utils.get_headers(api_key)
+ asset = self.id_data
+ bkit_ratings = asset.bkit_ratings
+ url = paths.get_api_url() + 'assets/' + asset['asset_data']['id'] + '/rating/'
+
+ if bkit_ratings.rating_quality > 0.1:
+ ratings = [('working_hours', round(bkit_ratings.rating_work_hours, 1))]
+ tasks_queue.add_task((send_rating_to_thread_work_hours, (url, ratings, headers)), wait=1, only_last=True)
+
+
def upload_rating(asset):
user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
api_key = user_preferences.api_key
@@ -134,8 +173,8 @@ def upload_rating(asset):
class StarRatingOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.blenderkit_rating"
- bl_label = "Rate the Asset"
- bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
+ bl_label = "Rate the Asset Quality"
+ bl_options = {'REGISTER', 'INTERNAL'}
property_name: StringProperty(
name="Rating Property",
@@ -148,7 +187,7 @@ class StarRatingOperator(bpy.types.Operator):
def execute(self, context):
asset = utils.get_active_asset()
props = asset.bkit_ratings
- props[self.property_name] = self.rating
+ props.rating_quality = self.rating
return {'FINISHED'}
@@ -162,6 +201,7 @@ asset_types = (
)
+# TODO drop this operator, not needed anymore.
class UploadRatingOperator(bpy.types.Operator):
"""Upload rating to the web db"""
bl_idname = "object.blenderkit_rating_upload"
@@ -169,12 +209,12 @@ class UploadRatingOperator(bpy.types.Operator):
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
# type of upload - model, material, textures, e.t.c.
- asset_type: EnumProperty(
- name="Type",
- items=asset_types,
- description="Type of asset",
- default="MODEL",
- )
+ # asset_type: EnumProperty(
+ # name="Type",
+ # items=asset_types,
+ # description="Type of asset",
+ # default="MODEL",
+ # )
# @classmethod
# def poll(cls, context):
diff --git a/blenderkit/search.py b/blenderkit/search.py
index 56c22dbb..f5cadaad 100644
--- a/blenderkit/search.py
+++ b/blenderkit/search.py
@@ -244,10 +244,10 @@ def timer_update(): # TODO might get moved to handle all blenderkit stuff.
'tags': r['tags'],
'can_download': r.get('canDownload', True),
'verification_status': r['verificationStatus'],
- 'author_id': str(r['author']['id'])
+ 'author_id': str(r['author']['id']),
# 'author': r['author']['firstName'] + ' ' + r['author']['lastName']
# 'description': r['description'],
- # 'author': r['description'],
+ 'author': r['author'],
}
asset_data['downloaded'] = 0
@@ -504,7 +504,7 @@ def generate_tooltip(mdata):
# t += 'uv: %s\n'
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list