Include changes in activity log if only one field changed.

This commit is contained in:
2016-10-12 16:02:02 +02:00
parent 2842201974
commit b457b57a09
2 changed files with 39 additions and 4 deletions

View File

@@ -1,9 +1,12 @@
import itertools
import logging
from attract.node_types.shot import node_type_shot
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'])
@@ -29,9 +32,24 @@ def activity_after_replacing_shot(shot, original):
validation.
"""
# TODO: compare to original, and either mention the things that changed,
# Compare to original, and either mention the things that changed,
# or (if they are equal) don't log an activity at all.
register_shot_activity(shot, 'edited shot "%s"' % shot['name'])
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]
human_key = key.rsplit('.', 1)[-1]
if key == 'properties.status':
val_shot = pillar.web.jinja.format_undertitle(val_shot)
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