Skip to content
Snippets Groups Projects
Verified Commit f01d29fc authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

[Register objects table] Use the last known school term if there is no current school term

(cherry picked from commit 4468aa1b)
parent 0d16bb00
No related branches found
No related tags found
1 merge request!209Prepare release 2.0rc2
......@@ -296,8 +296,14 @@ class FilterRegisterObjectForm(forms.Form):
def get_initial(cls, has_documentation: Optional[bool] = None):
date_end = timezone.now().date()
date_start = date_end - timedelta(days=30)
school_term = SchoolTerm.current
# If there is no current school year, use last known school year.
if not school_term:
school_term = SchoolTerm.objects.all().last()
return {
"school_term": SchoolTerm.current,
"school_term": school_term,
"date_start": date_start,
"date_end": date_end,
"has_documentation": has_documentation,
......
......@@ -336,6 +336,11 @@ def generate_list_of_all_register_objects(filter_dict: Dict[str, Any]) -> List[D
# Always force a value for school term, start and end date so that queries won't get too big
initial_filter_data = FilterRegisterObjectForm.get_initial()
filter_dict["school_term"] = filter_dict.get("school_term", initial_filter_data["school_term"])
# If there is not school year at all, there are definitely no data.
if not filter_dict["school_term"]:
return []
filter_dict["date_start"] = filter_dict.get("date_start", initial_filter_data["date_start"])
filter_dict["date_end"] = filter_dict.get("date_end", initial_filter_data["date_end"])
filter_dict["filter_date"] = bool(filter_dict.get("date_start")) and bool(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment