Skip to content

Commit

Permalink
chore: fix linter complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzawaleed01 committed Oct 23, 2023
1 parent 7c8c5db commit 8bd3405
Showing 1 changed file with 53 additions and 69 deletions.
122 changes: 53 additions & 69 deletions integrated_channels/degreed2/exporters/learner_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,77 +32,16 @@ def get_learner_data_records(
If no remote ID can be found, return None.
"""
percent_grade = kwargs.get('grade_percent') * 100 if kwargs.get('grade_percent') else None
# Degreed expects completion dates of the form 'yyyy-mm-ddTHH:MM:SS'.
degreed_completed_timestamp = completed_date.strftime('%Y-%m-%dT%H:%M:%S') if isinstance(
completed_date, datetime
) else None
try:
percent_grade = kwargs.get('grade_percent') * 100 if kwargs.get('grade_percent') else None
# Degreed expects completion dates of the form 'yyyy-mm-ddTHH:MM:SS'.
degreed_completed_timestamp = completed_date.strftime('%Y-%m-%dT%H:%M:%S') if isinstance(
completed_date, datetime
) else None
LOGGER.info(generate_formatted_log(
self.enterprise_configuration.channel_code(),
enterprise_enrollment.enterprise_customer_user.enterprise_customer.uuid,
enterprise_enrollment.enterprise_customer_user.user_id,
enterprise_enrollment.course_id,
'[Degreed2Client] - Attempting get_learner_data_records:'
f'percent_grade={percent_grade}, degreed_completed_timestamp={degreed_completed_timestamp}'
f'completed_date={completed_date}, course_completed={course_completed}'
))
if enterprise_enrollment.enterprise_customer_user.get_remote_id(
remote_id = enterprise_enrollment.enterprise_customer_user.get_remote_id(
self.enterprise_configuration.idp_id
) is not None:
LOGGER.info(generate_formatted_log(
self.enterprise_configuration.channel_code(),
enterprise_enrollment.enterprise_customer_user.enterprise_customer.uuid,
enterprise_enrollment.enterprise_customer_user.user_id,
enterprise_enrollment.course_id,
'[Degreed2Client] - Found remote id:'
f'percent_grade={percent_grade}, degreed_completed_timestamp={degreed_completed_timestamp}'
f'completed_date={completed_date}, course_completed={course_completed}'
f'course_id={get_course_id_for_enrollment(enterprise_enrollment)}'
))
Degreed2LearnerDataTransmissionAudit = apps.get_model(
'degreed2',
'Degreed2LearnerDataTransmissionAudit'
)
# We return two records here, one with the course key and one with the course run id, to account for
# uncertainty about the type of content (course vs. course run) that was sent to the integrated channel.
return [
Degreed2LearnerDataTransmissionAudit(
enterprise_course_enrollment_id=enterprise_enrollment.id,
degreed_user_email=enterprise_enrollment.enterprise_customer_user.user_email,
user_email=enterprise_enrollment.enterprise_customer_user.user_email,
course_id=get_course_id_for_enrollment(enterprise_enrollment),
completed_timestamp=completed_date,
degreed_completed_timestamp=degreed_completed_timestamp,
course_completed=course_completed,
grade=percent_grade,
enterprise_customer_uuid=enterprise_enrollment.enterprise_customer_user.enterprise_customer.uuid,
plugin_configuration_id=self.enterprise_configuration.id,
),
Degreed2LearnerDataTransmissionAudit(
enterprise_course_enrollment_id=enterprise_enrollment.id,
degreed_user_email=enterprise_enrollment.enterprise_customer_user.user_email,
user_email=enterprise_enrollment.enterprise_customer_user.user_email,
course_id=enterprise_enrollment.course_id,
completed_timestamp=completed_date,
degreed_completed_timestamp=degreed_completed_timestamp,
course_completed=course_completed,
grade=percent_grade,
enterprise_customer_uuid=enterprise_enrollment.enterprise_customer_user.enterprise_customer.uuid,
plugin_configuration_id=self.enterprise_configuration.id,
)
]
LOGGER.info(generate_formatted_log(
self.enterprise_configuration.channel_code(),
enterprise_enrollment.enterprise_customer_user.enterprise_customer.uuid,
enterprise_enrollment.enterprise_customer_user.user_id,
enterprise_enrollment.course_id,
('get_learner_data_records finished. No learner data was sent for this LMS User Id because '
'Degreed2 User ID not found for [{name}]'.format(
name=enterprise_enrollment.enterprise_customer_user.enterprise_customer.name
))))
return None
except Exception as e:
)
except Exception as e: # pylint: disable=broad-except
LOGGER.error(generate_formatted_log(
self.enterprise_configuration.channel_code(),
enterprise_enrollment.enterprise_customer_user.enterprise_customer.uuid,
Expand All @@ -111,3 +50,48 @@ def get_learner_data_records(
'[Degreed2Client] get_learner_data_records failed, possibly due to an invalid customer configuration. '
f'Error: {e}'
))
return None

if remote_id is not None:
Degreed2LearnerDataTransmissionAudit = apps.get_model(
'degreed2',
'Degreed2LearnerDataTransmissionAudit'
)
# We return two records here, one with the course key and one with the course run id, to account for
# uncertainty about the type of content (course vs. course run) that was sent to the integrated channel.
return [
Degreed2LearnerDataTransmissionAudit(
enterprise_course_enrollment_id=enterprise_enrollment.id,
degreed_user_email=enterprise_enrollment.enterprise_customer_user.user_email,
user_email=enterprise_enrollment.enterprise_customer_user.user_email,
course_id=get_course_id_for_enrollment(enterprise_enrollment),
completed_timestamp=completed_date,
degreed_completed_timestamp=degreed_completed_timestamp,
course_completed=course_completed,
grade=percent_grade,
enterprise_customer_uuid=enterprise_enrollment.enterprise_customer_user.enterprise_customer.uuid,
plugin_configuration_id=self.enterprise_configuration.id,
),
Degreed2LearnerDataTransmissionAudit(
enterprise_course_enrollment_id=enterprise_enrollment.id,
degreed_user_email=enterprise_enrollment.enterprise_customer_user.user_email,
user_email=enterprise_enrollment.enterprise_customer_user.user_email,
course_id=enterprise_enrollment.course_id,
completed_timestamp=completed_date,
degreed_completed_timestamp=degreed_completed_timestamp,
course_completed=course_completed,
grade=percent_grade,
enterprise_customer_uuid=enterprise_enrollment.enterprise_customer_user.enterprise_customer.uuid,
plugin_configuration_id=self.enterprise_configuration.id,
)
]
LOGGER.info(generate_formatted_log(
self.enterprise_configuration.channel_code(),
enterprise_enrollment.enterprise_customer_user.enterprise_customer.uuid,
enterprise_enrollment.enterprise_customer_user.user_id,
enterprise_enrollment.course_id,
('get_learner_data_records finished. No learner data was sent for this LMS User Id because '
'Degreed2 User ID not found for [{name}]'.format(
name=enterprise_enrollment.enterprise_customer_user.enterprise_customer.name
))))
return None

0 comments on commit 8bd3405

Please sign in to comment.