Commit c96a29d7 by Diana Huang

Move course_id into the urls.

parent 94def0aa
......@@ -5,5 +5,5 @@ from course_modes import views
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
class ChooseModeView(View):
@method_decorator(login_required)
def get(self, request, error=None):
course_id = request.GET.get("course_id")
def get(self, request, course_id, error=None):
modes = CourseMode.modes_for_course_dict(course_id)
context = {
"course_id": course_id,
......@@ -38,8 +37,7 @@ class ChooseModeView(View):
return render_to_response("course_modes/choose.html", context)
def post(self, request):
course_id = request.GET.get("course_id")
def post(self, request, course_id):
user = request.user
# This is a bit redundant with logic in student.views.change_enrollement,
......@@ -47,7 +45,7 @@ class ChooseModeView(View):
course = course_from_id(course_id)
if not has_access(user, course, 'enroll'):
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"))
if requested_mode == "verified" and request.POST.get("honor-code"):
......@@ -72,29 +70,25 @@ class ChooseModeView(View):
amount_value = decimal.Decimal(amount).quantize(decimal.Decimal('.01'), rounding=decimal.ROUND_DOWN)
except decimal.InvalidOperation:
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
if amount_value < mode_info.min_price:
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[course_id] = amount_value
request.session["donation_for_course"] = donation_for_course
if SoftwareSecurePhotoVerification.user_has_valid_or_pending(request.user):
return redirect(
"{}?{}".format(
reverse('verify_student_verified'),
urlencode(dict(course_id=course_id))
)
reverse('verify_student_verified',
kwargs={'course_id': course_id})
)
return redirect(
"{}?{}".format(
reverse('verify_student_show_requirements'),
urlencode(dict(course_id=course_id))
)
reverse('verify_student_show_requirements',
kwargs={'course_id': course_id}),
)
def get_requested_mode(self, user_choice):
......
......@@ -375,10 +375,7 @@ def change_enrollment(request):
available_modes = CourseMode.modes_for_course(course_id)
if len(available_modes) > 1:
return HttpResponse(
"{}?{}".format(
reverse("course_modes_choose"),
urlencode(dict(course_id=course_id))
)
reverse("course_modes_choose", kwargs={'course_id': course_id})
)
org, course_num, run = course_id.split("/")
......
......@@ -21,7 +21,7 @@ from student.tests.factories import UserFactory
class StartView(TestCase):
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):
"""
......
......@@ -24,19 +24,19 @@ urlpatterns = patterns(
# The above are what we did for the design mockups, but what we're really
# looking at now is:
url(
r'^show_requirements',
r'^show_requirements/(?P<course_id>[^/]+/[^/]+/[^/]+)$',
views.show_requirements,
name="verify_student_show_requirements"
),
url(
r'^verify',
r'^verify/(?P<course_id>[^/]+/[^/]+/[^/]+)$',
views.VerifyView.as_view(),
name="verify_student_verify"
),
url(
r'^verified',
r'^verified/(?P<course_id>[^/]+/[^/]+/[^/]+)$',
views.VerifiedView.as_view(),
name="verify_student_verified"
),
......@@ -48,7 +48,7 @@ urlpatterns = patterns(
),
url(
r'^show_verification_page',
r'^show_verification_page/(?P<course_id>[^/]+/[^/]+/[^/]+)$',
views.show_verification_page,
name="verify_student/show_verification_page"
),
......
......@@ -10,11 +10,12 @@ from mitxmako.shortcuts import render_to_response
from django.conf import settings
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.views.generic.base import View
from django.utils.translation import ugettext as _
from django.utils.http import urlencode
from django.contrib.auth.decorators import login_required
from course_modes.models import CourseMode
from student.models import CourseEnrollment
......@@ -29,19 +30,15 @@ log = logging.getLogger(__name__)
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,
# redirect straight to the payment -- no need to verify again.
if SoftwareSecurePhotoVerification.user_has_valid_or_pending(request.user):
return redirect(
"{}?{}".format(
reverse('verify_student_verified'),
urlencode(dict(course_id=course_id))
)
)
reverse('verify_student_verified',
kwargs={'course_id': course_id}))
else:
# 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
......@@ -76,11 +73,10 @@ class VerifiedView(View):
View that gets shown once the user has already gone through the
verification flow
"""
def get(self, request):
def get(self, request, course_id):
"""
Handle the case where we have a get request
"""
course_id = request.GET['course_id']
verify_mode = CourseMode.mode_for_course(course_id, "verified")
if course_id in request.session.get("donation_for_course", {}):
chosen_price = request.session["donation_for_course"][course_id]
......@@ -131,10 +127,12 @@ def create_order(request):
return HttpResponse(json.dumps(params), content_type="text/json")
def show_requirements(request):
"""This might just be a plain template without a view."""
context = { "course_id": request.GET.get("course_id") }
@login_required
def show_requirements(request, course_id):
"""
Show the requirements necessary for
"""
context = { "course_id": course_id }
return render_to_response("verify_student/show_requirements.html", context)
def face_upload(request):
......@@ -175,7 +173,7 @@ def enroll(user, course_id, mode_slug):
# to a page that lets them choose which mode they want.
if len(available_modes) > 1:
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...
else:
......@@ -188,11 +186,11 @@ def enroll(user, course_id, mode_slug):
return HttpResponseRedirect(reverse('dashboard'))
if mode_slug == "verify":
if SoftwareSecureVerification.has_submitted_recent_request(user):
if SoftwareSecurePhotoVerification.has_submitted_recent_request(user):
# Capture payment info
# Create an order
# 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
......
......@@ -518,7 +518,7 @@
<li class="help-item">
<h3 class="title">Change your mind?</h3>
<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>
</li>
</ul>
......
......@@ -124,7 +124,7 @@
<ol class="wizard-steps">
<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>
</ol>
</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