BlenderKit: Fixes

rating showing to non-logged in users
Upload wasn't showing proper error message when not logged in too.
Replace selected models wasn't shown with no active object
First registration search wasn't shown.
Sorting of uploaded assets for validators was reversed
This commit is contained in:
Vilém Duha 2020-05-24 10:34:25 +02:00
parent 0c551e05a4
commit c5fad30a5d
8 changed files with 45 additions and 5 deletions

View File

@ -17,12 +17,12 @@
# ##### END GPL LICENSE BLOCK #####
bl_info = {
"name": "BlenderKit Asset Library",
"name": "BlenderKit Online Asset Library",
"author": "Vilem Duha, Petr Dlouhy",
"version": (1, 0, 30),
"blender": (2, 82, 0),
"location": "View3D > Properties > BlenderKit",
"description": "Online BlenderKit library (materials, models, brushes and more)",
"description": "Online BlenderKit library (materials, models, brushes and more). Connects to the internet.",
"warning": "",
"doc_url": "{BLENDER_MANUAL_URL}/addons/add_mesh/blenderkit.html",
"category": "3D View",

View File

@ -139,6 +139,7 @@ class Logout(bpy.types.Operator):
preferences.login_attempt = False
preferences.api_key_refresh = ''
preferences.api_key = ''
del (bpy.context.window_manager['bkit profile'])
return {'FINISHED'}

View File

@ -770,6 +770,8 @@ def get_download_url(asset_data, scene_id, api_key, tcom=None):
data = {
'scene_uuid': scene_id
}
r = None
try:
r = rerequests.get(asset_data['download_url'], params=data, headers=headers)
except Exception as e:

View File

@ -109,6 +109,7 @@ def get_rating(asset_id):
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

View File

@ -156,7 +156,7 @@ def timer_update():
preferences = bpy.context.preferences.addons['blenderkit'].preferences
if first_time: # first time
first_time = False
if preferences.show_on_start or preferences.first_run:
if preferences.show_on_start:
# TODO here it should check if there are some results, and only open assetbar if this is the case, not search.
# if bpy.context.scene.get('search results') is None:
search()
@ -167,6 +167,10 @@ def timer_update():
ui.add_report(text='BlenderKit Tip: ' + random.choice(rtips), timeout=12, color=colors.GREEN)
return 3.0
if preferences.first_run:
search()
preferences.first_run = False
check_clipboard()
global search_threads
@ -765,7 +769,11 @@ class Searcher(threading.Thread):
if query.get('query') is None and query.get('category_subtree') == None:
# assumes no keywords and no category, thus an empty search that is triggered on start.
# orders by last core file upload
requeststring += '+order:-last_upload'
if query.get('verification_status') == 'uploaded':
#for validators, sort uploaded from oldest
requeststring += '+order:created'
else:
requeststring += '+order:-last_upload'
elif query.get('author_id') is not None and utils.profile_is_validator():
requeststring += '+order:-created'

View File

@ -73,6 +73,11 @@ def draw_ratings(layout, context):
# this function should run only when asset was already checked to be existing
if asset == None:
return;
if not utils.user_logged_in():
label_multiline(layout, text='Please login or sign up '
'to rate assets.')
return
bkit_ratings = asset.bkit_ratings
ratings.draw_rating(layout, bkit_ratings, 'rating_quality', 'Quality')
@ -89,6 +94,14 @@ def draw_ratings(layout, context):
# op = row.operator("object.blenderkit_rating_upload", text="Send rating", icon='URL')
# return op
def draw_not_logged_in(source):
title = "User not logged in"
def draw_message(source, context):
layout = source.layout
label_multiline(layout, text='Please login or sign up '
'to upload files.')
draw_login_buttons(layout)
bpy.context.window_manager.popup_menu(draw_message, title=title, icon='INFO')
def draw_upload_common(layout, props, asset_type, context):
op = layout.operator("wm.url_open", text="Read upload instructions",
@ -919,8 +932,10 @@ class OBJECT_MT_blenderkit_asset_menu(bpy.types.Menu):
op = layout.operator('view3d.blenderkit_search', text='Search Similar')
op.keywords = asset_data['name'] + ' ' + asset_data['description'] + ' ' + ' '.join(asset_data['tags'])
if asset_data.get('canDownload') != 0:
if bpy.context.view_layer.objects.active is not None and ui_props.asset_type == 'MODEL':
if len(bpy.context.selected_objects)>0 and ui_props.asset_type == 'MODEL':
aob = bpy.context.active_object
if aob is None:
aob = bpy.context.selected_objects[0]
op = layout.operator('scene.blenderkit_download', text='Replace Active Models')
op.asset_type = ui_props.asset_type
op.asset_index = ui_props.active_index

View File

@ -750,6 +750,8 @@ class UploadOperator(Operator):
return result
def draw(self, context):
props = utils.get_upload_props()
layout = self.layout
@ -774,6 +776,10 @@ class UploadOperator(Operator):
def invoke(self, context, event):
props = utils.get_upload_props()
if not utils.user_logged_in():
ui_panels.draw_not_logged_in(self)
return {'CANCELLED'}
if props.is_private == 'PUBLIC':
return context.window_manager.invoke_props_dialog(self)
else:

View File

@ -546,6 +546,13 @@ def dict_to_params(inputs, parameters=None):
return parameters
def user_logged_in():
a = bpy.context.window_manager.get('bkit profile')
if a is not None:
return True
return False
def profile_is_validator():
a = bpy.context.window_manager.get('bkit profile')
if a is not None and a['user'].get('exmenu'):