2. Naming script example. Which can be used to replace standard naming.
3. Message to Telegram if you have new note in your task:
Code:
mode = input['mode']
ext = input.get('ext')
project_code = input['project']
parent = None
project = None
if input.get('sobject'):
sobject = input['sobject'].get_value
project = input['sobject'].get_project().get_value
parent = input['sobject'].get_parent()
if parent:
parent = parent.get_value
else:
parent = sobject
if input.get('snapshot'):
snapshot = input['snapshot'].get_value
version = snapshot('version')
if version:
version = int(version)
if version in [-1, 0]:
version = None
if input.get('file_object'):
file_object = input['file_object'].get_value
else:
return None
if mode == 'file':
if version:
# Version file name for Publish process
if snapshot('process') == 'publish':
full_name = u'{sobject_name}_v{version:03d}{ext}'.format(
sobject_name=sobject('name'),
version=version,
ext=ext,
)
else:
# Version naming
full_name = u'{sobject_name}_{snapshot_context}_v{version:03d}{ext}'.format(
sobject_name=sobject('name'),
snapshot_context=snapshot('context'),
version=version,
ext=ext,
)
else:
if snapshot('process') == 'publish':
# Versionless file name
full_name = u'{sobject_name}{ext}'.format(
sobject_name=sobject('name'),
ext=ext,
)
else:
# Versionless file name
full_name = u'{sobject_name}_{snapshot_context}{ext}'.format(
sobject_name=sobject('name'),
snapshot_context=snapshot('context'),
ext=ext,
)
return full_name.replace('/', '_')
elif mode == 'dir':
# path for icons and web files
if file_object('type') == 'web':
preview_path = u'/__preview/web'
elif file_object('type') == 'icon':
preview_path = u'/__preview/icon'
elif file_object('type') == 'playblast':
preview_path = u'/__preview'
else:
preview_path = u''
if not version:
if snapshot('process') == 'publish':
full_dir = u'{project_category}/{project_code}/assets/{parent_code}/{sobject_name}/{preview_path}'.format(
project_category=project('category'),
project_code=project('code'),
parent_code=parent('code'),
sobject_name=sobject('name'),
preview_path=preview_path,
)
else:
full_dir = u'{project_category}/{project_code}/assets/{parent_code}/{sobject_name}/{snapshot_context}{preview_path}'.format(
project_category=project('category'),
project_code=project('code'),
parent_code=parent('code'),
sobject_name=sobject('name'),
snapshot_context=snapshot('context'),
preview_path=preview_path,
)
else:
if snapshot('process') == 'publish':
snapshot_context = ''
else:
snapshot_context = '/{0}'.format(snapshot('context'))
full_dir = u'{project_category}/{project_code}/assets/{parent_code}/{sobject_name}/{snapshot_context}/versions/{preview_path}'.format(
project_category=project('category'),
project_code=project('code'),
parent_code=parent('code'),
sobject_name=sobject('name'),
snapshot_context=snapshot_context,
preview_path=preview_path,
)
return full_dir
3. Message to Telegram if you have new note in your task:
Code:
from pyasm.prod.biz import ProdSetting
import json
server.set_project('YOUR PROJECT')
telegram_notifications_enabled = ProdSetting.get_value_by_key('telegram_notifications_enabled')
telegram_notifications_enabled = json.loads(telegram_notifications_enabled)
import telegram
from telegram.utils.request import Request
bot = telegram.Bot(token='YOUR TOKEN')
CHECK_ID = "TESTING TELEGAM ID: 1111111111"
if telegram_notifications_enabled:
def get_related_task(sobj):
search_code = sobj.get('search_code')
process = sobj.get('process')
if search_code and process:
related_task = server.eval("@SOBJECT(sthpw/task['search_code', '{0}']['process', '{1}'])".format(search_code, process), single=True)
if related_task:
return related_task
def get_user_from_task_sobj(sobj):
assigned_user = sobj.get('assigned')
if assigned_user:
assigned_user_sobj = server.eval("@SOBJECT(sthpw/login['login','{0}'])".format(assigned_user), single=True)
return assigned_user_sobj
task_sobject = get_related_task(input['sobject'])
if task_sobject:
assigned_user = get_user_from_task_sobj(task_sobject)
else:
assigned_user = None
assigned_user_chat_id = None
if assigned_user:
assigned_user_chat_id = assigned_user['phone_number']
def generate_task_info_message(input, task_sobject, assigned_user):
message_text = None
if input['mode'] == 'insert':
note = input['update_data'].get('note')
filters = [('code', task_sobject['search_code'])]
related_sobject = server.query(task_sobject['search_type'], filters, single=True)
user_telegram_login = bot.get_chat(assigned_user_chat_id)['username']
if user_telegram_login:
assigned_user_title = u'{0} {1} @{2}'.format(assigned_user['first_name'], assigned_user['last_name'], user_telegram_login)
else:
assigned_user_title = u'{0} {1}'.format(assigned_user['first_name'], assigned_user['last_name'])
related_sobject_name = related_sobject['name']
task_process = task_sobject['context']
#task_description = task_sobject['description']
#parent_description = related_sobject['description']
message_con = []
message_con.append(u'<i>Message to task: </i> <b>#{0}</b>, '.format(related_sobject_name))
if task_process:
message_con.append(u'<i>Process:</i> <b>#{0}</b>\n'.format(task_process))
if note:
message_con.append(u'\n<i>{0}:</i> {1}'.format(assigned_user_title, note))
message_text = u''.join(message_con)
return message_text
if assigned_user:
message_text = generate_task_info_message(input, task_sobject, assigned_user)
else:
message_text = None
if message_text:
# sendging message to assigned user
if assigned_user_chat_id:
try:
bot.send_message(chat_id=assigned_user_chat_id, parse_mode=telegram.ParseMode.HTML, text=message_text)
except:
mess = 'Message not sent to {0}'.format(assigned_user_chat_id)
bot.send_message(chat_id=CHECK_ID, text=mess)