def get_base_template_context(site): """ Dict with entries needed for all templates that use the base template. """ # When on LMS and a dashboard is available, use that as the dashboard url. # Otherwise, use the home url instead. try: dashboard_url = reverse('dashboard') except NoReverseMatch: dashboard_url = reverse('home') return { # Platform information 'homepage_url': marketing_link('ROOT'), 'dashboard_url': dashboard_url, 'template_revision': getattr(settings, 'EDX_PLATFORM_REVISION', None), 'platform_name': get_config_value_from_site_or_settings( 'PLATFORM_NAME', site=site, site_config_name='platform_name', ), 'contact_email': get_config_value_from_site_or_settings( 'CONTACT_EMAIL', site=site, site_config_name='contact_email'), 'contact_mailing_address': get_config_value_from_site_or_settings( 'CONTACT_MAILING_ADDRESS', site=site, site_config_name='contact_mailing_address'), 'social_media_urls': get_config_value_from_site_or_settings('SOCIAL_MEDIA_FOOTER_URLS', site=site), 'mobile_store_urls': get_config_value_from_site_or_settings('MOBILE_STORE_URLS', site=site), }
def _get_tracking_id(self): tracking_id = get_config_value_from_site_or_settings( "GOOGLE_ANALYTICS_ACCOUNT", site=self.site) if tracking_id is None: tracking_id = get_config_value_from_site_or_settings( "GOOGLE_ANALYTICS_TRACKING_ID", site=self.site) return tracking_id
def get_base_template_context(site): """ Dict with entries needed for all templates that use the base template. """ # When on LMS and a dashboard is available, use that as the dashboard url. # Otherwise, use the home url instead. try: dashboard_url = reverse('dashboard') except NoReverseMatch: dashboard_url = reverse('home') return { # Platform information 'homepage_url': marketing_link('ROOT'), 'dashboard_url': dashboard_url, 'template_revision': getattr(settings, 'EDX_PLATFORM_REVISION', None), 'platform_name': get_config_value_from_site_or_settings( 'PLATFORM_NAME', site=site, site_config_name='platform_name', ), 'contact_email': get_config_value_from_site_or_settings( 'CONTACT_EMAIL', site=site, site_config_name='contact_email'), 'contact_mailing_address': get_config_value_from_site_or_settings( 'CONTACT_MAILING_ADDRESS', site=site, site_config_name='contact_mailing_address'), 'social_media_urls': get_config_value_from_site_or_settings('SOCIAL_MEDIA_FOOTER_URLS', site=site), 'mobile_store_urls': get_config_value_from_site_or_settings('MOBILE_STORE_URLS', site=site), }
def get_base_template_context(site): """ Dict with entries needed for all templates that use the base template. """ # When on LMS and a dashboard is available, use that as the dashboard url. # Otherwise, use the home url instead. try: dashboard_url = reverse('dashboard') except NoReverseMatch: dashboard_url = reverse('home') contact_mailing_address = configuration_helpers.get_value( 'CONTACT_MAILING_ADDRESS') if not contact_mailing_address: contact_mailing_address = get_config_value_from_site_or_settings( 'CONTACT_MAILING_ADDRESS', site=site, site_config_name='CONTACT_MAILING_ADDRESS') return { # Platform information 'homepage_url': marketing_link('ROOT'), 'dashboard_url': dashboard_url, 'template_revision': getattr(settings, 'EDX_PLATFORM_REVISION', None), 'platform_name': get_config_value_from_site_or_settings( 'PLATFORM_NAME', site=site, site_config_name='platform_name', ), 'contact_email': get_config_value_from_site_or_settings( 'CONTACT_EMAIL', site=site, site_config_name='contact_email'), 'contact_mailing_address': contact_mailing_address, 'social_media_urls': get_config_value_from_site_or_settings('SOCIAL_MEDIA_FOOTER_URLS', site=site), 'mobile_store_urls': get_config_value_from_site_or_settings('MOBILE_STORE_URLS', site=site), # Context processor values for dynamic theming 'edly_colors_config': get_theme_colors(), 'edly_fonts_config': configuration_helpers.get_dict('FONTS', DEFAULT_FONTS_DICT), 'edly_branding_config': configuration_helpers.get_dict('BRANDING', DEFAULT_BRANDING_DICT), # Context processor value for edly app 'edly_copyright_text': configuration_helpers.get_value('EDLY_COPYRIGHT_TEXT') }
def generate_image_url(self): """ A URL to a clear image that can be embedded in HTML documents to track email open events. The query string of this URL is used to capture data about the email and visitor. """ parameters = {} fields = attr.fields(self.__class__) for attribute in fields: value = getattr(self, attribute.name, None) if value is not None and 'param_name' in attribute.metadata: parameter_name = attribute.metadata['param_name'] parameters[parameter_name] = str(value) tracking_id = self._get_tracking_id() if tracking_id is None: return None parameters['tid'] = tracking_id user_id_dimension = get_config_value_from_site_or_settings( "GOOGLE_ANALYTICS_USER_ID_CUSTOM_DIMENSION", site=self.site, ) if user_id_dimension is not None and self.user_id is not None: parameter_name = f'cd{user_id_dimension}' parameters[parameter_name] = self.user_id if self.course_id is not None and self.event_label is None: param_name = fields.event_label.metadata['param_name'] parameters[param_name] = str(self.course_id) return f"https://www.google-analytics.com/collect?{urlencode(parameters)}"
def generate_image_url(self): """ A URL to a clear image that can be embedded in HTML documents to track email open events. The query string of this URL is used to capture data about the email and visitor. """ parameters = {} fields = attr.fields(self.__class__) for attribute in fields: value = getattr(self, attribute.name, None) if value is not None and 'param_name' in attribute.metadata: parameter_name = attribute.metadata['param_name'] parameters[parameter_name] = str(value) tracking_id = self._get_tracking_id() if tracking_id is None: return None parameters['tid'] = tracking_id user_id_dimension = get_config_value_from_site_or_settings( "GOOGLE_ANALYTICS_USER_ID_CUSTOM_DIMENSION", site=self.site, ) if user_id_dimension is not None and self.user_id is not None: parameter_name = 'cd{0}'.format(user_id_dimension) parameters[parameter_name] = self.user_id if self.course_id is not None and self.event_label is None: param_name = fields.event_label.metadata['param_name'] parameters[param_name] = unicode(self.course_id) return u"https://www.google-analytics.com/collect?{params}".format(params=urlencode(parameters))
def get_base_template_context(site): """ Dict with entries needed for all templates that use the base template. """ return { # Platform information 'homepage_url': marketing_link('ROOT'), 'dashboard_url': reverse('dashboard'), 'template_revision': getattr(settings, 'EDX_PLATFORM_REVISION', None), 'platform_name': get_config_value_from_site_or_settings( 'PLATFORM_NAME', site=site, site_config_name='platform_name', ), 'contact_mailing_address': get_config_value_from_site_or_settings( 'CONTACT_MAILING_ADDRESS', site=site, site_config_name='contact_mailing_address'), 'social_media_urls': get_config_value_from_site_or_settings('SOCIAL_MEDIA_FOOTER_URLS', site=site), 'mobile_store_urls': get_config_value_from_site_or_settings('MOBILE_STORE_URLS', site=site), }
def retrieve_last_sitewide_block_completed(username): """ Completion utility From a string 'username' or object User retrieve the last course block marked as 'completed' and construct a URL :param username: str(username) or obj(User) :return: block_lms_url """ if not completion_waffle.waffle().is_enabled( completion_waffle.ENABLE_COMPLETION_TRACKING): return if not isinstance(username, User): userobj = User.objects.get(username=username) else: userobj = username latest_completions_by_course = BlockCompletion.latest_blocks_completed_all_courses( userobj) known_site_configs = [ other_site_config.get_value('course_org_filter') for other_site_config in SiteConfiguration.objects.all() if other_site_config.get_value('course_org_filter') ] current_site_configuration = get_config_value_from_site_or_settings( name='course_org_filter', site=get_current_site()) # courses.edx.org has no 'course_org_filter' # however the courses within DO, but those entries are not found in # known_site_configs, which are White Label sites # This is necessary because the WL sites and courses.edx.org # have the same AWS RDS mySQL instance candidate_course = None candidate_block_key = None latest_date = None # Go through dict, find latest for course, [modified_date, block_key] in latest_completions_by_course.items(): if not current_site_configuration: # This is a edx.org if course.org in known_site_configs: continue if not latest_date or modified_date > latest_date: candidate_course = course candidate_block_key = block_key latest_date = modified_date else: # This is a White Label site, and we should find candidates from the same site if course.org not in current_site_configuration: # Not the same White Label, or a edx.org course continue if not latest_date or modified_date > latest_date: candidate_course = course candidate_block_key = block_key latest_date = modified_date if not candidate_course: return lms_root = SiteConfiguration.get_value_for_org(candidate_course.org, "LMS_ROOT_URL", settings.LMS_ROOT_URL) try: item = modulestore().get_item(candidate_block_key, depth=1) except ItemNotFoundError: item = None if not (lms_root and item): return return u"{lms_root}/courses/{course_key}/jump_to/{location}".format( lms_root=lms_root, course_key=text_type(item.location.course_key), location=text_type(item.location), )
def retrieve_last_sitewide_block_completed(user): """ Completion utility From a string 'username' or object User retrieve the last course block marked as 'completed' and construct a URL :param user: obj(User) :return: block_lms_url """ if not completion_waffle.waffle().is_enabled(completion_waffle.ENABLE_COMPLETION_TRACKING): return latest_completions_by_course = BlockCompletion.latest_blocks_completed_all_courses(user) known_site_configs = [ other_site_config.get_value('course_org_filter') for other_site_config in SiteConfiguration.objects.all() if other_site_config.get_value('course_org_filter') ] current_site_configuration = get_config_value_from_site_or_settings( name='course_org_filter', site=get_current_site() ) # courses.edx.org has no 'course_org_filter' # however the courses within DO, but those entries are not found in # known_site_configs, which are White Label sites # This is necessary because the WL sites and courses.edx.org # have the same AWS RDS mySQL instance candidate_course = None candidate_block_key = None latest_date = None # Go through dict, find latest for course, [modified_date, block_key] in latest_completions_by_course.items(): if not current_site_configuration: # This is a edx.org if course.org in known_site_configs: continue if not latest_date or modified_date > latest_date: candidate_course = course candidate_block_key = block_key latest_date = modified_date else: # This is a White Label site, and we should find candidates from the same site if course.org not in current_site_configuration: # Not the same White Label, or a edx.org course continue if not latest_date or modified_date > latest_date: candidate_course = course candidate_block_key = block_key latest_date = modified_date if not candidate_course: return lms_root = SiteConfiguration.get_value_for_org(candidate_course.org, "LMS_ROOT_URL", settings.LMS_ROOT_URL) try: item = modulestore().get_item(candidate_block_key, depth=1) except ItemNotFoundError: item = None if not (lms_root and item): return return u"{lms_root}/courses/{course_key}/jump_to/{location}".format( lms_root=lms_root, course_key=text_type(item.location.course_key), location=text_type(item.location), )
def _get_tracking_id(self): tracking_id = get_config_value_from_site_or_settings("GOOGLE_ANALYTICS_ACCOUNT", site=self.site) if tracking_id is None: tracking_id = get_config_value_from_site_or_settings("GOOGLE_ANALYTICS_TRACKING_ID", site=self.site) return tracking_id