Skip to content

Commit

Permalink
Merge pull request #2 from arbisoft/dsheraz/validation
Browse files Browse the repository at this point in the history
Form updates
  • Loading branch information
DawoudSheraz authored Oct 24, 2019
2 parents 0704a13 + 1c8cfa3 commit d5f8971
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 19 deletions.
28 changes: 14 additions & 14 deletions freshgrad_test/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@


CAMPUS = (
('Lahore', _('Lahore')),
('Faisalabad', _('Faisalabad')),
('Islamabad', _('Islamabad')),
('Peshawar', _('Peshawar')),
('Taxilla', _('Taxilla')),
('Vehari', _('Vehari')),
('Gujrat', _('Gujrat')),
('Mianwali', _('Mianwali')),
('Multan', _('Multan')),
('Bahawalpur', _('Bahawalpur')),
('Bahawalnagar', _('Bahawalnagar')),
('Rahim Yar Khan', _('Rahim Yar Khan')),
('Sargodha', _('Sargodha')),
('Other', _('Other'))
('Lahore', 'Lahore'),
('Faisalabad', 'Faisalabad'),
('Islamabad', 'Islamabad'),
('Peshawar', 'Peshawar'),
('Taxilla', 'Taxilla'),
('Vehari', 'Vehari'),
('Gujrat', 'Gujrat'),
('Mianwali', 'Mianwali'),
('Multan', 'Multan'),
('Bahawalpur', 'Bahawalpur'),
('Bahawalnagar', 'Bahawalnagar'),
('Rahim Yar Khan', 'Rahim Yar Khan'),
('Sargodha', 'Sargodha'),
('Other', 'Other')
)
21 changes: 17 additions & 4 deletions freshgrad_test/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ class CandidateInfoForm(forms.ModelForm):
)
]
)
other_university = forms.CharField(
label=_("Mention University/Campus details if not present in list"),
required=False
)

def clean_other_university(self):
"""
Check that the user has provided the relevant information
if the university/campus information is not present in the
given options.
"""
university = self.cleaned_data['university']
campus = self.cleaned_data['campus']
other_university = (self.cleaned_data['other_university']).strip()
if other_university == '' and (university == 'Other' or campus == 'Other'):
raise forms.ValidationError(_("Please provide University/Campus details."))
return other_university

class Meta(object):
model = CandidateInfo
Expand Down Expand Up @@ -57,10 +74,6 @@ class Meta(object):
'why_arbisoft': {
'field_type': 'textarea',
},
'expected_salary': { # added this to hide salary expectation field for internship test
'field_type': 'hidden',
'default': 'N/A',
},
'career_plans': {
'field_type': 'textarea',
},
Expand Down
20 changes: 20 additions & 0 deletions freshgrad_test/migrations/0005_auto_20191023_0940.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.25 on 2019-10-23 09:40
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('freshgrad_test', '0004_auto_20191015_0801'),
]

operations = [
migrations.AlterField(
model_name='candidateinfo',
name='university',
field=models.CharField(choices=[(b'COMSATS', 'COMSATS'), (b'University of Engineering & Technology', 'University of Engineering & Technology'), (b'National University of Sciences & Technology', 'National University of Sciences & Technology'), (b'Bahria University', 'Bahria University'), (b'NAMAL', 'NAMAL'), (b'University of Gujrat', 'University of Gujrat'), (b'Islamia University of Bahawalpur', 'Islamia University of Bahawalpur'), (b'PUCIT', 'PUCIT'), (b'GIKI', 'GIKI'), (b'FAST', 'FAST'), (b'Superior University', 'Superior University'), (b'Imperial College', 'Imperial College'), (b'University of Central Punjab', 'University of Central Punjab'), (b'Forman Christian College', 'Forman Christian College'), (b'Szabist', 'Szabist'), (b'Lahore College for Women', 'Lahore College for Women'), (b'University of Lahore', 'University of Lahore'), (b'Kinnaird College', 'Kinnaird College'), (b'University of Management & Technology', 'University of Management & Technology'), (b'AJK University', 'AJK University'), (b'BZU Multan', 'BZU Multan'), (b'Islamia College University', 'Islamia College University'), (b'AIR University', 'AIR University'), (b'Information Technology University', 'Information Technology University'), (b'University of Peshawar', 'University of Peshawar'), (b'Virtual University', 'Virtual University'), (b'Lahore University of Management & Sciences', 'Lahore University of Management & Sciences'), (b'University of Sargodha', 'University of Sargodha'), (b'International Islamic University', 'International Islamic University'), (b'Other', 'Other')], max_length=100),
),
]
2 changes: 1 addition & 1 deletion freshgrad_test/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CandidateInfo(models.Model):
"""
user = models.OneToOneField(USER_MODEL)
cnic_number = models.CharField(max_length=20, verbose_name=_("CNIC Number"))
university = models.CharField(max_length=60, choices=UNIVERSITIES)
university = models.CharField(max_length=100, choices=UNIVERSITIES)
campus = models.CharField(max_length=30, choices=CAMPUS)
other_university = models.CharField(
max_length=50, blank=True, verbose_name=_("University details, if not in list")
Expand Down

0 comments on commit d5f8971

Please sign in to comment.