From eef3697a74dbccc4147a7257c2e0c3daad2a180f Mon Sep 17 00:00:00 2001 From: Alexander Dusenbery Date: Wed, 24 Jul 2024 16:33:50 -0400 Subject: [PATCH] fix: ContentMetadata.bulk_update() changes the modified value --- enterprise_catalog/apps/catalog/models.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/enterprise_catalog/apps/catalog/models.py b/enterprise_catalog/apps/catalog/models.py index eb72ad045..860db4f59 100644 --- a/enterprise_catalog/apps/catalog/models.py +++ b/enterprise_catalog/apps/catalog/models.py @@ -493,6 +493,25 @@ def get_xapi_activity_id(self, content_resource, content_key): return xapi_activity_id +class ContentMetadataManager(models.Manager): + """ + Customer manager for ContentMetadata that forces the `modified` field + to be updated during `bulk_update()`. + """ + + def bulk_update(self, objs, fields, batch_size=None): + """ + Updates the `modified` time of each object, and then + does the usual bulk update, with `modified` as also + a field to save. + """ + last_modified = localized_utcnow() + for obj in objs: + obj.modified = last_modified + fields += ['modified'] + + super().bulk_update(objs, fields, batch_size=None) + class ContentMetadata(TimeStampedModel): """ Stores the JSON metadata for a piece of content, such as a course, course run, or program. @@ -556,6 +575,8 @@ class ContentMetadata(TimeStampedModel): history = HistoricalRecords() + objects = ContentMetadataManager() + class Meta: verbose_name = _("Content Metadata") verbose_name_plural = _("Content Metadata")