Commit 25bbecee by Pavel Yushchenko

added error messages, fixes reqired fields, add validation for Statgrad

parent b0da5adf
...@@ -62,13 +62,10 @@ class UserProfile(models.Model): ...@@ -62,13 +62,10 @@ class UserProfile(models.Model):
# This is not visible to other users, but could introduce holes later # This is not visible to other users, but could introduce holes later
user = models.OneToOneField(User, unique=True, db_index=True, related_name='profile') user = models.OneToOneField(User, unique=True, db_index=True, related_name='profile')
name = models.CharField(blank=True, max_length=255, db_index=True) name = models.CharField(blank=True, max_length=255, db_index=True)
lastname = models.CharField(blank=False, null=True, max_length=30, db_index=True) lastname = models.CharField(blank=False, null=True, max_length=30, db_index=True)
firstname = models.CharField(blank=False, null=True, max_length=30, db_index=True) firstname = models.CharField(blank=False, null=True, max_length=30, db_index=True)
middlename = models.CharField(blank=False, null=True, max_length=30, db_index=True) middlename = models.CharField(blank=False, null=True, max_length=30, db_index=True)
meta = models.TextField(blank=True) # JSON dictionary for future expansion meta = models.TextField(blank=True) # JSON dictionary for future expansion
courseware = models.CharField(blank=True, max_length=255, default='course.xml') courseware = models.CharField(blank=True, max_length=255, default='course.xml')
...@@ -82,7 +79,7 @@ class UserProfile(models.Model): ...@@ -82,7 +79,7 @@ class UserProfile(models.Model):
this_year = datetime.now(UTC).year this_year = datetime.now(UTC).year
VALID_YEARS = range(this_year, this_year - 120, -1) VALID_YEARS = range(this_year, this_year - 120, -1)
year_of_birth = models.IntegerField(blank=True, null=True, db_index=True) year_of_birth = models.IntegerField(blank=True, null=True, db_index=True)
GENDER_CHOICES = (('m', 'Male'), ('f', 'Female'), ('o', 'Other')) GENDER_CHOICES = (('m', 'Male'), ('f', 'Female'), ('o', 'Other'))
gender = models.CharField( gender = models.CharField(
blank=True, null=True, max_length=6, db_index=True, choices=GENDER_CHOICES blank=True, null=True, max_length=6, db_index=True, choices=GENDER_CHOICES
...@@ -189,11 +186,11 @@ class UserProfile(models.Model): ...@@ -189,11 +186,11 @@ class UserProfile(models.Model):
('first', _("First")), ('first', _("First")),
('second', _("Second")) ('second', _("Second"))
) )
work_qualification_category = models.CharField(blank=False, null=True, max_length=10, db_index=False, choices=WORK_QUALIFICATION_CATEGORY_CHOICES) work_qualification_category = models.CharField(blank=False, null=True, max_length=10, db_index=False, choices=WORK_QUALIFICATION_CATEGORY_CHOICES)
work_qualification_category_year = models.IntegerField(blank=False, null=True, db_index=True) work_qualification_category_year = models.IntegerField(blank=False, null=True, db_index=True)
contact_phone = models.CharField(blank=False, null=True, max_length=10, db_index=False) contact_phone = models.CharField(blank=False, null=True, max_length=10, db_index=False)
mailing_address = models.TextField(blank=True, null=True) mailing_address = models.TextField(blank=True, null=True)
goals = models.TextField(blank=True, null=True) goals = models.TextField(blank=True, null=True)
allow_certificate = models.BooleanField(default=1) allow_certificate = models.BooleanField(default=1)
......
...@@ -526,6 +526,19 @@ def change_setting(request): ...@@ -526,6 +526,19 @@ def change_setting(request):
'location': up.location, })) 'location': up.location, }))
def _validate_statgradlogin(login):
"""
Raises ValidationError
"""
p = re.compile('sch\d+\Z')
try:
if p.match(login) is None:
raise ValidationError
except:
raise ValidationError
def _do_create_account(post_vars): def _do_create_account(post_vars):
""" """
Given cleaned post variables, create the User and UserProfile objects, as well as the Given cleaned post variables, create the User and UserProfile objects, as well as the
...@@ -557,6 +570,7 @@ def _do_create_account(post_vars): ...@@ -557,6 +570,7 @@ def _do_create_account(post_vars):
registration.register(user) registration.register(user)
profile = UserProfile(user=user) profile = UserProfile(user=user)
profile.name = "%s %s %s" % (post_vars.get('lastname'), post_vars.get('firstname'), post_vars.get('middlename'))
profile.lastname = post_vars.get('lastname') profile.lastname = post_vars.get('lastname')
profile.firstname = post_vars.get('firstname') profile.firstname = post_vars.get('firstname')
profile.middlename = post_vars.get('middlename') profile.middlename = post_vars.get('middlename')
...@@ -664,30 +678,30 @@ def create_account(request, post_override=None): ...@@ -664,30 +678,30 @@ def create_account(request, post_override=None):
required_post_vars = ['username', 'email', 'name', 'password', 'honor_code'] required_post_vars = ['username', 'email', 'name', 'password', 'honor_code']
for a in required_post_vars: for a in required_post_vars:
if len(post_vars[a]) < 1: if len(post_vars[a]) < 2:
error_str = {'username': 'Username must be minimum of two characters long.', error_str = {'username': _('Username must be minimum of two characters long.'),
'email': 'A properly formatted e-mail is required.', 'email': _('A properly formatted e-mail is required.'),
'name': 'Your legal name must be a minimum of two characters long.', 'name': _('Your legal name must be a minimum of two characters long.'),
'password': 'A valid password is required.', 'password': _('A valid password is required.'),
'terms_of_service': 'Accepting Terms of Service is required.', 'terms_of_service': _('Accepting Terms of Service is required.'),
'honor_code': 'Agreeing to the Honor Code is required.', 'honor_code': _('Agreeing to the Honor Code is required.'),
'lastname': 'Aht', 'lastname': _('Lastname must be a minimum of two characters long.'),
'firstname': '', 'firstname': _('Firstname must be a minimum of two characters long.'),
'middlename': '', 'middlename': _('Middlename must be a minimum of two characters long.'),
'year_of_birth': '', 'year_of_birth': _('Year of birth is required'),
'level_of_education': '', 'level_of_education': _('Education level is required'),
'education_place': '', 'education_place': _('Education place is required'),
'education_year': '', 'education_year': _('Education year is required'),
'work_type': '', 'work_type': _('Work type is required'),
'work_number': '', 'work_number': _('Work number is required'),
'work_name': '', 'work_name': _('Work name is required'),
'work_login': '', 'work_login': _('Work StatGrad login is required'),
'work_location': '', 'work_location': _('Work location is required'),
'work_occupation': '', 'work_occupation': _('Work occupation is required'),
'work_teaching_experience': '', 'work_teaching_experience': _('Work teaching experience is required'),
'work_qualification_category': '', 'work_qualification_category': _('Work qualification category is required'),
'work_qualification_category_year': '', 'work_qualification_category_year': _('Work qualification year is required'),
'contact_phone': ''} 'contact_phone': _('Contact phone is required')}
js['value'] = error_str[a] js['value'] = error_str[a]
js['field'] = a js['field'] = a
return HttpResponse(json.dumps(js)) return HttpResponse(json.dumps(js))
...@@ -699,6 +713,13 @@ def create_account(request, post_override=None): ...@@ -699,6 +713,13 @@ def create_account(request, post_override=None):
js['field'] = 'email' js['field'] = 'email'
return HttpResponse(json.dumps(js)) return HttpResponse(json.dumps(js))
try:
_validate_statgradlogin(post_vars['work_login'])
except ValidationError:
js['value'] = _("Valid StatGrad login is required.").format(field=a)
js['field'] = 'work_login'
return HttpResponse(json.dumps(js))
# try: # try:
# validate_slug(post_vars['username']) # validate_slug(post_vars['username'])
# except ValidationError: # except ValidationError:
......
...@@ -25,8 +25,9 @@ ...@@ -25,8 +25,9 @@
<label data-field="email" for="signup_email">${_('E-mail')}</label> <label data-field="email" for="signup_email">${_('E-mail')}</label>
<input id="signup_email" type="email" name="email" placeholder="${_('e.g. yourname@domain.com')}" required /> <input id="signup_email" type="email" name="email" placeholder="${_('e.g. yourname@domain.com')}" required />
</span> </span>
<span class="field required text" id="field-password">
<label data-field="password" for="signup_password">${_('Password')}</label> <label data-field="password" for="signup_password">${_('Password')}</label>
<input id="signup_password" type="password" name="password" placeholder="&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;" required /> <input id="signup_password" type="password" name="password" placeholder="&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;" required aria-required="true" />
</span> </span>
</div> </div>
...@@ -77,11 +78,11 @@ ...@@ -77,11 +78,11 @@
<span class="field text" id="field-education-qualification"> <span class="field text" id="field-education-qualification">
<label for="education-qualification">${_('Diploma qualification')}</label> <label for="education-qualification">${_('Diploma qualification')}</label>
<input id="education-qualification" type="text" name="education_qualification" value="" required aria-required="true" /> <input id="education-qualification" type="text" name="education_qualification" value="" />
</span> </span>
<span class="field text" id="field-education-specialty"> <span class="field text" id="field-education-specialty">
<label for="education-specialty">${_('Diploma specialty')}</label> <label for="education-specialty">${_('Diploma specialty')}</label>
<input id="education-specialty" type="text" name="education_specialty" value="" required aria-required="true" /> <input id="education-specialty" type="text" name="education_specialty" value="" />
</span> </span>
<span class="field required select" id="field-work-type"> <span class="field required select" id="field-work-type">
<label for="work-type">${_("Type of educational institution")}</label> <label for="work-type">${_("Type of educational institution")}</label>
...@@ -137,7 +138,7 @@ ...@@ -137,7 +138,7 @@
</span> </span>
<span class="field text" id="field-work-managing-experience"> <span class="field text" id="field-work-managing-experience">
<label for="work-managing-experience">${_('Managing experience at educational institution')}</label> <label for="work-managing-experience">${_('Managing experience at educational institution')}</label>
<input id="work-managing-experience" type="text" name="work-managing-experience" value="" required aria-required="true" /> <input id="work-managing-experience" type="text" name="work-managing-experience" value=""/>
</span> </span>
<span class="field select" id="field-work-qualification-category"> <span class="field select" id="field-work-qualification-category">
<label for="work-qualification-category">${_("Qualification category")}</label> <label for="work-qualification-category">${_("Qualification category")}</label>
...@@ -152,7 +153,7 @@ ...@@ -152,7 +153,7 @@
<label for="work-qualification-category-year">${_('Qualification category year')}</label> <label for="work-qualification-category-year">${_('Qualification category year')}</label>
<input id="work-qualification-category-year" type="text" name="work_qualification_category_year" value="" required aria-required="true" /> <input id="work-qualification-category-year" type="text" name="work_qualification_category_year" value="" required aria-required="true" />
</span> </span>
<span class="field text" id="field-contact-phone"> <span class="field required text" id="field-contact-phone">
<label for="contact-phone">${_('Contact phone')}</label> <label for="contact-phone">${_('Contact phone')}</label>
<input id="contact-phone" type="text" name="contact_phone" value="" required aria-required="true" /> <input id="contact-phone" type="text" name="contact_phone" value="" required aria-required="true" />
</span> </span>
......
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