def test_model_serializer(self): custom_serializer = 'tests.test_app.models.CustomSerializer' with override_settings(SIMPLE_LOG_MODEL_SERIALIZER=custom_serializer): with isolate_lru_cache(get_serializer): self.assertEqual(get_serializer(TestModel), CustomSerializer) with override_settings(SIMPLE_LOG_MODEL_SERIALIZER=CustomSerializer): with isolate_lru_cache(get_serializer): self.assertEqual(get_serializer(TestModel), CustomSerializer)
def save_logs_on_commit(logs): for log in [x for x in logs if not x.pk]: instance = log.instance serializer = get_serializer(instance.__class__)() log.old = getattr(instance, '_old_values', None) log.new = serializer(instance) if log.force_save or log.old != log.new: log.save() if settings.SAVE_RELATED and any([x.pk for x in logs if not x.disable_related]): save_related(logs)
def save_logs_on_commit(): logs = get_thread_variable('logs', []) for log in [x for x in logs if not x.pk]: instance = log.instance serializer = get_serializer(instance.__class__)() log.old = getattr(instance, '_old_values', None) log.new = serializer(instance) if log.force_save or log.old != log.new: log.save() if (settings.SAVE_RELATED and not get_thread_variable('disable_related') and any([x.pk for x in logs])): save_related(logs) del_thread_variable('logs') del_thread_variable('request')
def test_concrete_model_serializer(self, mocked): with isolate_lru_cache(get_serializer): self.assertEqual(get_serializer(TestModel), CustomSerializer)