Added username into Authors file [Ex-12] Add user to input coupon code in the Shopping Cart [Ex-13] Discount should be reflected in the Payment confirmation page and email added E-commerce Tab in Instructor Dashboard added name/email in authors file removed the is_active column, change the colors scheme, fixed bugs wip wip test github account STORE_BILLING_INFO set to True cybersource api update, reference number updated, merchant_data removed from params View Course buttons on receipt link for course added to receipt receipt.html view course button - func update receipt.html course link update move new CyberSource implementation to a separate file so that we can keep the original remove config changes remove config changes remove coupon redemption during clear cart and update test cases [Ex-11]added test cases(E-commerce Tab Instuctor Dashboard) update data model max_length to 255 remove array paid_course_ids init in views.py removed the is_active filter=false, added styling to the inactive coupon codes remove coupon redemption during clear cart and update test cases [Ex-11]added test cases(E-commerce Tab Instuctor Dashboard) update data model max_length to 255 Add column to the list of coupons in the E-Commerce tab Add ability for microsites to specify custom CyberSource secret configuration, i.e. run under different accounts make the new CyberSource2 also microsite aware updating migration for student and shopping cart apps added user signup functionality that orignated from the Microsites added non-microsite user signup tests fix the hard coded callback URL to localhost add comment Modify e-commerce instructor tab to show a total amount above the coupon listings for admin finance user made changes as suggested by diana khuang add the CourseAccessRoles table to the Django Admin website shopping cart coupon checkout changes as suggested by Jason Bau changes are made according to the suggesstions on PR#4172 changes made in the coupons file changes in the coupons get_coupon_info view fix merge conflict resolution error changes in the remove_coupon view json response changes as suggested by David Baumgold pep8/pylint fixes Changes as suggested by jasonBau don't assume item in shopping cart is a PaidCourseRegistration fix up some logging changed the urls of the coupon views and use the post to get the values from the request
136 lines
4.9 KiB
Python
136 lines
4.9 KiB
Python
"""
|
|
E-commerce Tab Instructor Dashboard Coupons Operations views
|
|
"""
|
|
from django.contrib.auth.decorators import login_required
|
|
from django.core.exceptions import ObjectDoesNotExist
|
|
from django.db.models import Q
|
|
from django.views.decorators.http import require_POST
|
|
from django.utils.translation import ugettext as _
|
|
from util.json_request import JsonResponse
|
|
from django.http import HttpResponse, HttpResponseNotFound
|
|
from shoppingcart.models import Coupon
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
@require_POST
|
|
@login_required
|
|
def remove_coupon(request, course_id): # pylint: disable=W0613
|
|
"""
|
|
remove the coupon against the coupon id
|
|
set the coupon is_active flag to false
|
|
"""
|
|
coupon_id = request.POST.get('id', None)
|
|
if not coupon_id:
|
|
return JsonResponse({
|
|
'message': _('coupon id is None')
|
|
}, status=400) # status code 400: Bad Request
|
|
|
|
try:
|
|
coupon = Coupon.objects.get(id=coupon_id)
|
|
except ObjectDoesNotExist:
|
|
return JsonResponse({
|
|
'message': _('coupon with the coupon id ({coupon_id}) DoesNotExist').format(coupon_id=coupon_id)
|
|
}, status=400) # status code 400: Bad Request
|
|
if not coupon.is_active:
|
|
return JsonResponse({
|
|
'message': _('coupon with the coupon id ({coupon_id}) is already inactive').format(coupon_id=coupon_id)
|
|
}, status=400) # status code 400: Bad Request
|
|
coupon.is_active = False
|
|
coupon.save()
|
|
return JsonResponse({
|
|
'message': _('coupon with the coupon id ({coupon_id}) updated successfully').format(coupon_id=coupon_id)
|
|
}) # status code 200: OK by default
|
|
|
|
|
|
@require_POST
|
|
@login_required
|
|
def add_coupon(request, course_id): # pylint: disable=W0613
|
|
"""
|
|
add coupon in the Coupons Table
|
|
"""
|
|
code = request.POST.get('code')
|
|
|
|
# check if the code is already in the Coupons Table and active
|
|
coupon = Coupon.objects.filter(is_active=True, code=code)
|
|
|
|
if coupon:
|
|
return HttpResponseNotFound(_("coupon with the coupon code ({code}) already exist").format(code=code))
|
|
|
|
description = request.POST.get('description')
|
|
course_id = request.POST.get('course_id')
|
|
discount = request.POST.get('discount')
|
|
coupon = Coupon(
|
|
code=code, description=description, course_id=course_id,
|
|
percentage_discount=discount, created_by_id=request.user.id
|
|
)
|
|
coupon.save()
|
|
return HttpResponse(_("coupon with the coupon code ({code}) added successfully").format(code=code))
|
|
|
|
|
|
@require_POST
|
|
@login_required
|
|
def update_coupon(request, course_id): # pylint: disable=W0613
|
|
"""
|
|
update the coupon object in the database
|
|
"""
|
|
coupon_id = request.POST.get('coupon_id', None)
|
|
if not coupon_id:
|
|
return HttpResponseNotFound(_("coupon id not found"))
|
|
|
|
try:
|
|
coupon = Coupon.objects.get(pk=coupon_id)
|
|
except ObjectDoesNotExist:
|
|
return HttpResponseNotFound(_("coupon with the coupon id ({coupon_id}) DoesNotExist").format(coupon_id=coupon_id))
|
|
|
|
code = request.POST.get('code')
|
|
filtered_coupons = Coupon.objects.filter(~Q(id=coupon_id), code=code, is_active=True)
|
|
|
|
if filtered_coupons:
|
|
return HttpResponseNotFound(_("coupon with the coupon id ({coupon_id}) already exists").format(coupon_id=coupon_id))
|
|
|
|
description = request.POST.get('description')
|
|
course_id = request.POST.get('course_id')
|
|
discount = request.POST.get('discount')
|
|
coupon.code = code
|
|
coupon.description = description
|
|
coupon.course_id = course_id
|
|
coupon.percentage_discount = discount
|
|
coupon.save()
|
|
return HttpResponse(_("coupon with the coupon id ({coupon_id}) updated Successfully").format(coupon_id=coupon_id))
|
|
|
|
|
|
@require_POST
|
|
@login_required
|
|
def get_coupon_info(request, course_id): # pylint: disable=W0613
|
|
"""
|
|
get the coupon information to display in the pop up form
|
|
"""
|
|
coupon_id = request.POST.get('id', None)
|
|
if not coupon_id:
|
|
return JsonResponse({
|
|
'message': _("coupon id not found")
|
|
}, status=400) # status code 400: Bad Request
|
|
|
|
try:
|
|
coupon = Coupon.objects.get(id=coupon_id)
|
|
except ObjectDoesNotExist:
|
|
return JsonResponse({
|
|
'message': _("coupon with the coupon id ({coupon_id}) DoesNotExist").format(coupon_id=coupon_id)
|
|
}, status=400) # status code 400: Bad Request
|
|
|
|
if not coupon.is_active:
|
|
return JsonResponse({
|
|
'message': _("coupon with the coupon id ({coupon_id}) is already inactive").format(coupon_id=coupon_id)
|
|
}, status=400) # status code 400: Bad Request
|
|
|
|
return JsonResponse({
|
|
'coupon_code': coupon.code,
|
|
'coupon_description': coupon.description,
|
|
'coupon_course_id': coupon.course_id.to_deprecated_string(),
|
|
'coupon_discount': coupon.percentage_discount,
|
|
'message': _('coupon with the coupon id ({coupon_id}) updated successfully').format(coupon_id=coupon_id)
|
|
}) # status code 200: OK by default
|