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