@@ -1375,21 +1375,37 @@ class LinkedInAddToProfileConfiguration(ConfigurationModel):
13751375 ),
13761376 )
13771377
1378+ @property
1379+ def share_settings (self ):
1380+ """
1381+ Initialize share_settings once for reuse across methods
1382+ """
1383+ if self ._share_settings is None :
1384+ self ._share_settings = configuration_helpers .get_value (
1385+ 'SOCIAL_SHARING_SETTINGS' ,
1386+ settings .SOCIAL_SHARING_SETTINGS
1387+ )
1388+ return self ._share_settings
1389+
1390+ def __init__ (self , * args , ** kwargs ):
1391+ super ().__init__ (* args , ** kwargs )
1392+ self ._share_settings = None
1393+
13781394 def is_enabled (self , * key_fields ): # pylint: disable=arguments-differ
13791395 """
13801396 Checks both the model itself and share_settings to see if LinkedIn Add to Profile is enabled
13811397 """
13821398 enabled = super ().is_enabled (* key_fields )
1383- share_settings = configuration_helpers .get_value ('SOCIAL_SHARING_SETTINGS' , settings .SOCIAL_SHARING_SETTINGS )
1384- return share_settings .get ('CERTIFICATE_LINKEDIN' , enabled )
1399+ return self .share_settings .get ('CERTIFICATE_LINKEDIN' , enabled )
1400+
1401+ def add_to_profile_url (self , course , cert_mode , cert_url , certificate = None ):
13851402
1386- def add_to_profile_url (self , course_name , cert_mode , cert_url , certificate = None ):
13871403 """
13881404 Construct the URL for the "add to profile" button. This will autofill the form based on
13891405 the params provided.
13901406
13911407 Arguments:
1392- course_name (str ): The display name of the course .
1408+ course (CourseOverview ): Course/CourseOverview Object .
13931409 cert_mode (str): The course mode of the user's certificate (e.g. "verified", "honor", "professional")
13941410 cert_url (str): The URL for the certificate.
13951411
@@ -1398,11 +1414,11 @@ def add_to_profile_url(self, course_name, cert_mode, cert_url, certificate=None)
13981414 If provided, this function will also autofill the certId and issue date for the cert.
13991415 """
14001416 params = {
1401- 'name' : self ._cert_name (course_name , cert_mode ),
1417+ 'name' : self ._cert_name (course . display_name , cert_mode ),
14021418 'certUrl' : cert_url ,
14031419 }
14041420
1405- params .update (self ._organization_information ())
1421+ params .update (self ._organization_information (course ))
14061422
14071423 if certificate :
14081424 params .update ({
@@ -1426,28 +1442,45 @@ def _cert_name(self, course_name, cert_mode):
14261442 Returns:
14271443 str: The formatted string to display for the name field on the LinkedIn Add to Profile dialog.
14281444 """
1429- default_cert_name = self .MODE_TO_CERT_NAME .get (cert_mode , _ ('{platform_name} Certificate for {course_name}' ))
1445+ default_cert_name = self .MODE_TO_CERT_NAME .get (
1446+ cert_mode , _ ('{platform_name} Certificate for {course_name}' )
1447+ )
14301448 # Look for an override of the certificate name in the SOCIAL_SHARING_SETTINGS setting
1431- share_settings = configuration_helpers .get_value ('SOCIAL_SHARING_SETTINGS' , settings .SOCIAL_SHARING_SETTINGS )
1432- cert_name = share_settings .get ('CERTIFICATE_LINKEDIN_MODE_TO_CERT_NAME' , {}).get (cert_mode , default_cert_name )
1449+ cert_name = self .share_settings .get (
1450+ 'CERTIFICATE_LINKEDIN_MODE_TO_CERT_NAME' , {}
1451+ ).get (cert_mode , default_cert_name )
14331452
14341453 return cert_name .format (
14351454 platform_name = configuration_helpers .get_value ('platform_name' , settings .PLATFORM_NAME ),
14361455 course_name = course_name
14371456 )
14381457
1439- def _organization_information (self ):
1458+ def _organization_information (self , course = None ):
14401459 """
1441- Returns organization information for use in the URL parameters for add to profile.
1460+ Returns organization information for use in the URL parameters for add to
1461+ profile. By default when sharing to LinkedIn, Platform Name and/or Platform
1462+ LINKEDIN_COMPANY_ID will be used. If Course specific Organization Name is
1463+ prefered when sharing Certificate to linkedIn the flag for that
1464+ CERTIFICATE_LINKEDIN_DEFAULTS_TO_COURSE_ORGANIZATION_NAME should be set
1465+ to True alongside other LinkedIn settings
14421466
14431467 Returns:
1444- dict: Either the organization ID on LinkedIn or the organization's name
1468+ dict: Either the organization ID on LinkedIn, the organization's name or
1469+ organization name associated to a specific course
14451470 Will be used to prefill the organization on the add to profile action.
14461471 """
1447- org_id = configuration_helpers .get_value ('LINKEDIN_COMPANY_ID' , self .company_identifier )
1472+ prefer_course_organization_name = self .share_settings .get (
1473+ 'CERTIFICATE_LINKEDIN_DEFAULTS_TO_COURSE_ORGANIZATION_NAME' , False
1474+ )
1475+ if (prefer_course_organization_name and course ):
1476+ return {"organizationName" : course .display_organization }
1477+
1478+ org_id = configuration_helpers .get_value (
1479+ "LINKEDIN_COMPANY_ID" , self .company_identifier
1480+ )
14481481 # Prefer organization ID per documentation at https://addtoprofile.linkedin.com/
14491482 if org_id :
1450- return {' organizationId' : org_id }
1483+ return {" organizationId" : org_id }
14511484 return {'organizationName' : configuration_helpers .get_value ('platform_name' , settings .PLATFORM_NAME )}
14521485
14531486
0 commit comments