From 805c325653a5e9ce107daa9fcc4d4befd00e9d00 Mon Sep 17 00:00:00 2001
From: Julia Hansbrough <julia@edx.org>
Date: Fri, 8 Aug 2014 17:51:22 +0000
Subject: [PATCH] Update redirect and wording for prof ed

- Changes registraiton button text for professional ed courses
- Professional ed courses do not see "choose your track" page; go straight to verification flow
---
 .../course_modes/tests/test_views.py          | 42 +++++++++++++++++++
 common/djangoapps/course_modes/views.py       | 18 +++++++-
 lms/djangoapps/courseware/views.py            |  2 +-
 .../courseware/mktg_course_about.html         | 10 ++++-
 4 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/common/djangoapps/course_modes/tests/test_views.py b/common/djangoapps/course_modes/tests/test_views.py
index 4df40ab2af7..25dfad2a2ba 100644
--- a/common/djangoapps/course_modes/tests/test_views.py
+++ b/common/djangoapps/course_modes/tests/test_views.py
@@ -98,3 +98,45 @@ class CourseModeViewTest(TestCase):
         self.assertEquals(response.status_code, 200)
         # TODO: Fix it so that response.templates works w/ mako templates, and then assert
         # that the right template rendered
+
+
+class ProfessionalModeViewTest(TestCase):
+    """
+    Tests for redirects specific to the 'professional' course mode.
+    Can't really put this in the ddt-style tests in CourseModeViewTest,
+    since 'professional' mode implies it is the *only* mode for a course
+    """
+    def setUp(self):
+        self.course_id = SlashSeparatedCourseKey('org', 'course', 'run')
+        CourseModeFactory(mode_slug='professional', course_id=self.course_id)
+        self.user = UserFactory()
+
+    @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
+    def test_professional_registration(self):
+        self.client.login(
+            username=self.user.username,
+            password='test'
+        )
+
+        response = self.client.get(
+            reverse('course_modes_choose', args=[self.course_id.to_deprecated_string()]),
+            follow=False,
+        )
+
+        self.assertEquals(response.status_code, 302)
+        self.assertTrue(response['Location'].endswith(reverse('verify_student_show_requirements', args=[unicode(self.course_id)])))
+
+        CourseEnrollmentFactory(
+            user=self.user,
+            is_active=True,
+            mode="professional",
+            course_id=unicode(self.course_id),
+        )
+
+        response = self.client.get(
+            reverse('course_modes_choose', args=[self.course_id.to_deprecated_string()]),
+            follow=False,
+        )
+
+        self.assertEquals(response.status_code, 302)
+        self.assertTrue(response['Location'].endswith(reverse('dashboard')))
diff --git a/common/djangoapps/course_modes/views.py b/common/djangoapps/course_modes/views.py
index 83c12ab69f1..a773c77f623 100644
--- a/common/djangoapps/course_modes/views.py
+++ b/common/djangoapps/course_modes/views.py
@@ -41,12 +41,26 @@ class ChooseModeView(View):
         request.session['attempting_upgrade'] = upgrade
 
         # Inactive users always need to re-register
-        # verified users do not need to register or upgrade
+        # verified and professional users do not need to register or upgrade
         # registered users who are not trying to upgrade do not need to re-register
-        if is_active and (upgrade is False or enrollment_mode == 'verified'):
+        if is_active and (upgrade is False or enrollment_mode == 'verified' or enrollment_mode == 'professional'):
             return redirect(reverse('dashboard'))
 
         modes = CourseMode.modes_for_course_dict(course_key)
+
+        # We assume that, if 'professional' is one of the modes, it is the *only* mode.
+        # If we offer more modes alongside 'professional' in the future, this will need to route
+        # to the usual "choose your track" page.
+        if "professional" in modes:
+            return redirect(
+                reverse(
+                    'verify_student_show_requirements',
+                    kwargs={'course_id': course_key.to_deprecated_string()}
+                )
+            )
+
+
+
         donation_for_course = request.session.get("donation_for_course", {})
         chosen_price = donation_for_course.get(course_key, None)
 
diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py
index 8c23a0512b3..baadac464cb 100644
--- a/lms/djangoapps/courseware/views.py
+++ b/lms/djangoapps/courseware/views.py
@@ -708,7 +708,7 @@ def mktg_course_about(request, course_id):
 
     show_courseware_link = (has_access(request.user, 'load', course) or
                             settings.FEATURES.get('ENABLE_LMS_MIGRATION'))
-    course_modes = CourseMode.modes_for_course(course.id)
+    course_modes = CourseMode.modes_for_course_dict(course.id)
 
     return render_to_response('courseware/mktg_course_about.html', {
         'course': course,
diff --git a/lms/templates/courseware/mktg_course_about.html b/lms/templates/courseware/mktg_course_about.html
index e59ebb0f69c..cb195b47f17 100644
--- a/lms/templates/courseware/mktg_course_about.html
+++ b/lms/templates/courseware/mktg_course_about.html
@@ -55,7 +55,15 @@
         <a class="action action-register register ${'has-option-verified' if len(course_modes) > 1 else ''}" href="#">${_("Register for")} <strong>${course.display_number_with_default | h}</strong>
             %if len(course_modes) > 1:
             <span class="track">
-            and choose your student track
+            ## Translators: This is the second line on a button users can click.  The first line is "Register for COURSE_NAME"
+            ## The "choose your student track" means users can select between taking the course as an auditor, as a verified student, etc
+            ${_("and choose your student track")}
+            </span>
+            %elif "professional" in course_modes:
+            <span class="track">
+            ## Translators: This is the second line on a button users can click.  The first line is "Register for COURSE_NAME"
+            ## 'Verification' here refers to verifying one's identity in order to receive a verified certificate.
+            ${_("and proceed to verification")}
             </span>
             %endif
         </a>
-- 
GitLab