Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Ftrack Multiple notes as server action #1794

Merged
merged 4 commits into from
Jul 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions pype/modules/ftrack/events/action_multiple_notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
from pype.modules.ftrack.lib import ServerAction


class MultipleNotesServer(ServerAction):
'''Edit meta data action.'''

#: Action identifier.
identifier = 'multiple.notes.server'
#: Action label.
label = 'Multiple Notes (Server)'
#: Action description.
description = 'Add same note to multiple Asset Versions'

def discover(self, session, entities, event):
''' Validation '''
valid = True
for entity in entities:
if entity.entity_type.lower() != 'assetversion':
valid = False
break
return valid

def interface(self, session, entities, event):
event_source = event["source"]
user_info = event_source.get("user") or {}
user_id = user_info.get("id")
if not user_id:
return {
"success": False,
"message": "Couldn't get user information."
}

if not event['data'].get('values', {}):
note_label = {
'type': 'label',
'value': '# Enter note: #'
}

note_value = {
'name': 'note',
'type': 'textarea'
}

category_label = {
'type': 'label',
'value': '## Category: ##'
}

category_data = []
category_data.append({
'label': '- None -',
'value': 'none'
})
all_categories = session.query('NoteCategory').all()
for cat in all_categories:
category_data.append({
'label': cat['name'],
'value': cat['id']
})
category_value = {
'type': 'enumerator',
'name': 'category',
'data': category_data,
'value': 'none'
}

splitter = {
'type': 'label',
'value': '{}'.format(200*"-")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing whitespace around arithmetic operator

}

items = []
items.append(note_label)
items.append(note_value)
items.append(splitter)
items.append(category_label)
items.append(category_value)
return items

def launch(self, session, entities, event):
if 'values' not in event['data']:
return

values = event['data']['values']
if len(values) <= 0 or 'note' not in values:
return False
# Get Note text
note_value = values['note']
if note_value.lower().strip() == '':
return False

# Get User
event_source = event["source"]
user_info = event_source.get("user") or {}
user_id = user_info.get("id")
user = None
if user_id:
user = session.query(
'User where id is "{}"'.format(user_id)
).first()

if not user:
return {
"success": False,
"message": "Couldn't get user information."
}

# Base note data
note_data = {
'content': note_value,
'author': user
}
# Get category
category_value = values['category']
if category_value != 'none':
category = session.query(
'NoteCategory where id is "{}"'.format(category_value)
).one()
note_data['category'] = category
# Create notes for entities
for entity in entities:
new_note = session.create('Note', note_data)
entity['notes'].append(new_note)
session.commit()
return True


def register(session, plugins_presets={}):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use mutable data structures for argument defaults. They are created during function definition time. All calls to the function reuse this one instance of that data structure, persisting changes between them.

'''Register plugin. Called when used as an plugin.'''

MultipleNotesServer(session, plugins_presets).register()