diff --git a/libraries/views.py b/libraries/views.py index a29aeb8e..1c27ae0a 100644 --- a/libraries/views.py +++ b/libraries/views.py @@ -102,22 +102,42 @@ class LibraryDetail(CategoryMixin, FormMixin, DetailView): def get_context_data(self, **kwargs): """Set the form action to the main libraries page""" context = super().get_context_data(**kwargs) - context["documentation_url"] = self.get_documentation_url() + + # Get fields related to Boost versions context["version"] = self.get_version() - context["maintainers"] = self.get_maintainers(context["version"]) + latest_version = Version.objects.most_recent() + context["latest_version"] = latest_version context["versions"] = ( Version.objects.active() .filter(library_version__library=self.object) .distinct() .order_by("-release_date") ) + + # Show an alert if the user is on an older version + if context["version"] != latest_version: + context["version_alert"] = True + context["latest_library_version"] = self.get_current_library_version( + context["version"] + ) + else: + context["version_alert"] = False + + # Get general data and version-sensitive data + context["documentation_url"] = self.get_documentation_url() + context["github_url"] = self.get_github_url(context["version"]) + context["maintainers"] = self.get_maintainers(context["version"]) + + # Populate the commit graphs + context["commit_data_annual"] = self.get_commit_data_annual() + context["commit_data_last_12_months"] = self.get_commit_data_last_12_months() + + # Populate the library description client = GithubAPIClient(repo_slug=self.object.github_repo) context["description"] = self.object.get_description( client, tag=context["version"].name ) - context["github_url"] = self.get_github_url(context["version"]) - context["commit_data_annual"] = self.get_commit_data_annual() - context["commit_data_last_12_months"] = self.get_commit_data_last_12_months() + return context def get_object(self): @@ -206,6 +226,13 @@ class LibraryDetail(CategoryMixin, FormMixin, DetailView): result = self._prepare_commit_data(prepared_commit_data, "monthly") return result + def get_current_library_version(self, version): + """Return the library-version for the latest version of Boost""" + # Avoid raising an error if the library has been removed from the latest version + return LibraryVersion.objects.filter( + library=self.object, version=version + ).first() + def get_documentation_url(self): """Return the URL for the link to the external Boost documentation.""" obj = self.get_object() diff --git a/templates/libraries/detail.html b/templates/libraries/detail.html index 5eca76bb..2446213e 100644 --- a/templates/libraries/detail.html +++ b/templates/libraries/detail.html @@ -40,6 +40,9 @@ + + {% include "libraries/includes/version_alert.html" %} +
This is an older version and was released in {{ version.release_date|date:"Y"}}. The current version is {{ latest_version.display_name }}.
+This is an older version and was released in {{ version.release_date|date:"Y"}}. + The current version is + {% if latest_library_version %} + + {% else %} + + {% endif %} + {{ latest_version.display_name }}. +