def update_or_create_salesforce_organization(instance, created, **kwargs): # pylint: disable=unused-argument partner = instance.partner util = get_salesforce_util(partner) if util: if not instance.salesforce_id: util.create_publisher_organization(instance) if not created and requires_salesforce_update('organization', instance): util.update_publisher_organization(instance)
def update_or_create_salesforce_course_run(instance, created, **kwargs): # pylint: disable=unused-argument partner = instance.course.partner util = get_salesforce_util(partner) if util: if instance.draft: util.create_course_run(instance) elif not created and not instance.draft: created_in_salesforce = False if not instance.salesforce_id and instance.draft_version: created_in_salesforce = populate_official_with_existing_draft(instance, util) if not created_in_salesforce and requires_salesforce_update('course_run', instance): util.update_course_run(instance)
def test_requires_salesforce_update(self): org = OrganizationFactoryNoSignals( partner=self.salesforce_config.partner) org.description = 'changed' self.assertEqual(requires_salesforce_update('organization', org), False) org.name = 'changed' self.assertEqual(requires_salesforce_update('organization', org), True) course = CourseFactory() course.short_description = 'changed' self.assertEqual(requires_salesforce_update('course', course), False) course.title = 'changed' self.assertEqual(requires_salesforce_update('course', course), True) course_run = CourseRunFactory() course_run.full_description = 'changed' self.assertEqual(requires_salesforce_update('course_run', course_run), False) course_run.key = 'changed' self.assertEqual(requires_salesforce_update('course_run', course_run), True)
def update_or_create_salesforce_course(instance, created, **kwargs): # pylint: disable=unused-argument partner = instance.partner util = get_salesforce_util(partner) # Only bother to create the course if there's a util, and the auth orgs are already set up if util and instance.authoring_organizations.first(): if not created and not instance.draft: created_in_salesforce = False # Only populate the Official instance if the draft information is ready to go (has auth orgs set) if (not instance.salesforce_id and instance.draft_version and instance.draft_version.authoring_organizations.first()): created_in_salesforce = populate_official_with_existing_draft(instance, util) if not created_in_salesforce and requires_salesforce_update('course', instance): util.update_course(instance)
def update_or_create_salesforce_course_run(instance, created, **kwargs): # pylint: disable=unused-argument try: partner = instance.course.partner except (Course.DoesNotExist, Partner.DoesNotExist): # exit early in the unusual event that we can't look up the appropriate partner return util = get_salesforce_util(partner) if util: if instance.draft: util.create_course_run(instance) elif not created and not instance.draft: created_in_salesforce = False if not instance.salesforce_id and instance.draft_version: created_in_salesforce = populate_official_with_existing_draft( instance, util) if not created_in_salesforce and requires_salesforce_update( 'course_run', instance): util.update_course_run(instance)