@@ -16,9 +16,9 @@ class Meta(object):
16
16
exclude = ['is_active' , 'is_approved' ]
17
17
18
18
19
- def city_options (province ):
19
+ def city_options (all_schools , province ):
20
20
cities = (
21
- School . objects . filter (province = province , is_active = True )
21
+ all_schools . filter (province = province )
22
22
.order_by ('city' )
23
23
.distinct ()
24
24
.values_list ('city' , flat = True )
@@ -28,9 +28,9 @@ def city_options(province):
28
28
return cities
29
29
30
30
31
- def school_options (province , city ):
31
+ def school_options (all_schools , province , city ):
32
32
schools = (
33
- School . objects . filter (province = province , city = city , is_active = True )
33
+ all_schools . filter (province = province , city = city )
34
34
.order_by ('name' )
35
35
.only ('name' , 'address' )
36
36
)
@@ -40,6 +40,11 @@ def school_options(province, city):
40
40
41
41
42
42
class SchoolSelect (forms .Select ):
43
+ def __init__ (self , is_contest_with_coordinator = False , is_coordinator = False , * args , ** kwargs ):
44
+ super (SchoolSelect , self ).__init__ (* args , ** kwargs )
45
+ self .is_contest_with_coordinator = is_contest_with_coordinator
46
+ self .is_coordinator = is_coordinator
47
+
43
48
def render (self , name , value , attrs = None , renderer = None ):
44
49
# check if this is the default renderer
45
50
if renderer is not None and not isinstance (
@@ -59,8 +64,8 @@ def render(self, name, value, attrs=None, renderer=None):
59
64
pass
60
65
61
66
provinces = [('' , _ ("-- Choose province --" ))] + list (PROVINCES )
62
- cities = city_options (province )
63
- schools = school_options (province , city )
67
+ cities = city_options (self . get_schools (), province )
68
+ schools = school_options (self . get_schools (), province , city )
64
69
65
70
attr = {'name' : name , 'id' : 'id_' + name }
66
71
options = [
@@ -71,12 +76,16 @@ def render(self, name, value, attrs=None, renderer=None):
71
76
selects = {
72
77
'attr' : attr ,
73
78
'options' : options ,
74
- # Do not show 'add new' link in admin view. Hack.
75
- 'show_add_new ' : 'oi_oiregistration' not in name ,
79
+ 'is_contest_with_coordinator' : self . is_contest_with_coordinator ,
80
+ 'is_coordinator ' : self . is_coordinator ,
76
81
}
77
82
78
83
return render_to_string ('forms/school_select_form.html' , selects )
79
84
85
+ @staticmethod
86
+ def get_schools ():
87
+ return School .objects .filter (is_active = True )
88
+
80
89
81
90
class OIRegistrationForm (forms .ModelForm ):
82
91
class Meta (object ):
0 commit comments