diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5aeb0368516a20fd84948c7d6597a89c02226ea3..4c6689f4fad6078bf3c9876130bc08abbf8d2151 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,14 @@ All notable changes to this project will be documented in this file. The format is based on `Keep a Changelog`_, and this project adheres to `Semantic Versioning`_. +Unreleased +---------- + +Fixed +~~~~~ + +* "My overview" and "All lessons" didn't work if there was no current school term. + `2.0rc1`_ - 2021-06-23 ---------------------- diff --git a/aleksis/apps/alsijil/forms.py b/aleksis/apps/alsijil/forms.py index 53b5ffee1c68c2b0645d86753e0eb8eb934d2c0c..cb12a4eb86e424167d4301b31fca0a0dd035b625 100644 --- a/aleksis/apps/alsijil/forms.py +++ b/aleksis/apps/alsijil/forms.py @@ -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, diff --git a/aleksis/apps/alsijil/util/alsijil_helpers.py b/aleksis/apps/alsijil/util/alsijil_helpers.py index b7442f9986730dc23de2611602f06b85e5ef9b9b..29381c6cb76cd424e945b6e42bd2fdddf414c05c 100644 --- a/aleksis/apps/alsijil/util/alsijil_helpers.py +++ b/aleksis/apps/alsijil/util/alsijil_helpers.py @@ -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(