openbackloggery/collection/games/signals.py

24 lines
796 B
Python

from games.models import Timeline
def game_saved(sender, instance, created, raw, using, update_fields,
**kwargs):
"""
Add timeline entry.
If game is created, add 2 timlines: 1 with CREATED status. The other with
current object status.
"""
# FIXME: don't write a timeline if previous have same title and object_id
entry = {
'item': instance,
'status': instance.status,
}
# Add CREATED status if Game was created
if created is True:
new_entry = dict(entry)
new_entry.update({'status': instance.CREATED})
Timeline.objects.create(**new_entry)
# Add new timeline entry ONLY if status is difference from CREATED one
if instance.status != instance.CREATED:
Timeline.objects.create(**entry)