def get_course_enrollments(user, org_whitelist, org_blacklist): """ Given a user, return a filtered set of his or her course enrollments. Arguments: user (User): the user in question. org_whitelist (list[str]): If not None, ONLY courses of these orgs will be returned. org_blacklist (list[str]): Courses of these orgs will be excluded. Returns: generator[CourseEnrollment]: a sequence of enrollments to be displayed on the user's dashboard. """ for enrollment in CourseEnrollment.enrollments_for_user_with_overviews_preload( user): # If the course is missing or broken, log an error and skip it. course_overview = enrollment.course_overview if not course_overview: log.error("User %s enrolled in broken or non-existent course %s", user.username, enrollment.course_id) continue # Filter out anything that is not in the whitelist. if org_whitelist and course_overview.location.org not in org_whitelist: continue # Conversely, filter out any enrollments in the blacklist. elif org_blacklist and course_overview.location.org in org_blacklist: continue # Else, include the enrollment. else: yield enrollment
def get(self, request): context = { 'platform_name': configuration_helpers.get_value('platform_name', settings.PLATFORM_NAME), 'support_email': configuration_helpers.get_value('CONTACT_EMAIL', settings.CONTACT_EMAIL), 'custom_fields': settings.ZENDESK_CUSTOM_FIELDS } # Tag all issues with LMS to distinguish channel which received the request tags = ['LMS'] # Per edX support, we would like to be able to route feedback items by site via tagging current_site_name = configuration_helpers.get_value("SITE_NAME") if current_site_name: current_site_name = current_site_name.replace(".", "_") tags.append("site_name_{site}".format(site=current_site_name)) if request.user.is_authenticated(): context['course_id'] = request.session.get('course_id', '') context[ 'user_enrollments'] = CourseEnrollment.enrollments_for_user_with_overviews_preload( request.user) enterprise_learner_data = enterprise_api.get_enterprise_learner_data( user=request.user) if enterprise_learner_data: tags.append('enterprise_learner') context['tags'] = tags return render_to_response("support/contact_us.html", context)
def get(self, request): if not configuration_helpers.get_value('CONTACT_US_PAGE', True): raise Http404 context = { 'platform_name': configuration_helpers.get_value('platform_name', settings.PLATFORM_NAME), 'support_email': configuration_helpers.get_value('CONTACT_EMAIL', settings.CONTACT_EMAIL), 'custom_fields': settings.ZENDESK_CUSTOM_FIELDS } # Tag all issues with LMS to distinguish channel which received the request tags = ['LMS'] # Per edX support, we would like to be able to route feedback items by site via tagging current_site_name = configuration_helpers.get_value("SITE_NAME") if current_site_name: current_site_name = current_site_name.replace(".", "_") tags.append("site_name_{site}".format(site=current_site_name)) if request.user.is_authenticated: context['course_id'] = request.session.get('course_id', '') context['user_enrollments'] = CourseEnrollment.enrollments_for_user_with_overviews_preload(request.user) enterprise_learner_data = enterprise_api.get_enterprise_learner_data(user=request.user) if enterprise_learner_data: tags.append('enterprise_learner') context['tags'] = tags return render_to_response("support/contact_us.html", context)
def get_course_enrollments(user, org_whitelist, org_blacklist): """ Given a user, return a filtered set of his or her course enrollments. Arguments: user (User): the user in question. org_whitelist (list[str]): If not None, ONLY courses of these orgs will be returned. org_blacklist (list[str]): Courses of these orgs will be excluded. Returns: generator[CourseEnrollment]: a sequence of enrollments to be displayed on the user's dashboard. """ for enrollment in CourseEnrollment.enrollments_for_user_with_overviews_preload( user): # If the course is missing or broken, log an error and skip it. course_overview = enrollment.course_overview if not course_overview: log.error("User %s enrolled in broken or non-existent course %s", user.username, enrollment.course_id) continue # [COLARAZ_CUSTOM] # To restrict users from viewing unallowed courses. if settings.FEATURES.get('ORGANIZATIONS_APP', False): if org_whitelist and OrganizationCourse.objects.filter( course_id=str(course_overview), organization__short_name__in=org_whitelist, active=True): yield enrollment else: continue else: # Filter out anything that is not in the whitelist. if org_whitelist and course_overview.location.org not in org_whitelist: continue # Conversely, filter out any enrollments in the blacklist. elif org_blacklist and course_overview.location.org in org_blacklist: continue # Else, include the enrollment. else: yield enrollment
def get_course_enrollments(user, org_whitelist, org_blacklist): """ Given a user, return a filtered set of his or her course enrollments. Arguments: user (User): the user in question. org_whitelist (list[str]): If not None, ONLY courses of these orgs will be returned. org_blacklist (list[str]): Courses of these orgs will be excluded. Returns: generator[CourseEnrollment]: a sequence of enrollments to be displayed on the user's dashboard. """ for enrollment in CourseEnrollment.enrollments_for_user_with_overviews_preload(user): # If the course is missing or broken, log an error and skip it. course_overview = enrollment.course_overview if not course_overview: log.error( "User %s enrolled in broken or non-existent course %s", user.username, enrollment.course_id ) continue # Filter out anything that is not in the whitelist. if org_whitelist and course_overview.location.org not in org_whitelist: continue # Conversely, filter out any enrollments in the blacklist. elif org_blacklist and course_overview.location.org in org_blacklist: continue # Else, include the enrollment. else: yield enrollment