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): context = { 'platform_name': configuration_helpers.get_value('platform_name', settings.PLATFORM_NAME), 'zendesk_api_host': settings.ZENDESK_URL, 'access_token': 'DUMMY_ACCESS_TOKEN', # LEARNER-3450 'custom_fields': settings.ZENDESK_CUSTOM_FIELDS } # Tag all issues with LMS to distinguish channel in Zendesk; requested by student support team zendesk_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(".", "_") zendesk_tags.append("site_name_{site}".format(site=current_site_name)) if request.user.is_authenticated(): context['user_enrollments'] = CourseEnrollment.enrollments_for_user(request.user) enterprise_learner_data = enterprise_api.get_enterprise_learner_data(site=request.site, user=request.user) if enterprise_learner_data: zendesk_tags.append('enterprise_learner') context['zendesk_tags'] = zendesk_tags return render_to_response("support/contact_us.html", context)
def get(self, request): context = { 'platform_name': configuration_helpers.get_value('platform_name', settings.PLATFORM_NAME), 'zendesk_api_host': settings.ZENDESK_URL, 'access_token': 'DUMMY_ACCESS_TOKEN', # LEARNER-3450 'custom_fields': settings.ZENDESK_CUSTOM_FIELDS } # Tag all issues with LMS to distinguish channel in Zendesk; requested by student support team zendesk_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(".", "_") zendesk_tags.append( "site_name_{site}".format(site=current_site_name)) if request.user.is_authenticated(): context[ 'user_enrollments'] = CourseEnrollment.enrollments_for_user( request.user) enterprise_learner_data = enterprise_api.get_enterprise_learner_data( site=request.site, user=request.user) if enterprise_learner_data: zendesk_tags.append('enterprise_learner') context['zendesk_tags'] = zendesk_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_redirect_url_for_audit_enrollment(self, request, course_id): """ After a user has been enrolled in a course in an audit mode, determine the appropriate location to which they ought to be redirected, bearing in mind enterprise data sharing consent considerations. """ enterprise_learner_data = enterprise_api.get_enterprise_learner_data( site=request.site, user=request.user) if enterprise_learner_data: enterprise_learner = enterprise_learner_data[0] # If we have an enterprise learner, check to see if the current course is in the enterprise's catalog. is_course_in_enterprise_catalog = enterprise_api.is_course_in_enterprise_catalog( site=request.site, course_id=course_id, enterprise_catalog_id=enterprise_learner['enterprise_customer'] ['catalog']) # If the course is in the catalog, check for an existing Enterprise enrollment if is_course_in_enterprise_catalog: client = enterprise_api.EnterpriseApiClient() if not client.get_enterprise_course_enrollment( enterprise_learner['id'], course_id): # If there's no existing Enterprise enrollment, create one. client.post_enterprise_course_enrollment( request.user.username, course_id, None) # Check if consent is required, and generate a redirect URL to the # consent service if so; this function returns None if consent # is not required or has already been granted. consent_url = get_enterprise_consent_url( request, course_id, user=request.user, return_to='dashboard', course_specific_return=False, ) # If we got a redirect URL for consent, go there. if consent_url: return consent_url # If the enrollment isn't Enterprise-linked, or if consent isn't necessary, go to the Dashboard. return reverse('dashboard')
def _get_redirect_url_for_audit_enrollment(self, request, course_id): """ After a user has been enrolled in a course in an audit mode, determine the appropriate location to which they ought to be redirected, bearing in mind enterprise data sharing consent considerations. """ enterprise_learner_data = enterprise_api.get_enterprise_learner_data(site=request.site, user=request.user) if enterprise_learner_data: enterprise_learner = enterprise_learner_data[0] # If we have an enterprise learner, check to see if the current course is in the enterprise's catalog. is_course_in_enterprise_catalog = enterprise_api.is_course_in_enterprise_catalog( site=request.site, course_id=course_id, enterprise_catalog_id=enterprise_learner['enterprise_customer']['catalog'] ) # If the course is in the catalog, check for an existing Enterprise enrollment if is_course_in_enterprise_catalog: client = enterprise_api.EnterpriseApiClient() if not client.get_enterprise_course_enrollment(enterprise_learner['id'], course_id): # If there's no existing Enterprise enrollment, create one. client.post_enterprise_course_enrollment(request.user.username, course_id, None) # Check if consent is required, and generate a redirect URL to the # consent service if so; this function returns None if consent # is not required or has already been granted. consent_url = get_enterprise_consent_url( request, course_id, user=request.user, return_to='dashboard', course_specific_return=False, ) # If we got a redirect URL for consent, go there. if consent_url: return consent_url # If the enrollment isn't Enterprise-linked, or if consent isn't necessary, go to the Dashboard. return reverse('dashboard')
def submit_feedback(request): """ Create a Zendesk ticket or if not available, send an email with the feedback form fields. If feedback submission is not enabled, any request will raise `Http404`. If any configuration parameter (`ZENDESK_URL`, `ZENDESK_USER`, or `ZENDESK_API_KEY`) is missing, any request will raise an `Exception`. The request must be a POST request specifying `subject` and `details`. If the user is not authenticated, the request must also specify `name` and `email`. If the user is authenticated, the `name` and `email` will be populated from the user's information. If any required parameter is missing, a 400 error will be returned indicating which field is missing and providing an error message. If Zendesk ticket creation fails, 500 error will be returned with no body; if ticket creation succeeds, an empty successful response (200) will be returned. """ if not settings.FEATURES.get('ENABLE_FEEDBACK_SUBMISSION', False): raise Http404() if request.method != "POST": return HttpResponseNotAllowed(["POST"]) def build_error_response(status_code, field, err_msg): return HttpResponse(json.dumps({ "field": field, "error": err_msg }), status=status_code) required_fields = ["subject", "details"] if not request.user.is_authenticated(): required_fields += ["name", "email"] required_field_errs = { "subject": "Please provide a subject.", "details": "Please provide details.", "name": "Please provide your name.", "email": "Please provide a valid e-mail.", } for field in required_fields: if field not in request.POST or not request.POST[field]: return build_error_response(400, field, required_field_errs[field]) if not request.user.is_authenticated(): try: validate_email(request.POST["email"]) except ValidationError: return build_error_response(400, "email", required_field_errs["email"]) success = False context = get_feedback_form_context(request) #Update the tag info with 'enterprise_learner' if the user belongs to an enterprise customer. enterprise_learner_data = enterprise_api.get_enterprise_learner_data( site=request.site, user=request.user) if enterprise_learner_data: context["tags"]["learner_type"] = "enterprise_learner" support_backend = configuration_helpers.get_value( 'CONTACT_FORM_SUBMISSION_BACKEND', SUPPORT_BACKEND_ZENDESK) if support_backend == SUPPORT_BACKEND_EMAIL: try: send_mail(subject=render_to_string( 'emails/contact_us_feedback_email_subject.txt', context), message=render_to_string( 'emails/contact_us_feedback_email_body.txt', context), from_email=context["support_email"], recipient_list=[context["support_email"]], fail_silently=False) success = True except SMTPException: log.exception( 'Error sending feedback to contact_us email address.') success = False else: if not settings.ZENDESK_URL or not settings.ZENDESK_USER or not settings.ZENDESK_API_KEY: raise Exception("Zendesk enabled but not configured") custom_fields = None if settings.ZENDESK_CUSTOM_FIELDS: custom_field_context = _get_zendesk_custom_field_context( request, learner_data=enterprise_learner_data) custom_fields = _format_zendesk_custom_fields(custom_field_context) success = _record_feedback_in_zendesk( context["realname"], context["email"], context["subject"], context["details"], context["tags"], context["additional_info"], support_email=context["support_email"], custom_fields=custom_fields) _record_feedback_in_datadog(context["tags"]) return HttpResponse(status=(200 if success else 500))
def get(self, request, course_id, error=None): """Displays the course mode choice page. Args: request (`Request`): The Django Request object. course_id (unicode): The slash-separated course key. Keyword Args: error (unicode): If provided, display this error message on the page. Returns: Response """ course_key = CourseKey.from_string(course_id) # Check whether the user has access to this course # based on country access rules. embargo_redirect = embargo_api.redirect_if_blocked( course_key, user=request.user, ip_address=get_ip(request), url=request.path) if embargo_redirect: return redirect(embargo_redirect) enrollment_mode, is_active = CourseEnrollment.enrollment_mode_for_user( request.user, course_key) modes = CourseMode.modes_for_course_dict(course_key) ecommerce_service = EcommerceService() # We assume that, if 'professional' is one of the modes, it should be the *only* mode. # If there are both modes, default to non-id-professional. has_enrolled_professional = ( CourseMode.is_professional_slug(enrollment_mode) and is_active) if CourseMode.has_professional_mode( modes) and not has_enrolled_professional: purchase_workflow = request.GET.get("purchase_workflow", "single") verify_url = reverse('verify_student_start_flow', kwargs={'course_id': unicode(course_key)}) redirect_url = "{url}?purchase_workflow={workflow}".format( url=verify_url, workflow=purchase_workflow) if ecommerce_service.is_enabled(request.user): professional_mode = modes.get( CourseMode.NO_ID_PROFESSIONAL_MODE) or modes.get( CourseMode.PROFESSIONAL) if purchase_workflow == "single" and professional_mode.sku: redirect_url = ecommerce_service.checkout_page_url( professional_mode.sku) if purchase_workflow == "bulk" and professional_mode.bulk_sku: redirect_url = ecommerce_service.checkout_page_url( professional_mode.bulk_sku) return redirect(redirect_url) # If there isn't a verified mode available, then there's nothing # to do on this page. Send the user to the dashboard. if not CourseMode.has_verified_mode(modes): return redirect(reverse('dashboard')) # If a user has already paid, redirect them to the dashboard. if is_active and (enrollment_mode in CourseMode.VERIFIED_MODES + [CourseMode.NO_ID_PROFESSIONAL_MODE]): return redirect(reverse('dashboard')) donation_for_course = request.session.get("donation_for_course", {}) chosen_price = donation_for_course.get(unicode(course_key), None) course = modulestore().get_course(course_key) if CourseEnrollment.is_enrollment_closed(request.user, course): locale = to_locale(get_language()) enrollment_end_date = format_datetime(course.enrollment_end, 'short', locale=locale) params = urllib.urlencode({'course_closed': enrollment_end_date}) return redirect('{0}?{1}'.format(reverse('dashboard'), params)) # When a credit mode is available, students will be given the option # to upgrade from a verified mode to a credit mode at the end of the course. # This allows students who have completed photo verification to be eligible # for univerity credit. # Since credit isn't one of the selectable options on the track selection page, # we need to check *all* available course modes in order to determine whether # a credit mode is available. If so, then we show slightly different messaging # for the verified track. has_credit_upsell = any( CourseMode.is_credit_mode(mode) for mode in CourseMode.modes_for_course(course_key, only_selectable=False)) course_id = course_key.to_deprecated_string() context = { "course_modes_choose_url": reverse("course_modes_choose", kwargs={'course_id': course_id}), "modes": modes, "has_credit_upsell": has_credit_upsell, "course_name": course.display_name_with_default_escaped, "course_org": course.display_org_with_default, "course_num": course.display_number_with_default, "chosen_price": chosen_price, "error": error, "responsive": True, "nav_hidden": True, } title_content = _( "Congratulations! You are now enrolled in {course_name}").format( course_name=course.display_name_with_default_escaped) enterprise_learner_data = enterprise_api.get_enterprise_learner_data( site=request.site, user=request.user) if enterprise_learner_data: is_course_in_enterprise_catalog = enterprise_api.is_course_in_enterprise_catalog( site=request.site, course_id=course_id, enterprise_catalog_id=enterprise_learner_data[0] ['enterprise_customer']['catalog']) if is_course_in_enterprise_catalog: partner_names = partner_name = course.display_organization \ if course.display_organization else course.org enterprise_name = enterprise_learner_data[0][ 'enterprise_customer']['name'] organizations = organization_api.get_course_organizations( course_id=course.id) if organizations: partner_names = ' and '.join([ org.get('name', partner_name) for org in organizations ]) title_content = _( "Welcome, {username}! You are about to enroll in {course_name}," " from {partner_names}, sponsored by {enterprise_name}. Please select your enrollment" " information below.").format( username=request.user.username, course_name=course.display_name_with_default_escaped, partner_names=partner_names, enterprise_name=enterprise_name) context["title_content"] = title_content if "verified" in modes: verified_mode = modes["verified"] context["suggested_prices"] = [ decimal.Decimal(x.strip()) for x in verified_mode.suggested_prices.split(",") if x.strip() ] context["currency"] = verified_mode.currency.upper() context["min_price"] = verified_mode.min_price context["verified_name"] = verified_mode.name context["verified_description"] = verified_mode.description if verified_mode.sku: context[ "use_ecommerce_payment_flow"] = ecommerce_service.is_enabled( request.user) context[ "ecommerce_payment_page"] = ecommerce_service.payment_page_url( ) context["sku"] = verified_mode.sku context["bulk_sku"] = verified_mode.bulk_sku return render_to_response("course_modes/choose.html", context)
def submit_feedback(request): """ Create a Zendesk ticket or if not available, send an email with the feedback form fields. If feedback submission is not enabled, any request will raise `Http404`. If any configuration parameter (`ZENDESK_URL`, `ZENDESK_USER`, or `ZENDESK_API_KEY`) is missing, any request will raise an `Exception`. The request must be a POST request specifying `subject` and `details`. If the user is not authenticated, the request must also specify `name` and `email`. If the user is authenticated, the `name` and `email` will be populated from the user's information. If any required parameter is missing, a 400 error will be returned indicating which field is missing and providing an error message. If Zendesk ticket creation fails, 500 error will be returned with no body; if ticket creation succeeds, an empty successful response (200) will be returned. """ if not settings.FEATURES.get('ENABLE_FEEDBACK_SUBMISSION', False): raise Http404() if request.method != "POST": return HttpResponseNotAllowed(["POST"]) def build_error_response(status_code, field, err_msg): return HttpResponse(json.dumps({"field": field, "error": err_msg}), status=status_code) required_fields = ["subject", "details"] if not request.user.is_authenticated(): required_fields += ["name", "email"] required_field_errs = { "subject": "Please provide a subject.", "details": "Please provide details.", "name": "Please provide your name.", "email": "Please provide a valid e-mail.", } for field in required_fields: if field not in request.POST or not request.POST[field]: return build_error_response(400, field, required_field_errs[field]) if not request.user.is_authenticated(): try: validate_email(request.POST["email"]) except ValidationError: return build_error_response(400, "email", required_field_errs["email"]) success = False context = get_feedback_form_context(request) #Update the tag info with 'enterprise_learner' if the user belongs to an enterprise customer. enterprise_learner_data = enterprise_api.get_enterprise_learner_data(site=request.site, user=request.user) if enterprise_learner_data: context["tags"]["learner_type"] = "enterprise_learner" support_backend = configuration_helpers.get_value('CONTACT_FORM_SUBMISSION_BACKEND', SUPPORT_BACKEND_ZENDESK) if support_backend == SUPPORT_BACKEND_EMAIL: try: send_mail( subject=render_to_string('emails/contact_us_feedback_email_subject.txt', context), message=render_to_string('emails/contact_us_feedback_email_body.txt', context), from_email=context["support_email"], recipient_list=[context["support_email"]], fail_silently=False ) success = True except SMTPException: log.exception('Error sending feedback to contact_us email address.') success = False else: if not settings.ZENDESK_URL or not settings.ZENDESK_USER or not settings.ZENDESK_API_KEY: raise Exception("Zendesk enabled but not configured") custom_fields = None if settings.ZENDESK_CUSTOM_FIELDS: custom_field_context = _get_zendesk_custom_field_context(request, learner_data=enterprise_learner_data) custom_fields = _format_zendesk_custom_fields(custom_field_context) success = _record_feedback_in_zendesk( context["realname"], context["email"], context["subject"], context["details"], context["tags"], context["additional_info"], support_email=context["support_email"], custom_fields=custom_fields ) _record_feedback_in_datadog(context["tags"]) return HttpResponse(status=(200 if success else 500))
def get(self, request, course_id, error=None): """Displays the course mode choice page. Args: request (`Request`): The Django Request object. course_id (unicode): The slash-separated course key. Keyword Args: error (unicode): If provided, display this error message on the page. Returns: Response """ course_key = CourseKey.from_string(course_id) # Check whether the user has access to this course # based on country access rules. embargo_redirect = embargo_api.redirect_if_blocked( course_key, user=request.user, ip_address=get_ip(request), url=request.path ) if embargo_redirect: return redirect(embargo_redirect) enrollment_mode, is_active = CourseEnrollment.enrollment_mode_for_user(request.user, course_key) modes = CourseMode.modes_for_course_dict(course_key) ecommerce_service = EcommerceService() # We assume that, if 'professional' is one of the modes, it should be the *only* mode. # If there are both modes, default to non-id-professional. has_enrolled_professional = (CourseMode.is_professional_slug(enrollment_mode) and is_active) if CourseMode.has_professional_mode(modes) and not has_enrolled_professional: purchase_workflow = request.GET.get("purchase_workflow", "single") verify_url = reverse('verify_student_start_flow', kwargs={'course_id': unicode(course_key)}) redirect_url = "{url}?purchase_workflow={workflow}".format(url=verify_url, workflow=purchase_workflow) if ecommerce_service.is_enabled(request.user): professional_mode = modes.get(CourseMode.NO_ID_PROFESSIONAL_MODE) or modes.get(CourseMode.PROFESSIONAL) if purchase_workflow == "single" and professional_mode.sku: redirect_url = ecommerce_service.get_checkout_page_url(professional_mode.sku) if purchase_workflow == "bulk" and professional_mode.bulk_sku: redirect_url = ecommerce_service.get_checkout_page_url(professional_mode.bulk_sku) return redirect(redirect_url) # If there isn't a verified mode available, then there's nothing # to do on this page. Send the user to the dashboard. if not CourseMode.has_verified_mode(modes): # If the learner has arrived at this screen via the traditional enrollment workflow, # then they should already be enrolled in an audit mode for the course, assuming one has # been configured. However, alternative enrollment workflows have been introduced into the # system, such as third-party discovery. These workflows result in learners arriving # directly at this screen, and they will not necessarily be pre-enrolled in the audit mode. # In this particular case, Audit is the ONLY option available, and thus we need to ensure # that the learner is truly enrolled before we redirect them away to the dashboard. if len(modes) == 1 and modes.get(CourseMode.AUDIT): CourseEnrollment.enroll(request.user, course_key, CourseMode.AUDIT) return redirect(self._get_redirect_url_for_audit_enrollment(request, course_id)) return redirect(reverse('dashboard')) # If a user has already paid, redirect them to the dashboard. if is_active and (enrollment_mode in CourseMode.VERIFIED_MODES + [CourseMode.NO_ID_PROFESSIONAL_MODE]): return redirect(reverse('dashboard')) donation_for_course = request.session.get("donation_for_course", {}) chosen_price = donation_for_course.get(unicode(course_key), None) course = modulestore().get_course(course_key) if CourseEnrollment.is_enrollment_closed(request.user, course): locale = to_locale(get_language()) enrollment_end_date = format_datetime(course.enrollment_end, 'short', locale=locale) params = urllib.urlencode({'course_closed': enrollment_end_date}) return redirect('{0}?{1}'.format(reverse('dashboard'), params)) # When a credit mode is available, students will be given the option # to upgrade from a verified mode to a credit mode at the end of the course. # This allows students who have completed photo verification to be eligible # for univerity credit. # Since credit isn't one of the selectable options on the track selection page, # we need to check *all* available course modes in order to determine whether # a credit mode is available. If so, then we show slightly different messaging # for the verified track. has_credit_upsell = any( CourseMode.is_credit_mode(mode) for mode in CourseMode.modes_for_course(course_key, only_selectable=False) ) course_id = course_key.to_deprecated_string() context = { "course_modes_choose_url": reverse( "course_modes_choose", kwargs={'course_id': course_id} ), "modes": modes, "has_credit_upsell": has_credit_upsell, "course_name": course.display_name_with_default_escaped, "course_org": course.display_org_with_default, "course_num": course.display_number_with_default, "chosen_price": chosen_price, "error": error, "responsive": True, "nav_hidden": True, } title_content = _("Congratulations! You are now enrolled in {course_name}").format( course_name=course.display_name_with_default_escaped ) enterprise_learner_data = enterprise_api.get_enterprise_learner_data(site=request.site, user=request.user) if enterprise_learner_data: enterprise_learner = enterprise_learner_data[0] is_course_in_enterprise_catalog = enterprise_api.is_course_in_enterprise_catalog( site=request.site, course_id=course_id, enterprise_catalog_id=enterprise_learner['enterprise_customer']['catalog'] ) if is_course_in_enterprise_catalog: partner_names = partner_name = course.display_organization \ if course.display_organization else course.org enterprise_name = enterprise_learner['enterprise_customer']['name'] organizations = organization_api.get_course_organizations(course_id=course.id) if organizations: partner_names = ' and '.join([org.get('name', partner_name) for org in organizations]) title_content = _("Welcome, {username}! You are about to enroll in {course_name}," " from {partner_names}, sponsored by {enterprise_name}. Please select your enrollment" " information below.").format( username=request.user.username, course_name=course.display_name_with_default_escaped, partner_names=partner_names, enterprise_name=enterprise_name ) # Hide the audit modes for this enterprise customer, if necessary if not enterprise_learner['enterprise_customer'].get('enable_audit_enrollment'): for audit_mode in CourseMode.AUDIT_MODES: modes.pop(audit_mode, None) context["title_content"] = title_content if "verified" in modes: verified_mode = modes["verified"] context["suggested_prices"] = [ decimal.Decimal(x.strip()) for x in verified_mode.suggested_prices.split(",") if x.strip() ] context["currency"] = verified_mode.currency.upper() context["min_price"] = verified_mode.min_price context["verified_name"] = verified_mode.name context["verified_description"] = verified_mode.description if verified_mode.sku: context["use_ecommerce_payment_flow"] = ecommerce_service.is_enabled(request.user) context["ecommerce_payment_page"] = ecommerce_service.payment_page_url() context["sku"] = verified_mode.sku context["bulk_sku"] = verified_mode.bulk_sku return render_to_response("course_modes/choose.html", context)
def account_settings_context(request): """ Context for the account settings page. Args: request: The request object. Returns: dict """ user = request.user year_of_birth_options = [(unicode(year), unicode(year)) for year in UserProfile.VALID_YEARS] try: user_orders = get_user_orders(user) except: # pylint: disable=bare-except log.exception('Error fetching order history from Otto.') # Return empty order list as account settings page expect a list and # it will be broken if exception raised user_orders = [] context = { 'auth': {}, 'duplicate_provider': None, 'nav_hidden': True, 'fields': { 'country': { 'options': list(countries), }, 'gender': { 'options': [(choice[0], _(choice[1])) for choice in UserProfile.GENDER_CHOICES], # pylint: disable=translation-of-non-string }, 'language': { 'options': released_languages(), }, 'level_of_education': { 'options': [(choice[0], _(choice[1])) for choice in UserProfile.LEVEL_OF_EDUCATION_CHOICES], # pylint: disable=translation-of-non-string }, 'password': { 'url': reverse('password_reset'), }, 'year_of_birth': { 'options': year_of_birth_options, }, 'preferred_language': { 'options': all_languages(), }, 'time_zone': { 'options': TIME_ZONE_CHOICES, } }, 'platform_name': configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME), 'password_reset_support_link': configuration_helpers.get_value('PASSWORD_RESET_SUPPORT_LINK', settings.PASSWORD_RESET_SUPPORT_LINK) or settings.SUPPORT_SITE_LINK, 'user_accounts_api_url': reverse("accounts_api", kwargs={'username': user.username}), 'user_preferences_api_url': reverse('preferences_api', kwargs={'username': user.username}), 'disable_courseware_js': True, 'show_program_listing': ProgramsApiConfig.is_enabled(), 'show_dashboard_tabs': True, 'order_history': user_orders, 'extended_profile_fields': _get_extended_profile_fields(), } enterprise_customer_name = None sync_learner_profile_data = False enterprise_learner_data = get_enterprise_learner_data(site=request.site, user=request.user) if enterprise_learner_data: enterprise_customer_name = enterprise_learner_data[0][ 'enterprise_customer']['name'] enterprise_idp = enterprise_learner_data[0]['enterprise_customer'][ 'identity_provider'] identity_provider = third_party_auth.provider.Registry.get( provider_id=enterprise_idp) sync_learner_profile_data = identity_provider.sync_learner_profile_data if identity_provider else False context['sync_learner_profile_data'] = sync_learner_profile_data context['edx_support_url'] = configuration_helpers.get_value( 'SUPPORT_SITE_LINK', settings.SUPPORT_SITE_LINK) context['enterprise_name'] = enterprise_customer_name context['enterprise_readonly_account_fields'] = { 'fields': settings.ENTERPRISE_READONLY_ACCOUNT_FIELDS } if third_party_auth.is_enabled(): # If the account on the third party provider is already connected with another edX account, # we display a message to the user. context['duplicate_provider'] = pipeline.get_duplicate_provider( messages.get_messages(request)) auth_states = pipeline.get_provider_user_states(user) context['auth']['providers'] = [ { 'id': state.provider.provider_id, 'name': state.provider.name, # The name of the provider e.g. Facebook 'connected': state. has_account, # Whether the user's edX account is connected with the provider. # If the user is not connected, they should be directed to this page to authenticate # with the particular provider, as long as the provider supports initiating a login. 'connect_url': pipeline.get_login_url( state.provider.provider_id, pipeline.AUTH_ENTRY_ACCOUNT_SETTINGS, # The url the user should be directed to after the auth process has completed. redirect_url=reverse('account_settings'), ), 'accepts_logins': state.provider.accepts_logins, # If the user is connected, sending a POST request to this url removes the connection # information for this provider from their edX account. 'disconnect_url': pipeline.get_disconnect_url(state.provider.provider_id, state.association_id), # We only want to include providers if they are either currently available to be logged # in with, or if the user is already authenticated with them. } for state in auth_states if state.provider.display_for_login or state.has_account ] return context