Changed University Student expected graduation date to be a dynamic dropdown.
authorLennard de Rijk <ljvderijk@gmail.com>
Sat, 30 May 2009 09:19:10 +0200
changeset 2371 805400745f57
parent 2370 85ed68167efb
child 2372 f1cbafd21f75
child 2373 05ab9393303d
Changed University Student expected graduation date to be a dynamic dropdown. The range of choices is dynamically made by taking the current_year-1 to the current_year+20. It does not start at the current year because a Student might need to change it's profile during a Program that runs across multiple years.
app/soc/models/student.py
app/soc/views/models/student.py
--- a/app/soc/models/student.py	Sat May 30 01:03:20 2009 +0200
+++ b/app/soc/models/student.py	Sat May 30 09:19:10 2009 +0200
@@ -64,8 +64,7 @@
   degree.group = ugettext("5. Education")
   expected_graduation = db.IntegerProperty(required=True,
       verbose_name=ugettext('Expected Graduation Year'))
-  expected_graduation.help_text = ugettext("Year in integer format only!")
-  expected_graduation.example_text = ugettext('Year only, for example "2012"')
+  expected_graduation.help_text = ugettext("Pick your expected graduation year")
   expected_graduation.group = ugettext("5. Education")
 
   #: Property to gain insight into where students heard about this program
--- a/app/soc/views/models/student.py	Sat May 30 01:03:20 2009 +0200
+++ b/app/soc/views/models/student.py	Sat May 30 09:19:10 2009 +0200
@@ -22,6 +22,8 @@
   ]
 
 
+import time
+
 from django import forms
 from django.utils.translation import ugettext
 
@@ -99,11 +101,17 @@
 
     new_params['extra_dynaexclude'] = ['agreed_to_tos', 'school']
 
+    current_year = time.gmtime().tm_year
+    # the current year is not the minimum because a program could span
+    # more than one year
+    allowed_years = range(current_year-1, current_year+20)
+
     new_params['create_extra_dynaproperties'] = {
-        'expected_graduation': forms.IntegerField(required=True,
-                                                  max_value=2030,
-                                                  min_value=2009)
-        }
+        'expected_graduation': forms.TypedChoiceField(
+            choices=[(x,x) for x in allowed_years],
+            coerce=lambda val: int(val)
+            )
+        } 
 
     new_params['create_dynafields'] = [
         {'name': 'scope_path',