From 448f5cc41fc53ff329300437c7bea7d69718bfd4 Mon Sep 17 00:00:00 2001
From: Julia Hansbrough <julia@edx.org>
Date: Mon, 4 Nov 2013 20:32:47 +0000
Subject: [PATCH] Response to CR

---
 common/djangoapps/student/views.py            | 22 +++++++++----------
 lms/djangoapps/shoppingcart/models.py         |  5 +----
 lms/templates/dashboard.html                  |  6 ++---
 .../dashboard/_dashboard_course_listing.html  |  2 +-
 4 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py
index a3195e11a4e..b6904f2fb7f 100644
--- a/common/djangoapps/student/views.py
+++ b/common/djangoapps/student/views.py
@@ -296,13 +296,13 @@ def complete_course_mode_info(course_id, enrollment):
 def dashboard(request):
     user = request.user
 
-    # Build our courses list for the user, but ignore any courses that no longer
-    # exist (because the course IDs have changed). Still, we don't delete those
+    # Build our (course, enorllment) list for the user, but ignore any courses that no 
+    # longer exist (because the course IDs have changed). Still, we don't delete those
     # enrollments, because it could have been a data push snafu.
-    courses = []
+    course_enrollment_pairs = []
     for enrollment in CourseEnrollment.enrollments_for_user(user):
         try:
-            courses.append((course_from_id(enrollment.course_id), enrollment))
+            course_enrollment_pairs.append((course_from_id(enrollment.course_id), enrollment))
         except ItemNotFoundError:
             log.error("User {0} enrolled in non-existent course {1}"
                       .format(user.username, enrollment.course_id))
@@ -321,15 +321,15 @@ def dashboard(request):
         staff_access = True
         errored_courses = modulestore().get_errored_courses()
 
-    show_courseware_links_for = frozenset(course.id for course, _enrollment in courses
+    show_courseware_links_for = frozenset(course.id for course, _enrollment in course_enrollment_pairs
                                           if has_access(request.user, course, 'load'))
 
-    course_modes = {course.id: complete_course_mode_info(course.id, enrollment) for course, enrollment in courses}
-    cert_statuses = {course.id: cert_info(request.user, course) for course, _enrollment in courses}
+    course_modes = {course.id: complete_course_mode_info(course.id, enrollment) for course, enrollment in course_enrollment_pairs}
+    cert_statuses = {course.id: cert_info(request.user, course) for course, _enrollment in course_enrollment_pairs}
 
     # only show email settings for Mongo course and when bulk email is turned on
     show_email_settings_for = frozenset(
-        course.id for course, _enrollment in courses if (
+        course.id for course, _enrollment in course_enrollment_pairs if (
             settings.MITX_FEATURES['ENABLE_INSTRUCTOR_EMAIL'] and
             modulestore().get_modulestore_type(course.id) == MONGO_MODULESTORE_TYPE and
             CourseAuthorization.instructor_email_enabled(course.id)
@@ -339,7 +339,7 @@ def dashboard(request):
     # Verification Attempts
     verification_status, verification_msg = SoftwareSecurePhotoVerification.user_status(user)
 
-    show_refund_option_for = frozenset(course.id for course, _enrollment in courses
+    show_refund_option_for = frozenset(course.id for course, _enrollment in course_enrollment_pairs
                                        if _enrollment.refundable())
 
     # get info w.r.t ExternalAuthMap
@@ -349,7 +349,7 @@ def dashboard(request):
     except ExternalAuthMap.DoesNotExist:
         pass
 
-    context = {'courses': courses,
+    context = {'course_enrollment_pairs': course_enrollment_pairs,
                'course_optouts': course_optouts,
                'message': message,
                'external_auth_map': external_auth_map,
@@ -1515,4 +1515,4 @@ def change_email_settings(request):
         log.info(u"User {0} ({1}) opted out of receiving emails from course {2}".format(user.username, user.email, course_id))
         track.views.server_track(request, "change-email-settings", {"receive_emails": "no", "course": course_id}, page='dashboard')
 
-    return HttpResponse(json.dumps({'success': True}))
+    return HttpResponse(json.dumps({'success': True}))
\ No newline at end of file
diff --git a/lms/djangoapps/shoppingcart/models.py b/lms/djangoapps/shoppingcart/models.py
index d9fb051e9a1..03be80861af 100644
--- a/lms/djangoapps/shoppingcart/models.py
+++ b/lms/djangoapps/shoppingcart/models.py
@@ -411,10 +411,7 @@ class CertificateItem(OrderItem):
         """
 
         # Only refund verified cert unenrollments that are within bounds of the expiration date
-        if course_enrollment.mode != 'verified':
-            return
-
-        if CourseMode.mode_for_course(course_enrollment.course_id, 'verified') is None:
+        if not course_enrollment.refundable():
             return
 
         target_certs = CertificateItem.objects.filter(course_id=course_enrollment.course_id, user_id=course_enrollment.user, status='purchased', mode='verified')
diff --git a/lms/templates/dashboard.html b/lms/templates/dashboard.html
index 2a24912633f..9d9600475cb 100644
--- a/lms/templates/dashboard.html
+++ b/lms/templates/dashboard.html
@@ -183,9 +183,9 @@
       <h2>${_("Current Courses")}</h2>
     </header>
 
-    % if len(courses) > 0:
+    % if len(course_enrollment_pairs) > 0:
       <ul class="listing-courses">
-        % for course, enrollment in courses:
+        % for course, enrollment in course_enrollment_pairs:
             <% show_courseware_link = (course.id in show_courseware_links_for) %>
             <% cert_status = cert_statuses.get(course.id) %>
             <% show_email_settings = (course.id in show_email_settings_for) %>
@@ -341,4 +341,4 @@
       </div>
     </form>
   </div>
-</section>
+</section>
\ No newline at end of file
diff --git a/lms/templates/dashboard/_dashboard_course_listing.html b/lms/templates/dashboard/_dashboard_course_listing.html
index 7c68d45e2ab..30c60fb9f1f 100644
--- a/lms/templates/dashboard/_dashboard_course_listing.html
+++ b/lms/templates/dashboard/_dashboard_course_listing.html
@@ -157,4 +157,4 @@
 
   </section>
 </article>
-</li>
+</li>
\ No newline at end of file
-- 
GitLab