def custom_add_to_object_timeline(obj:object, instance:object, event_type:str, namespace:str="default", extra_data:dict={}): assert isinstance(obj, Model), "obj must be a instance of Model" assert isinstance(instance, Model), "instance must be a instance of Model" event_type_key = _get_impl_key_from_model(instance.__class__, event_type) impl = _timeline_impl_map.get(event_type_key, None) bulk_creator.create_element(Timeline( content_object=obj, namespace=namespace, event_type=event_type_key, project=instance.project, data=impl(instance, extra_data=extra_data), data_content_type = ContentType.objects.get_for_model(instance.__class__), created = bulk_creator.created, ))
def custom_add_to_object_timeline(obj:object, instance:object, event_type:str, created_datetime:object, namespace:str="default", extra_data:dict={}): assert isinstance(obj, Model), "obj must be a instance of Model" assert isinstance(instance, Model), "instance must be a instance of Model" event_type_key = _get_impl_key_from_model(instance.__class__, event_type) impl = _timeline_impl_map.get(event_type_key, None) bulk_creator.create_element(Timeline( content_object=obj, namespace=namespace, event_type=event_type_key, project=instance.project, data=impl(instance, extra_data=extra_data), data_content_type=ContentType.objects.get_for_model(instance.__class__), created=created_datetime, ))
def flush(self): Timeline.objects.bulk_create(self.timeline_objects, batch_size=1000) del self.timeline_objects self.timeline_objects = [] gc.collect() bulk_creator = BulkCreator() def custom_add_to_object_timeline(obj:object, instance:object, event_type:str, created_datetime:object, namespace:str="default", extra_data:dict={}): assert isinstance(obj, Model), "obj must be a instance of Model" assert isinstance(instance, Model), "instance must be a instance of Model" event_type_key = _get_impl_key_from_model(instance.__class__, event_type) impl = _timeline_impl_map.get(event_type_key, None) bulk_creator.create_element(Timeline( content_object=obj, namespace=namespace, event_type=event_type_key, project=None, data=impl(instance, extra_data=extra_data), data_content_type = ContentType.objects.get_for_model(instance.__class__), created=created_datetime, )) def generate_timeline(): with patch('taiga.timeline.service._add_to_object_timeline', new=custom_add_to_object_timeline): # Users api wasn't a HistoryResourceMixin so we can't interate on the HistoryEntries in this case