def publish_to_studio(self, partner, course_run): api = StudioAPI(partner.studio_api_client) try: api.push_to_studio(course_run) return self.PUBLICATION_SUCCESS_STATUS except SlumberBaseException as ex: content = ex.content.decode('utf8') logger.exception( 'Failed to publish course run [%d] to Studio! Error was: [%s]', course_run.pk, content) return 'FAILED: ' + content except Exception as ex: # pylint: disable=broad-except logger.exception('Failed to publish course run [%d] to Studio!', course_run.pk) return 'FAILED: ' + str(ex)
def create_course_run_in_studio_receiver(sender, instance, created, **kwargs): # pylint: disable=unused-argument if created and waffle.switch_is_active( 'enable_publisher_create_course_run_in_studio'): course = instance.course partner = course.partner if not partner: logger.error( 'Failed to publish course run [%d] to Studio. Related course [%d] has no associated Partner.', instance.id, course.id) return logger.info('Publishing course run [%d] to Studio...', instance.id) api = StudioAPI(instance.course.partner.studio_api_client) discovery_course_run = instance.discovery_counterpart_latest_by_start_date try: if discovery_course_run: response = api.push_to_studio( instance, create=True, old_course_run_key=discovery_course_run.key) else: response = api.push_to_studio(instance, create=True) except SlumberBaseException as ex: logger.exception('Failed to create course run [%s] on Studio: %s', course.key, ex.content) raise except Exception: logger.exception('Failed to create course run [%s] on Studio', course.key) raise instance.lms_course_id = response['id'] instance.save() api.update_course_run_image_in_studio(instance, response) logger.info('Completed creation of course run [%s] on Studio.', instance.lms_course_id)
def create_course_run_in_studio_receiver(sender, instance, created, **kwargs): # pylint: disable=unused-argument if created and waffle.switch_is_active( 'enable_publisher_create_course_run_in_studio'): course = instance.course for organization in course.organizations.all(): try: if not organization.organization_extension.auto_create_in_studio: logger.warning( ('Course run [%d] will not be automatically created in studio.' 'Organization [%s] has opted out of this feature.'), course.id, organization.key, ) return except ObjectDoesNotExist: logger.exception( 'Organization [%s] does not have an associated OrganizationExtension', organization.key, ) partner = course.partner if not partner: logger.error( 'Failed to publish course run [%d] to Studio. Related course [%d] has no associated Partner.', instance.id, course.id) return logger.info('Publishing course run [%d] to Studio...', instance.id) api = StudioAPI(instance.course.partner.studio_api_client) discovery_course_run = instance.discovery_counterpart_latest_by_start_date try: response = api.push_to_studio(instance, create=True, old_course_run=discovery_course_run) except SlumberBaseException as ex: logger.exception('Failed to create course run [%s] on Studio: %s', course.key, ex.content) raise except Exception: # pylint: disable=broad-except logger.exception('Failed to create course run [%s] on Studio', course.key) raise instance.lms_course_id = response['id'] instance.save() logger.info('Completed creation of course run [%s] on Studio.', instance.lms_course_id)