@method_decorator(enterprise_login_required)<EOL><INDENT>def post(self, request, enterprise_uuid, course_id):<DEDENT>
enterprise_customer, course, course_run, course_modes = self.get_base_details(<EOL>request, enterprise_uuid, course_id<EOL>)<EOL>enterprise_customer_user, __ = EnterpriseCustomerUser.objects.get_or_create(<EOL>enterprise_customer=enterprise_customer,<EOL>user_id=request.user.id<EOL>)<EOL>enterprise_customer_user.update_session(request)<EOL>data_sharing_consent = DataSharingConsent.objects.proxied_get(<EOL>username=enterprise_customer_user.username,<EOL>course_id=course_id,<EOL>enterprise_customer=enterprise_customer<EOL>)<EOL>try:<EOL><INDENT>enterprise_course_enrollment = EnterpriseCourseEnrollment.objects.get(<EOL>enterprise_customer_user__enterprise_customer=enterprise_customer,<EOL>enterprise_customer_user__user_id=request.user.id,<EOL>course_id=course_id<EOL>)<EOL><DEDENT>except EnterpriseCourseEnrollment.DoesNotExist:<EOL><INDENT>enterprise_course_enrollment = None<EOL><DEDENT>enterprise_catalog_uuid = request.POST.get('<STR_LIT>')<EOL>selected_course_mode_name = request.POST.get('<STR_LIT>')<EOL>cohort_name = request.POST.get('<STR_LIT>')<EOL>selected_course_mode = None<EOL>for course_mode in course_modes:<EOL><INDENT>if course_mode['<STR_LIT>'] == selected_course_mode_name:<EOL><INDENT>selected_course_mode = course_mode<EOL>break<EOL><DEDENT><DEDENT>if not selected_course_mode:<EOL><INDENT>return self.get_enterprise_course_enrollment_page(<EOL>request,<EOL>enterprise_customer,<EOL>course,<EOL>course_run,<EOL>course_modes,<EOL>enterprise_course_enrollment,<EOL>data_sharing_consent<EOL>)<EOL><DEDENT>user_consent_needed = get_data_sharing_consent(<EOL>enterprise_customer_user.username,<EOL>enterprise_customer.uuid,<EOL>course_id=course_id<EOL>).consent_required()<EOL>if not selected_course_mode.get('<STR_LIT>') and not user_consent_needed:<EOL><INDENT>if not enterprise_course_enrollment:<EOL><INDENT>enterprise_course_enrollment = EnterpriseCourseEnrollment.objects.create(<EOL>enterprise_customer_user=enterprise_customer_user,<EOL>course_id=course_id,<EOL>)<EOL>track_enrollment('<STR_LIT>', request.user.id, course_id, request.get_full_path())<EOL><DEDENT>client = EnrollmentApiClient()<EOL>client.enroll_user_in_course(<EOL>request.user.username,<EOL>course_id,<EOL>selected_course_mode_name,<EOL>cohort=cohort_name<EOL>)<EOL>return redirect(LMS_COURSEWARE_URL.format(course_id=course_id))<EOL><DEDENT>if user_consent_needed:<EOL><INDENT>query_string_params = {<EOL>'<STR_LIT>': selected_course_mode_name,<EOL>}<EOL>if enterprise_catalog_uuid:<EOL><INDENT>query_string_params.update({'<STR_LIT>': enterprise_catalog_uuid})<EOL><DEDENT>next_url = '<STR_LIT>'.format(<EOL>handle_consent_enrollment_url=reverse(<EOL>'<STR_LIT>', args=[enterprise_customer.uuid, course_id]<EOL>),<EOL>query_string=urlencode(query_string_params)<EOL>)<EOL>failure_url = reverse('<STR_LIT>', args=[enterprise_customer.uuid, course_id])<EOL>if request.META['<STR_LIT>']:<EOL><INDENT>failure_url = '<STR_LIT>'.format(<EOL>course_enrollment_url=reverse(<EOL>'<STR_LIT>', args=[enterprise_customer.uuid, course_id]<EOL>),<EOL>query_string=request.META['<STR_LIT>']<EOL>)<EOL><DEDENT>return redirect(<EOL>'<STR_LIT>'.format(<EOL>grant_data_sharing_url=reverse('<STR_LIT>'),<EOL>params=urlencode(<EOL>{<EOL>'<STR_LIT>': next_url,<EOL>'<STR_LIT>': failure_url,<EOL>'<STR_LIT>': enterprise_customer.uuid,<EOL>'<STR_LIT>': course_id,<EOL>}<EOL>)<EOL>)<EOL>)<EOL><DEDENT>premium_flow = LMS_START_PREMIUM_COURSE_FLOW_URL.format(course_id=course_id)<EOL>if enterprise_catalog_uuid:<EOL><INDENT>premium_flow += '<STR_LIT>'.format(<EOL>catalog_uuid=enterprise_catalog_uuid<EOL>)<EOL><DEDENT>return redirect(premium_flow)<EOL>
Process a submitted track selection form for the enterprise.