def test_get_current_site_configuration_values(self): """ Test get_current_site_configuration_values helper function """ site_values = configuration_helpers.get_current_site_configuration_values( ) self.assertTrue(isinstance(site_values, dict)) # without any site configuration it should return empty dict self.assertEqual(site_values, {}) with with_site_configuration_context(configuration=test_config): site_values = configuration_helpers.get_current_site_configuration_values( ) self.assertEqual(site_values, test_config)
def generate_activation_email_context(user, registration): """ Constructs a dictionary for use in activation email contexts Arguments: user (User): Currently logged-in user registration (Registration): Registration object for the currently logged-in user """ context = get_base_template_context(None) context.update({ 'name': user.profile.name, 'key': registration.activation_key, 'lms_url': configuration_helpers.get_value('LMS_ROOT_URL', settings.LMS_ROOT_URL), 'platform_name': configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME), 'contact_mailing_address': configuration_helpers.get_value('contact_mailing_address', settings.CONTACT_MAILING_ADDRESS), 'support_url': configuration_helpers.get_value('ACTIVATION_EMAIL_SUPPORT_LINK', settings.ACTIVATION_EMAIL_SUPPORT_LINK) or settings.SUPPORT_SITE_LINK, 'support_email': configuration_helpers.get_value('CONTACT_EMAIL', settings.CONTACT_EMAIL), 'site_configuration_values': configuration_helpers.get_current_site_configuration_values(), }) return context
def get_email_params(course, auto_enroll, secure=True, course_key=None, display_name=None): """ Generate parameters used when parsing email templates. `auto_enroll` is a flag for auto enrolling non-registered students: (a `boolean`) Returns a dict of parameters """ protocol = 'https' if secure else 'http' course_key = course_key or str(course.id) display_name = display_name or Text(course.display_name_with_default) stripped_site_name = configuration_helpers.get_value( 'SITE_NAME', settings.SITE_NAME ) # TODO: Use request.build_absolute_uri rather than '{proto}://{site}{path}'.format # and check with the Services team that this works well with microsites registration_url = '{proto}://{site}{path}'.format( proto=protocol, site=stripped_site_name, path=reverse('register_user') ) course_url = '{proto}://{site}{path}'.format( proto=protocol, site=stripped_site_name, path=reverse('course_root', kwargs={'course_id': course_key}) ) # We can't get the url to the course's About page if the marketing site is enabled. course_about_url = None if not settings.FEATURES.get('ENABLE_MKTG_SITE', False): course_about_url = '{proto}://{site}{path}'.format( proto=protocol, site=stripped_site_name, path=reverse('about_course', kwargs={'course_id': course_key}) ) is_shib_course = uses_shib(course) # Collect mailing address and platform name to pass as context contact_mailing_address = configuration_helpers.get_value( 'contact_mailing_address', settings.CONTACT_MAILING_ADDRESS ) platform_name = configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME) # Composition of email email_params = { 'site_name': stripped_site_name, 'registration_url': registration_url, 'course': course, 'display_name': display_name, 'auto_enroll': auto_enroll, 'course_url': course_url, 'course_about_url': course_about_url, 'is_shib_course': is_shib_course, 'contact_mailing_address': contact_mailing_address, 'platform_name': platform_name, 'site_configuration_values': configuration_helpers.get_current_site_configuration_values(), } return email_params