diff --git a/blenderkit/ratings.py b/blenderkit/ratings.py index 10d815ba82122e5e46121c9eb877e9fb066520db..f6a221c4d11a46bd0637b3f2d94e8c860a3a6073 100644 --- a/blenderkit/ratings.py +++ b/blenderkit/ratings.py @@ -50,7 +50,6 @@ def pretty_print_POST(req): )) - def upload_review_thread(url, reviews, headers): r = rerequests.put(url, data=reviews, verify=True, headers=headers) @@ -58,9 +57,6 @@ def upload_review_thread(url, reviews, headers): # print('reviews upload failed: %s' % str(e)) - - - def upload_rating(asset): user_preferences = bpy.context.preferences.addons['blenderkit'].preferences api_key = user_preferences.api_key @@ -76,10 +72,12 @@ def upload_rating(asset): if bkit_ratings.rating_quality > 0.1: ratings = (('quality', bkit_ratings.rating_quality),) - tasks_queue.add_task((ratings_utils.send_rating_to_thread_quality, (url, ratings, headers)), wait=2.5, only_last=True) + tasks_queue.add_task((ratings_utils.send_rating_to_thread_quality, (url, ratings, headers)), wait=2.5, + only_last=True) if bkit_ratings.rating_work_hours > 0.1: ratings = (('working_hours', round(bkit_ratings.rating_work_hours, 1)),) - tasks_queue.add_task((ratings_utils.send_rating_to_thread_work_hours, (url, ratings, headers)), wait=2.5, only_last=True) + tasks_queue.add_task((ratings_utils.send_rating_to_thread_work_hours, (url, ratings, headers)), wait=2.5, + only_last=True) thread = threading.Thread(target=ratings_utils.upload_rating_thread, args=(url, ratings, headers)) thread.start() @@ -168,22 +166,22 @@ def draw_ratings_menu(self, context, layout): profile_name = '' profile = bpy.context.window_manager.get('bkit profile') - if profile and len(profile['user']['firstName'])>0: + if profile and len(profile['user']['firstName']) > 0: profile_name = ' ' + profile['user']['firstName'] col = layout.column() # layout.template_icon_view(bkit_ratings, property, show_labels=False, scale=6.0, scale_popup=5.0) row = col.row() - row.label(text='Quality:', icon = 'SOLO_ON') + row.label(text='Quality:', icon='SOLO_ON') row = col.row() row.label(text='Please help the community by rating quality:') row = col.row() row.prop(self, 'rating_quality_ui', expand=True, icon_only=True, emboss=False) - if self.rating_quality>0: + if self.rating_quality > 0: # row = col.row() - row.label(text=f' Thanks{profile_name}!', icon = 'FUND') + row.label(text=f' Thanks{profile_name}!', icon='FUND') # row.label(text=str(self.rating_quality)) col.separator() col.separator() @@ -220,17 +218,17 @@ def draw_ratings_menu(self, context, layout): row = col.row() row.prop(self, 'rating_work_hours_ui_1_5', expand=True, icon_only=False, emboss=True) - if self.rating_work_hours>0: + if self.rating_work_hours > 0: row = col.row() row.label(text=f'Thanks{profile_name}, you are amazing!', icon='FUND') + class FastRateMenu(Operator, ratings_utils.RatingsProperties): """Rating of the assets , also directly from the asset bar - without need to download assets""" bl_idname = "wm.blenderkit_menu_rating_upload" - bl_label = "" + bl_label = "Ratings" bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} - @classmethod def poll(cls, context): scene = bpy.context.scene @@ -239,39 +237,12 @@ class FastRateMenu(Operator, ratings_utils.RatingsProperties): def draw(self, context): layout = self.layout - layout.label(text=self.message) - layout.separator() - draw_ratings_menu(self, context, layout) def execute(self, context): - user_preferences = bpy.context.preferences.addons['blenderkit'].preferences - api_key = user_preferences.api_key - headers = utils.get_headers(api_key) - - url = paths.get_api_url() + f'assets/{self.asset_id}/rating/' - - rtgs = [ - - ] - - if self.rating_quality_ui == '': - self.rating_quality = 0 - else: - self.rating_quality = float(self.rating_quality_ui) - - if self.rating_quality > 0.1: - rtgs = (('quality', self.rating_quality),) - tasks_queue.add_task((ratings_utils.send_rating_to_thread_quality, (url, rtgs, headers)), wait=2.5, only_last=True) - - if self.rating_work_hours > 0.45: - rtgs = (('working_hours', round(self.rating_work_hours, 1)),) - tasks_queue.add_task((ratings_utils.send_rating_to_thread_work_hours, (url, rtgs, headers)), wait=2.5, only_last=True) - return {'FINISHED'} - - def invoke(self, context, event): scene = bpy.context.scene ui_props = scene.blenderkitUI + #get asset id if ui_props.active_index > -1: sr = bpy.context.window_manager['search results'] asset_data = dict(sr[ui_props.active_index]) @@ -280,15 +251,16 @@ class FastRateMenu(Operator, ratings_utils.RatingsProperties): if self.asset_id == '': return {'CANCELLED'} - self.message = f"{self.asset_name}" + wm = context.window_manager + self.prefill_ratings() if self.asset_type in ('model', 'scene'): # spawn a wider one for validators for the enum buttons - return wm.invoke_props_dialog(self, width=500) + return wm.invoke_popup(self, width=500) else: - return wm.invoke_props_dialog(self) + return wm.invoke_popup(self) def rating_menu_draw(self, context): diff --git a/blenderkit/search.py b/blenderkit/search.py index f0d1fec668dba86472a74c22534ed99e130af393..534f4a095e4c99932cfb5085f479d21915efc0bc 100644 --- a/blenderkit/search.py +++ b/blenderkit/search.py @@ -424,18 +424,22 @@ def timer_update(): if ok: bpy.ops.object.run_assetbar_fix_context() - user_preferences = bpy.context.preferences.addons['blenderkit'].preferences - api_key = user_preferences.api_key - headers = utils.get_headers(api_key) + for r in rdata['results']: asset_data = parse_result(r) if asset_data != None: result_field.append(asset_data) - if utils.profile_is_validator() and ratings_utils.get_rating_local(asset_data['id']) is None: - thread = threading.Thread(target=ratings_utils.get_rating, args=([asset_data['id'], headers]), daemon=True) - thread.start() + # Get ratings from BlenderKit server + if utils.profile_is_validator(): + user_preferences = bpy.context.preferences.addons['blenderkit'].preferences + api_key = user_preferences.api_key + headers = utils.get_headers(api_key) + for r in rdata['results']: + if ratings_utils.get_rating_local(asset_data['id']) is None: + thread = threading.Thread(target=ratings_utils.get_rating, args=([r['id'], headers]), daemon=True) + thread.start() wm[search_name] = result_field wm['search results'] = result_field diff --git a/blenderkit/ui.py b/blenderkit/ui.py index 09a1f88e8b5c99de82eecef01aaf5c38eb47424a..f6438d85aff9a1eab90124915a96a0a286eb0a61 100644 --- a/blenderkit/ui.py +++ b/blenderkit/ui.py @@ -391,8 +391,11 @@ def draw_tooltip_with_author(asset_data, x, y): rcount = min(rc['quality'], rc['workingHours']) if rcount > show_rating_threshold: quality = round(asset_data['ratingsAverage'].get('quality')) + author_text = '' + if len(a['firstName'])>0 or len(a['lastName'])>0: + author_text = f"by {a['firstName']} {a['lastName']}" - draw_tooltip(x, y, name=aname, author=f"by {a['firstName']} {a['lastName']}", quality=quality, img=img, + draw_tooltip(x, y, name=aname, author=author_text, quality=quality, img=img, gravatar=gimg) @@ -693,7 +696,7 @@ def draw_asset_bar(self, context): v_icon = verification_icons[result.get('verificationStatus', 'validated')] if v_icon is None and utils.profile_is_validator(): - # poke for validators to rate + # poke for validators to rate if ratings_utils.get_rating_local(result['id']) in (None, {}): v_icon = 'star_grey.png'