Skip to content

Commit 9e08444

Browse files
MasloMaslanetwalen
authored andcommitted
Add MAP course
1 parent 117a90c commit 9e08444

23 files changed

+1198
-119
lines changed

oioioi/base/static/css/select2.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

oioioi/base/static/js/select2.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

oioioi/oi/forms.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class Meta(object):
1616
exclude = ['is_active', 'is_approved']
1717

1818

19-
def city_options(province):
19+
def city_options(all_schools, province):
2020
cities = (
21-
School.objects.filter(province=province, is_active=True)
21+
all_schools.filter(province=province)
2222
.order_by('city')
2323
.distinct()
2424
.values_list('city', flat=True)
@@ -28,9 +28,9 @@ def city_options(province):
2828
return cities
2929

3030

31-
def school_options(province, city):
31+
def school_options(all_schools, province, city):
3232
schools = (
33-
School.objects.filter(province=province, city=city, is_active=True)
33+
all_schools.filter(province=province, city=city)
3434
.order_by('name')
3535
.only('name', 'address')
3636
)
@@ -40,6 +40,11 @@ def school_options(province, city):
4040

4141

4242
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+
4348
def render(self, name, value, attrs=None, renderer=None):
4449
# check if this is the default renderer
4550
if renderer is not None and not isinstance(
@@ -59,8 +64,8 @@ def render(self, name, value, attrs=None, renderer=None):
5964
pass
6065

6166
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)
6469

6570
attr = {'name': name, 'id': 'id_' + name}
6671
options = [
@@ -71,12 +76,16 @@ def render(self, name, value, attrs=None, renderer=None):
7176
selects = {
7277
'attr': attr,
7378
'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,
7681
}
7782

7883
return render_to_string('forms/school_select_form.html', selects)
7984

85+
@staticmethod
86+
def get_schools():
87+
return School.objects.filter(is_active=True)
88+
8089

8190
class OIRegistrationForm(forms.ModelForm):
8291
class Meta(object):

0 commit comments

Comments
 (0)