Commit c96a29d7 by Diana Huang

Move course_id into the urls.

parent 94def0aa
...@@ -5,5 +5,5 @@ from course_modes import views ...@@ -5,5 +5,5 @@ from course_modes import views
urlpatterns = patterns( urlpatterns = patterns(
'', '',
url(r'^choose', views.ChooseModeView.as_view(), name="course_modes_choose"), url(r'^choose/(?P<course_id>[^/]+/[^/]+/[^/]+)$', views.ChooseModeView.as_view(), name="course_modes_choose"),
) )
...@@ -21,8 +21,7 @@ from verify_student.models import SoftwareSecurePhotoVerification ...@@ -21,8 +21,7 @@ from verify_student.models import SoftwareSecurePhotoVerification
class ChooseModeView(View): class ChooseModeView(View):
@method_decorator(login_required) @method_decorator(login_required)
def get(self, request, error=None): def get(self, request, course_id, error=None):
course_id = request.GET.get("course_id")
modes = CourseMode.modes_for_course_dict(course_id) modes = CourseMode.modes_for_course_dict(course_id)
context = { context = {
"course_id": course_id, "course_id": course_id,
...@@ -38,8 +37,7 @@ class ChooseModeView(View): ...@@ -38,8 +37,7 @@ class ChooseModeView(View):
return render_to_response("course_modes/choose.html", context) return render_to_response("course_modes/choose.html", context)
def post(self, request): def post(self, request, course_id):
course_id = request.GET.get("course_id")
user = request.user user = request.user
# This is a bit redundant with logic in student.views.change_enrollement, # This is a bit redundant with logic in student.views.change_enrollement,
...@@ -47,7 +45,7 @@ class ChooseModeView(View): ...@@ -47,7 +45,7 @@ class ChooseModeView(View):
course = course_from_id(course_id) course = course_from_id(course_id)
if not has_access(user, course, 'enroll'): if not has_access(user, course, 'enroll'):
error_msg = _("Enrollment is closed") error_msg = _("Enrollment is closed")
return self.get(request, error=error_msg) return self.get(request, course_id, error=error_msg)
requested_mode = self.get_requested_mode(request.POST.get("mode")) requested_mode = self.get_requested_mode(request.POST.get("mode"))
if requested_mode == "verified" and request.POST.get("honor-code"): if requested_mode == "verified" and request.POST.get("honor-code"):
...@@ -72,29 +70,25 @@ class ChooseModeView(View): ...@@ -72,29 +70,25 @@ class ChooseModeView(View):
amount_value = decimal.Decimal(amount).quantize(decimal.Decimal('.01'), rounding=decimal.ROUND_DOWN) amount_value = decimal.Decimal(amount).quantize(decimal.Decimal('.01'), rounding=decimal.ROUND_DOWN)
except decimal.InvalidOperation: except decimal.InvalidOperation:
error_msg = _("Invalid amount selected.") error_msg = _("Invalid amount selected.")
return self.get(request, error=error_msg) return self.get(request, course_id, error=error_msg)
# Check for minimum pricing # Check for minimum pricing
if amount_value < mode_info.min_price: if amount_value < mode_info.min_price:
error_msg = _("No selected price or selected price is too low.") error_msg = _("No selected price or selected price is too low.")
return self.get(request, error=error_msg) return self.get(request, course_id, error=error_msg)
donation_for_course = request.session.get("donation_for_course", {}) donation_for_course = request.session.get("donation_for_course", {})
donation_for_course[course_id] = amount_value donation_for_course[course_id] = amount_value
request.session["donation_for_course"] = donation_for_course request.session["donation_for_course"] = donation_for_course
if SoftwareSecurePhotoVerification.user_has_valid_or_pending(request.user): if SoftwareSecurePhotoVerification.user_has_valid_or_pending(request.user):
return redirect( return redirect(
"{}?{}".format( reverse('verify_student_verified',
reverse('verify_student_verified'), kwargs={'course_id': course_id})
urlencode(dict(course_id=course_id))
)
) )
return redirect( return redirect(
"{}?{}".format( reverse('verify_student_show_requirements',
reverse('verify_student_show_requirements'), kwargs={'course_id': course_id}),
urlencode(dict(course_id=course_id))
)
) )
def get_requested_mode(self, user_choice): def get_requested_mode(self, user_choice):
......
...@@ -375,10 +375,7 @@ def change_enrollment(request): ...@@ -375,10 +375,7 @@ def change_enrollment(request):
available_modes = CourseMode.modes_for_course(course_id) available_modes = CourseMode.modes_for_course(course_id)
if len(available_modes) > 1: if len(available_modes) > 1:
return HttpResponse( return HttpResponse(
"{}?{}".format( reverse("course_modes_choose", kwargs={'course_id': course_id})
reverse("course_modes_choose"),
urlencode(dict(course_id=course_id))
)
) )
org, course_num, run = course_id.split("/") org, course_num, run = course_id.split("/")
......
...@@ -21,7 +21,7 @@ from student.tests.factories import UserFactory ...@@ -21,7 +21,7 @@ from student.tests.factories import UserFactory
class StartView(TestCase): class StartView(TestCase):
def start_url(course_id=""): def start_url(course_id=""):
return "/verify_student/start?course_id={0}".format(urllib.quote(course_id)) return "/verify_student/{0}".format(urllib.quote(course_id))
def test_start_new_verification(self): def test_start_new_verification(self):
""" """
......
...@@ -24,19 +24,19 @@ urlpatterns = patterns( ...@@ -24,19 +24,19 @@ urlpatterns = patterns(
# The above are what we did for the design mockups, but what we're really # The above are what we did for the design mockups, but what we're really
# looking at now is: # looking at now is:
url( url(
r'^show_requirements', r'^show_requirements/(?P<course_id>[^/]+/[^/]+/[^/]+)$',
views.show_requirements, views.show_requirements,
name="verify_student_show_requirements" name="verify_student_show_requirements"
), ),
url( url(
r'^verify', r'^verify/(?P<course_id>[^/]+/[^/]+/[^/]+)$',
views.VerifyView.as_view(), views.VerifyView.as_view(),
name="verify_student_verify" name="verify_student_verify"
), ),
url( url(
r'^verified', r'^verified/(?P<course_id>[^/]+/[^/]+/[^/]+)$',
views.VerifiedView.as_view(), views.VerifiedView.as_view(),
name="verify_student_verified" name="verify_student_verified"
), ),
...@@ -48,7 +48,7 @@ urlpatterns = patterns( ...@@ -48,7 +48,7 @@ urlpatterns = patterns(
), ),
url( url(
r'^show_verification_page', r'^show_verification_page/(?P<course_id>[^/]+/[^/]+/[^/]+)$',
views.show_verification_page, views.show_verification_page,
name="verify_student/show_verification_page" name="verify_student/show_verification_page"
), ),
......
...@@ -10,11 +10,12 @@ from mitxmako.shortcuts import render_to_response ...@@ -10,11 +10,12 @@ from mitxmako.shortcuts import render_to_response
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseBadRequest from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseRedirect
from django.shortcuts import redirect from django.shortcuts import redirect
from django.views.generic.base import View from django.views.generic.base import View
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.utils.http import urlencode from django.utils.http import urlencode
from django.contrib.auth.decorators import login_required
from course_modes.models import CourseMode from course_modes.models import CourseMode
from student.models import CourseEnrollment from student.models import CourseEnrollment
...@@ -29,19 +30,15 @@ log = logging.getLogger(__name__) ...@@ -29,19 +30,15 @@ log = logging.getLogger(__name__)
class VerifyView(View): class VerifyView(View):
def get(self, request): def get(self, request, course_id):
""" """
""" """
course_id = request.GET['course_id']
# If the user has already been verified within the given time period, # If the user has already been verified within the given time period,
# redirect straight to the payment -- no need to verify again. # redirect straight to the payment -- no need to verify again.
if SoftwareSecurePhotoVerification.user_has_valid_or_pending(request.user): if SoftwareSecurePhotoVerification.user_has_valid_or_pending(request.user):
return redirect( return redirect(
"{}?{}".format( reverse('verify_student_verified',
reverse('verify_student_verified'), kwargs={'course_id': course_id}))
urlencode(dict(course_id=course_id))
)
)
else: else:
# If they haven't completed a verification attempt, we have to # If they haven't completed a verification attempt, we have to
# restart with a new one. We can't reuse an older one because we # restart with a new one. We can't reuse an older one because we
...@@ -76,11 +73,10 @@ class VerifiedView(View): ...@@ -76,11 +73,10 @@ class VerifiedView(View):
View that gets shown once the user has already gone through the View that gets shown once the user has already gone through the
verification flow verification flow
""" """
def get(self, request): def get(self, request, course_id):
""" """
Handle the case where we have a get request Handle the case where we have a get request
""" """
course_id = request.GET['course_id']
verify_mode = CourseMode.mode_for_course(course_id, "verified") verify_mode = CourseMode.mode_for_course(course_id, "verified")
if course_id in request.session.get("donation_for_course", {}): if course_id in request.session.get("donation_for_course", {}):
chosen_price = request.session["donation_for_course"][course_id] chosen_price = request.session["donation_for_course"][course_id]
...@@ -131,10 +127,12 @@ def create_order(request): ...@@ -131,10 +127,12 @@ def create_order(request):
return HttpResponse(json.dumps(params), content_type="text/json") return HttpResponse(json.dumps(params), content_type="text/json")
@login_required
def show_requirements(request): def show_requirements(request, course_id):
"""This might just be a plain template without a view.""" """
context = { "course_id": request.GET.get("course_id") } Show the requirements necessary for
"""
context = { "course_id": course_id }
return render_to_response("verify_student/show_requirements.html", context) return render_to_response("verify_student/show_requirements.html", context)
def face_upload(request): def face_upload(request):
...@@ -175,7 +173,7 @@ def enroll(user, course_id, mode_slug): ...@@ -175,7 +173,7 @@ def enroll(user, course_id, mode_slug):
# to a page that lets them choose which mode they want. # to a page that lets them choose which mode they want.
if len(available_modes) > 1: if len(available_modes) > 1:
return HttpResponseRedirect( return HttpResponseRedirect(
reverse('choose_enroll_mode', course_id=course_id) reverse('choose_enroll_mode', kwargs={'course_id': course_id})
) )
# Otherwise, we use the only mode that's supported... # Otherwise, we use the only mode that's supported...
else: else:
...@@ -188,11 +186,11 @@ def enroll(user, course_id, mode_slug): ...@@ -188,11 +186,11 @@ def enroll(user, course_id, mode_slug):
return HttpResponseRedirect(reverse('dashboard')) return HttpResponseRedirect(reverse('dashboard'))
if mode_slug == "verify": if mode_slug == "verify":
if SoftwareSecureVerification.has_submitted_recent_request(user): if SoftwareSecurePhotoVerification.has_submitted_recent_request(user):
# Capture payment info # Capture payment info
# Create an order # Create an order
# Create a VerifiedCertificate order item # Create a VerifiedCertificate order item
return HttpResponse.Redirect(reverse('payment')) return HttpResponse.Redirect(reverse('verified'))
# There's always at least one mode available (default is "honor"). If they # There's always at least one mode available (default is "honor"). If they
......
...@@ -518,7 +518,7 @@ ...@@ -518,7 +518,7 @@
<li class="help-item"> <li class="help-item">
<h3 class="title">Change your mind?</h3> <h3 class="title">Change your mind?</h3>
<div class="copy"> <div class="copy">
<p>You can always <a href="${reverse('course_modes_choose') + '?course_id=' + course_id }">Audit the course for free</a> without verifying.</p> <p>You can always <a href="${reverse('course_modes_choose', kwargs={'course_id': course_id})}">Audit the course for free</a> without verifying.</p>
</div> </div>
</li> </li>
</ul> </ul>
......
...@@ -124,7 +124,7 @@ ...@@ -124,7 +124,7 @@
<ol class="wizard-steps"> <ol class="wizard-steps">
<li class="wizard-step"> <li class="wizard-step">
<a class="next action-primary" id="face_next_button" href="${reverse('verify_student_verify') + '?course_id=' + course_id}">Go to Step 1: Take my Photo</a> <a class="next action-primary" id="face_next_button" href="${reverse('verify_student_verify', kwargs={'course_id': course_id})}">Go to Step 1: Take my Photo</a>
</li> </li>
</ol> </ol>
</nav> </nav>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment