equal
deleted
inserted
replaced
|
1 # -*- coding: utf-8 -*- |
|
2 import logging |
|
3 from renkanmanager import settings as renkan_settings |
|
4 from renkanmanager.models import Revision |
|
5 from django.db.models.signals import post_save |
|
6 from django.dispatch import receiver |
|
7 |
|
8 logger = logging.getLogger(__name__) |
|
9 |
|
10 |
|
11 @receiver(post_save, sender=Revision) |
|
12 def revision_post_save(sender, instance, created, raw, using, update_fields, **kwargs): |
|
13 renkan = instance.parent_renkan |
|
14 parent_revisions = renkan.revisions.all() |
|
15 logger.debug("REVISIONS %r, INSTANCE %r, CURRENT %r", parent_revisions, instance, renkan.current_revision) |
|
16 |
|
17 if (not renkan.current_revision or renkan_settings.RENKAN_AUTO_CURRENT_REVISION) and parent_revisions.count() >= 1 and renkan.current_revision != parent_revisions[0]: |
|
18 logger.debug("CHANGE CURRENT REVISION OLD: %r , NEW: %r", renkan.current_revision, parent_revisions[0]) |
|
19 renkan.current_revision = parent_revisions[0] |
|
20 renkan.save() |