Skip to content

Commit 746c157

Browse files
committed
limit schools in registration
1 parent c5ce0ca commit 746c157

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

bullet/competitions/views/register.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,22 @@ def get_context_data(self, **kwargs):
250250
ctx["schools"] = []
251251
query = self.request.GET.get("q")
252252

253+
allowed_types = set(
254+
self.category.educations.values_list(
255+
"grades__school_type_id", flat=True
256+
).distinct()
257+
)
258+
allowed_types = ",".join(map(str, allowed_types))
259+
253260
if query:
254261
result = search.client.index("schools").search(
255262
query,
256263
{
257-
"filter": f"country = '{self.request.COUNTRY_CODE.upper()}' "
258-
f"AND is_hidden = false"
264+
"filter": [
265+
f"country = '{self.request.COUNTRY_CODE.upper()}'",
266+
"is_hidden = false",
267+
f"types IN [{allowed_types}]",
268+
]
259269
},
260270
)
261271
ctx["schools"] = result["hits"]

bullet/education/management/commands/indexschools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def handle(self, *args, **options):
1414

1515
search.client.index("schools").update_settings(
1616
{
17-
"filterableAttributes": ["country", "is_hidden"],
17+
"filterableAttributes": ["country", "is_hidden", "types"],
1818
"sortableAttributes": ["name", "address", "country"],
1919
"rankingRules": [
2020
"words",

bullet/education/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,6 @@ def for_search(self):
9090
"address": self.address,
9191
"search": self.search,
9292
"country": self.country.code,
93+
"types": [t.id for t in self.types.all()],
9394
"is_hidden": self.is_hidden,
9495
}

0 commit comments

Comments
 (0)