Clean up views and models.
This commit is contained in:
@@ -6,7 +6,7 @@ from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.translation import ugettext as _
|
||||
from model_utils.managers import InheritanceManager
|
||||
from courseware.courses import course_image_url, get_course_about_section
|
||||
from courseware.courses import get_course_about_section
|
||||
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.course_module import CourseDescriptor
|
||||
@@ -66,6 +66,7 @@ class Order(models.Model):
|
||||
|
||||
@property
|
||||
def total_cost(self):
|
||||
""" Return the total cost of the order """
|
||||
return sum(i.line_cost for i in self.orderitem_set.filter(status=self.status))
|
||||
|
||||
def clear(self):
|
||||
@@ -79,6 +80,19 @@ class Order(models.Model):
|
||||
"""
|
||||
Call to mark this order as purchased. Iterates through its OrderItems and calls
|
||||
their purchased_callback
|
||||
|
||||
`first` - first name of person billed (e.g. John)
|
||||
`last` - last name of person billed (e.g. Smith)
|
||||
`street1` - first line of a street address of the billing address (e.g. 11 Cambridge Center)
|
||||
`street2` - second line of a street address of the billing address (e.g. Suite 101)
|
||||
`city` - city of the billing address (e.g. Cambridge)
|
||||
`state` - code of the state, province, or territory of the billing address (e.g. MA)
|
||||
`postalcode` - postal code of the billing address (e.g. 02142)
|
||||
`country` - country code of the billing address (e.g. US)
|
||||
`ccnum` - last 4 digits of the credit card number of the credit card billed (e.g. 1111)
|
||||
`cardtype` - 3-digit code representing the card type used (e.g. 001)
|
||||
`processor_reply_dump` - all the parameters returned by the processor
|
||||
|
||||
"""
|
||||
self.status = 'purchased'
|
||||
self.purchase_time = datetime.now(pytz.utc)
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import logging
|
||||
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound, HttpResponseForbidden, Http404
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.decorators.http import require_POST
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from student.models import CourseEnrollment
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError
|
||||
from mitxmako.shortcuts import render_to_response
|
||||
from .models import *
|
||||
from .models import Order, PaidCourseRegistration, CertificateItem, OrderItem
|
||||
from .processors import process_postpay_callback, render_purchase_form_html
|
||||
|
||||
log = logging.getLogger("shoppingcart")
|
||||
@@ -38,6 +39,9 @@ def add_course_to_cart(request, course_id):
|
||||
|
||||
@login_required
|
||||
def register_for_verified_cert(request, course_id):
|
||||
"""
|
||||
Add a CertificateItem to the cart
|
||||
"""
|
||||
cart = Order.get_cart_for_user(request.user)
|
||||
CertificateItem.add_to_order(cart, course_id, 30, 'verified')
|
||||
return HttpResponse("Added")
|
||||
@@ -77,6 +81,7 @@ def remove_item(request):
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@require_POST
|
||||
def postpay_callback(request):
|
||||
"""
|
||||
Receives the POST-back from processor.
|
||||
@@ -111,7 +116,7 @@ def show_receipt(request, ordernum):
|
||||
raise Http404('Order not found!')
|
||||
|
||||
order_items = order.orderitem_set.all()
|
||||
any_refunds = "refunded" in [i.status for i in order_items]
|
||||
any_refunds = any(i.status == "refunded" for i in order_items)
|
||||
return render_to_response('shoppingcart/receipt.html', {'order': order,
|
||||
'order_items': order_items,
|
||||
'any_refunds': any_refunds})
|
||||
|
||||
Reference in New Issue
Block a user