Skip to content
Snippets Groups Projects
Commit 135d705d authored by Martin Burchell's avatar Martin Burchell
Browse files

Made last_modified on item update when term added

parent 13796d18
Branches
No related tags found
1 merge request!7Data Layer updates a "last edit date" field on the Item
from django.db import models
from django.dispatch.dispatcher import receiver
from django.utils import timezone
from taxonomies.models import Term
......@@ -11,6 +12,10 @@ class DataLayerModel(models.Model):
class Meta:
abstract = True
def note_external_modification(self):
self.last_modified = timezone.now()
self.save()
class Message(DataLayerModel):
body = models.TextField()
......@@ -45,3 +50,10 @@ class Message(DataLayerModel):
# TODO: rename this class
Item = Message
@receiver(models.signals.m2m_changed, sender=Item.terms.through,
dispatch_uid="data_layer.models.terms_signal_handler")
def terms_signal_handler(sender, **kwargs):
instance = kwargs.get('instance')
instance.note_external_modification()
......@@ -4,6 +4,7 @@ from django.utils import timezone
from factories import ItemFactory
from ..models import Item
from taxonomies.tests.factories import TermFactory
import datetime
from mock import patch, MagicMock
......@@ -35,3 +36,17 @@ def test_last_modified_date_updates_on_body_change():
item.save()
assert orig_last_modified < last_modified(item)
@pytest.mark.django_db
def test_last_modified_date_updates_on_category_change():
item = ItemFactory()
magic_mock = MagicMock(wraps=timezone.now,
side_effect=now_iter(timezone.now()))
with patch('django.utils.timezone.now', new=magic_mock):
orig_last_modified = last_modified(item)
term = TermFactory()
item.terms.add(term)
assert orig_last_modified < last_modified(item)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment