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 import logging
from attract.node_types.shot import node_type_shot from attract.node_types.shot import node_type_shot
from pillar.api.nodes import only_for_node_type_decorator from pillar.api.nodes import only_for_node_type_decorator
import pillar.api.activities import pillar.api.activities
import pillar.api.utils.authentication import pillar.api.utils.authentication
import pillar.api.utils
import pillar.web.jinja
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
only_for_shot = only_for_node_type_decorator(node_type_shot['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. 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. # 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 @only_for_shot

View File

@@ -1,11 +1,13 @@
import logging import logging
import itertools
from flask import current_app from flask import current_app
from attract.node_types.task import node_type_task from attract.node_types.task import node_type_task
from pillar.api.nodes import only_for_node_type_decorator from pillar.api.nodes import only_for_node_type_decorator
import pillar.api.activities import pillar.api.activities
import pillar.api.utils.authentication import pillar.api.utils.authentication
import pillar.web.jinja
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
only_for_task = only_for_node_type_decorator(node_type_task['name']) only_for_task = only_for_node_type_decorator(node_type_task['name'])
@@ -100,9 +102,24 @@ def register_task_activity(task, descr):
@only_for_task @only_for_task
def activity_after_replacing_task(task, original): def activity_after_replacing_task(task, original):
# 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. # or (if they are equal) don't log an activity at all.
register_task_activity(task, 'edited task "%s"' % task['name']) changes = list(itertools.islice(pillar.api.utils.doc_diff(task, original), 2))
if not changes:
log.info('Not registering replacement of task %s, as it is identical '
'in non-private fields.', task['_id'])
return
if len(changes) == 1:
(key, val_task, _) = changes[0]
human_key = key.rsplit('.', 1)[-1]
if key == 'properties.status':
val_task = pillar.web.jinja.format_undertitle(val_task)
descr = 'changed %s to %s in task "%s"' % (human_key, val_task, task['name'])
else:
descr = 'edited task "%s"' % task['name']
register_task_activity(task, descr)
@only_for_task @only_for_task