Skip to content

Commit

Permalink
testing the unit test builds
Browse files Browse the repository at this point in the history
  • Loading branch information
uzairr committed Sep 6, 2023
1 parent 2f2307f commit caa3c09
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 16 additions & 0 deletions course_discovery/apps/course_metadata/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,19 @@ def has_model_changed(field_tracker, external_keys=None, excluded_fields=None):
return len(changed) or any(
item.has_changed for item in external_keys if hasattr(item, 'has_changed')
)


def should_history_be_skipped_on_save(obj, *args, **kwargs):
"""
Sets the parameter 'skip_history_on_save' if the object is not changed
Args:
obj: Any Model instance
parent_obj: parent object of the instance obj
"""
if not obj.has_changed:
setattr(obj, 'skip_history_when_saving', True) # pylint: disable=literal-used-as-attribute

super(obj.__class__, obj).save(*args, **kwargs)

if hasattr(obj, 'skip_history_when_saving'):
delattr(obj, 'skip_history_when_saving') # pylint: disable=literal-used-as-attribute
6 changes: 3 additions & 3 deletions course_discovery/apps/course_metadata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from course_discovery.apps.course_metadata.constants import SUBDIRECTORY_SLUG_FORMAT_REGEX, PathwayType
from course_discovery.apps.course_metadata.fields import AutoSlugWithSlashesField, HtmlField, NullHtmlField
from course_discovery.apps.course_metadata.managers import DraftManager
from course_discovery.apps.course_metadata.model_utils import has_model_changed
from course_discovery.apps.course_metadata.model_utils import has_model_changed, should_history_be_skipped_on_save
from course_discovery.apps.course_metadata.people import MarketingSitePeople
from course_discovery.apps.course_metadata.publishers import (
CourseRunMarketingSitePublisher, ProgramMarketingSitePublisher
Expand Down Expand Up @@ -1459,11 +1459,11 @@ def save(self, *args, **kwargs):
and then need to update the boolean in the record based on conditional logic
"""
self.update_data_modified_timestamp()
super().save(*args, **kwargs)
should_history_be_skipped_on_save(self, *args, **kwargs)
self.enterprise_subscription_inclusion = self._check_enterprise_subscription_inclusion()
kwargs['force_insert'] = False
kwargs['force_update'] = True
super().save(*args, **kwargs)
should_history_be_skipped_on_save(self, *args, **kwargs)

# Course runs calculate enterprise subscription inclusion based off of their parent's status, so we need to
# force a recalculation
Expand Down

0 comments on commit caa3c09

Please sign in to comment.