Page MenuHome

eve_hooks.py
No OneTemporary

eve_hooks.py

# -*- encoding: utf-8 -*-
import itertools
import logging
from attract.node_types.shot import node_type_shot, human_readable_properties
from pillar.api.nodes import only_for_node_type_decorator
import pillar.api.activities
import pillar.api.utils.authentication
import pillar.api.utils
import pillar.web.jinja
log = logging.getLogger(__name__)
only_for_shot = only_for_node_type_decorator(node_type_shot['name'])
def register_shot_activity(shot, descr):
user_id = pillar.api.utils.authentication.current_user_id()
pillar.api.activities.register_activity(
user_id,
descr,
'node', shot['_id'],
'project', shot['project'],
shot['project'],
node_type=shot['node_type'],
)
@only_for_shot
def activity_after_replacing_shot(shot, original):
"""
Note: this is also used on PATCH, since our custom shot PATCH handler
performs a PUT-internal to run the patched node through Eve for
validation.
"""
# Compare to original, and either mention the things that changed,
# or (if they are equal) don't log an activity at all.
changes = list(itertools.islice(pillar.api.utils.doc_diff(shot, original), 2))
if not changes:
log.info('Not registering replacement of shot %s, as it is identical '
'in non-private fields.', shot['_id'])
return
if len(changes) == 1:
(key, val_shot, _) = changes[0]
try:
human_key = human_readable_properties[key]
except KeyError:
human_key = pillar.web.jinja.format_undertitle(key.rsplit('.', 1)[-1])
if key == 'properties.status':
val_shot = pillar.web.jinja.format_undertitle(val_shot)
elif len(val_shot) > 80:
val_shot = val_shot[:80] + u'…'
descr = 'changed "%s" to "%s" in shot "%s"' %\
(human_key, val_shot, shot['name'])
else:
descr = 'edited shot "%s"' % shot['name']
register_shot_activity(shot, descr)
@only_for_shot
def activity_after_creating_shot(shot):
register_shot_activity(shot, 'created a new shot "%s"' % shot['name'])
def activity_after_creating_shots(nodes):
for node in nodes:
activity_after_creating_shot(node)
@only_for_shot
def activity_after_deleting_shot(shot):
register_shot_activity(shot, 'deleted shot "%s"' % shot['name'])
def setup_app(app):
app.on_replaced_nodes += activity_after_replacing_shot
app.on_inserted_nodes += activity_after_creating_shots
app.on_deleted_item_nodes += activity_after_deleting_shot
app.on_deleted_resource_nodes += activity_after_deleting_shot

File Metadata

Mime Type
text/x-python
Expires
Thu, Dec 9, 8:28 AM (1 d, 23 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
04/cf/601976f692c7d12e51315f659b25

Event Timeline