events can show messages to user now

This commit is contained in:
Jakub Trllo 2018-11-29 16:30:07 +01:00
parent 5db5d7d086
commit 30c4066d2d
3 changed files with 28 additions and 95 deletions

View file

@ -17,8 +17,6 @@ class Sync_to_Avalon(BaseEvent):
if self.ca_mongoid in ent['keys']:
return False
self.proj = None
self.nameShotAsset = []
self.nameChanged = []
for entity in entities:
try:
@ -54,43 +52,33 @@ class Sync_to_Avalon(BaseEvent):
for entity in entities:
if entity.entity_type.lower() in ['task']:
entity = entity['parent']
try:
mongo_id = entity['custom_attributes'][self.ca_mongoid]
except:
return {
'success': False,
'message': "Please run 'Create Attributes' action or create custom attribute 'avalon_mongo_id' manually for {}".format(entity.entity_type)
}
message = "Please run 'Create Attributes' action or create custom attribute 'avalon_mongo_id' manually for {}".format(entity.entity_type)
self.show_message(event, message, False)
return
if entity not in importEntities:
importEntities.append(entity)
if len(importEntities) < 1:
return False
return
self.setAvalonAttributes()
io.install()
for entity in importEntities:
self.importToAvalon(entity)
io.uninstall()
message = ""
if len(self.nameChanged) > 0:
names = ", ".join(self.nameChanged)
message += "These entities name can't be changed in avalon, please reset DB or use restore action: {} \n".format(names)
if len(self.nameShotAsset) > 0:
names = ", ".join(self.nameChanged)
message += "These entities are already used in avalon, duplicates with new name were created: {}".format(names)
session.commit()
if message != "":
return {
'success': False,
'message': message
}
self.show_message(event, message, False)
return True
@ -162,22 +150,20 @@ class Sync_to_Avalon(BaseEvent):
if self.avalon_project is None:
self.importToAvalon(self.proj)
eLinks = []
for e in entity['link']:
tmp = self.session.get(e['type'], e['id'])
eLinks.append(tmp)
tasks = []
for child in entity['children']:
if child.entity_type in ['Task']:
tasks.append(child['name'])
folderStruct = []
parents = []
parentId = None
for i in range(1, len(eLinks)-1):
parents.append(eLinks[i])
parents = []
for i in range(1, len(entity['link'])-1):
tmp_type = entity['link'][i]['type']
tmp_id = entity['link'][i]['id']
tmp = self.session.get(tmp_type, tmp_id)
parents.append(tmp)
for parent in parents:
parname = self.checkName(parent['name'])

View file

@ -140,16 +140,20 @@ class BaseEvent(object):
message = str(input_message)
except:
return
source = {}
source['id'] = event['source']['applicationId']
source['user'] = event['source']['user']
self.session.event_hub.publish_reply(event, event['data'], source)
# event = ftrack_api.event.base.Event(
# topic='show_message_topic',
# data={'success':result, 'message': message}
# )
#
# self.session.event_hub.publish(event)
user_id = event['source']['user']['id']
self.session.event_hub.publish(
ftrack_api.event.base.Event(
topic='ftrack.action.trigger-user-interface',
data=dict(
type='message',
success=False,
message=message
),
target='applicationId=ftrack.client.web and user.id="{0}"'.format(user_id)
),
on_error='ignore'
)
def _handle_result(self, session, result, entities, event):
'''Validate the returned result from the action callback'''

View file

@ -10,37 +10,9 @@ class Test_Event(BaseEvent):
def launch(self, session, entities, event):
'''just a testing event'''
result = True
message = "test message"
data = {
'success':result,
'message': message,
}
self.log.info(event['data']['entities'])
# event['source']['id']
# self.show_message(event,"test",True)
# self.session.event_hub.publish_reply(event, data, subscriber.metadata)
# subscriber = None
# self.log.info("before Message")
# for s in self.session.event_hub._subscribers:
# if 'topic=custom_message_show' == str(s.subscription):
# subscriber = s
# break
#
# if subscriber is not None:
# id = subs.metadata['id']
#
# event = ftrack_api.event.base.Event(
# topic='topic=custom_message_show',
# data=data
# )
# self.session.event_hub.publish(event)
# self.log.info("after Message")
# self.show_message(event,"Test",True)
# self.log.info(event['source'])
return True
@ -51,32 +23,3 @@ def register(session, **kw):
event = Test_Event(session)
event.register()
# <Event {
# 'id': '2c6fc29e4ae342adbdf9eb8055759bd5',
# 'data': {
# 'entities': [
# {
# 'keys': ['name'],
# 'objectTypeId': '4be63b64-5010-42fb-bf1f-428af9d638f0',
# 'entityType': 'task',
# 'parents': [
# {'entityId': '42cb361a-f25b-11e8-b54e-0a580aa00143', 'entityType': 'task', 'parentId': '682ed692-f246-11e8-871e-0a580aa00143'},
# {'entityId': '682ed692-f246-11e8-871e-0a580aa00143', 'entityType': 'task', 'parentId': '2b7a3e24-f185-11e8-ac34-0a580aa00143'},
# {'entityId': '2b7a3e24-f185-11e8-ac34-0a580aa00143', 'entityType': 'show', 'parentId': None}],
# 'parentId': '682ed692-f246-11e8-871e-0a580aa00143',
# 'action': 'update',
# 'entityId': '42cb361a-f25b-11e8-b54e-0a580aa00143',
# 'changes': {'name': {'new': 'Cat01', 'old': 'Cat0'}}}],
# 'pushToken': 'b2e8d89ef3d711e899120a580aa00143',
# 'parents': ['682ed692-f246-11e8-871e-0a580aa00143', '42cb361a-f25b-11e8-b54e-0a580aa00143', '2b7a3e24-f185-11e8-ac34-0a580aa00143'],
# 'user': {'userid': '2a8ae090-cbd3-11e8-a87a-0a580aa00121', 'name': 'Kuba Trllo'},
# 'clientToken': 'b1e10dcc-f3d7-11e8-a9de-0a580aa00143'},
# 'topic': 'ftrack.update',
# 'sent': None,
# 'source': {
# 'applicationId': 'ftrack.client.web',
# 'user': {'username': 'jakub.trllo', 'id': '2a8ae090-cbd3-11e8-a87a-0a580aa00121'},
# 'id': 'b1e10dcc-f3d7-11e8-a9de-0a580aa00143'},
# 'target': '',
# 'in_reply_to_event': None}>]