From 77ee243e77af87d66fd07f1e6efd18958c9eebf1 Mon Sep 17 00:00:00 2001 From: Diana Huang Date: Mon, 19 Aug 2013 13:36:13 -0400 Subject: [PATCH] Some cleanup fixes to get verified certs working. --- lms/djangoapps/shoppingcart/models.py | 32 ++++++++++++++++----------- lms/djangoapps/shoppingcart/views.py | 9 ++------ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/lms/djangoapps/shoppingcart/models.py b/lms/djangoapps/shoppingcart/models.py index eb4e9f578d..54e7a33889 100644 --- a/lms/djangoapps/shoppingcart/models.py +++ b/lms/djangoapps/shoppingcart/models.py @@ -61,6 +61,12 @@ class Order(models.Model): else: return items[0].currency + def clear(self): + """ + Clear out all the items in the cart + """ + self.orderitem_set.all().delete() + def purchase(self, first='', last='', street1='', street2='', city='', state='', postalcode='', country='', ccnum='', cardtype='', processor_reply_dump=''): """ @@ -208,15 +214,6 @@ class PaidCourseRegistration(OrderItem): "run:{0}".format(run)]) -# Each entry is a dictionary of ModelName: 'lower_case_model_name' -# See https://docs.djangoproject.com/en/1.4/topics/db/models/#multi-table-inheritance for -# PLEASE KEEP THIS LIST UP_TO_DATE WITH THE SUBCLASSES OF OrderItem -ORDER_ITEM_SUBTYPES = { - PaidCourseRegistration: 'paidcourseregistration', - VerifiedCertificate: 'verifiedcertificate', -} - - class VerifiedCertificate(OrderItem): """ This is an inventory item for purchasing verified certificates @@ -229,8 +226,6 @@ class VerifiedCertificate(OrderItem): """ Add a VerifiedCertificate item to an order """ - # TODO: add the basic enrollment - # TODO: error checking course_enrollment = CourseEnrollment.create_enrollment(order.user, course_id, mode="verified") item, _created = cls.objects.get_or_create( order=order, @@ -248,5 +243,16 @@ class VerifiedCertificate(OrderItem): return item def purchased_callback(self): - # TODO: add code around putting student in the verified track - pass + """ + When purchase goes through, activate the course enrollment + """ + self.course_enrollment.activate() + + +# Each entry is a dictionary of ModelName: 'lower_case_model_name' +# See https://docs.djangoproject.com/en/1.4/topics/db/models/#multi-table-inheritance for +# PLEASE KEEP THIS LIST UP_TO_DATE WITH THE SUBCLASSES OF OrderItem +ORDER_ITEM_SUBTYPES = { + PaidCourseRegistration: 'paidcourseregistration', + VerifiedCertificate: 'verifiedcertificate', +} diff --git a/lms/djangoapps/shoppingcart/views.py b/lms/djangoapps/shoppingcart/views.py index f6ca5d0837..91dff59aed 100644 --- a/lms/djangoapps/shoppingcart/views.py +++ b/lms/djangoapps/shoppingcart/views.py @@ -57,7 +57,7 @@ def show_cart(request): @login_required def clear_cart(request): cart = Order.get_cart_for_user(request.user) - cart.orderitem_set.all().delete() + cart.clear() return HttpResponse('Cleared') @login_required @@ -89,7 +89,7 @@ def postpay_callback(request): return render_to_response('shoppingcart.processor_error.html', {'order':result['order'], 'error_html': result['error_html']}) - +@login_required def show_receipt(request, ordernum): """ Displays a receipt for a particular order. @@ -108,8 +108,3 @@ def show_receipt(request, ordernum): return render_to_response('shoppingcart/receipt.html', {'order': order, 'order_items': order_items, 'any_refunds': any_refunds}) - -#def show_orders(request): - """ - Displays all orders of a user - """