From 8e2ced916f45d7c517e7305006bf25d6dac1ad63 Mon Sep 17 00:00:00 2001 From: Matthew Mongeau Date: Thu, 26 Jul 2012 14:06:29 -0400 Subject: [PATCH] Add field-error class to field with issues. --- common/djangoapps/student/views.py | 8 ++++++++ lms/templates/signup_modal.html | 24 +++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 1644822d5f..6e2cf5b791 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -264,14 +264,17 @@ def create_account(request, post_override=None): for a in ['username', 'email', 'password', 'name']: if a not in post_vars: js['value'] = "Error (401 {field}). E-mail us.".format(field=a) + js['field'] = a return HttpResponse(json.dumps(js)) if post_vars.get('honor_code', 'false') != u'true': js['value'] = "To enroll, you must follow the honor code.".format(field=a) + js['field'] = 'honor_code' return HttpResponse(json.dumps(js)) if post_vars.get('terms_of_service', 'false') != u'true': js['value'] = "You must accept the terms of service.".format(field=a) + js['field'] = 'terms_of_service' return HttpResponse(json.dumps(js)) # Confirm appropriate fields are there. @@ -288,18 +291,21 @@ def create_account(request, post_override=None): 'terms_of_service': 'Accepting Terms of Service is required.', 'honor_code': 'Agreeing to the Honor Code is required.'} js['value'] = error_str[a] + js['field'] = a return HttpResponse(json.dumps(js)) try: validate_email(post_vars['email']) except ValidationError: js['value'] = "Valid e-mail is required.".format(field=a) + js['field'] = 'email' return HttpResponse(json.dumps(js)) try: validate_slug(post_vars['username']) except ValidationError: js['value'] = "Username should only consist of A-Z and 0-9.".format(field=a) + js['field'] = 'username' return HttpResponse(json.dumps(js)) u = User(username=post_vars['username'], @@ -315,10 +321,12 @@ def create_account(request, post_override=None): # Figure out the cause of the integrity error if len(User.objects.filter(username=post_vars['username'])) > 0: js['value'] = "An account with this username already exists." + js['field'] = 'username' return HttpResponse(json.dumps(js)) if len(User.objects.filter(email=post_vars['email'])) > 0: js['value'] = "An account with this e-mail already exists." + js['field'] = 'email' return HttpResponse(json.dumps(js)) raise diff --git a/lms/templates/signup_modal.html b/lms/templates/signup_modal.html index 26b248d0ee..aef90ab0f2 100644 --- a/lms/templates/signup_modal.html +++ b/lms/templates/signup_modal.html @@ -19,19 +19,19 @@
- + - + - + - +
- +
@@ -55,7 +55,7 @@
- +
- +
-