Created
November 9, 2023 13:55
-
-
Save jsam/e2970da1cd318bc772fbb3052a9fc9c6 to your computer and use it in GitHub Desktop.
update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update(self, **kwargs): | |
if "platforms" not in kwargs: | |
return super(Campaign, self).update(**kwargs) | |
for platform in kwargs.pop("platforms"): | |
if not platform.get("name"): | |
continue | |
platform_obj = self.get_platform(platform.get("name")) | |
if not platform_obj: | |
platform_obj = CampaignPlatform( | |
name=platform.get("name"), | |
end_date=platform.get("end_date"), | |
product=platform.get("product"), | |
duration=platform.get("duration"), | |
) | |
platform_obj.start_date = platform.get("start_date") | |
platform_obj.status = "active" | |
if not platform_obj.is_published: | |
platform_obj.status = "inactive" | |
self.platforms.append(platform_obj) | |
if platform_obj.end_date and platform_obj.end_date != platform.get('end_date'): | |
self.update_deactivate_platform_history( | |
platform_obj, | |
action=CampaignPlatformHistoryActions.UPDATE, | |
event=CampaignPlatformHistoryEvents.DEACTIVATE_PLATFORM | |
) | |
# NOTE: Create new ads | |
platform_obj.set_platform_data(platform) | |
return super(Campaign, self).update(**kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment