From 0403f837c46470f0d58763a4b31faf407a4c707b Mon Sep 17 00:00:00 2001 From: Lacey Williams Henschel Date: Tue, 9 May 2023 15:54:24 -0700 Subject: [PATCH] :sparkles: Add display for cxxstd value --- libraries/models.py | 15 +++++++++++++++ libraries/tests/test_models.py | 14 +++++++++++--- templates/includes/_header.html | 2 +- templates/libraries/detail.html | 7 +++++-- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/libraries/models.py b/libraries/models.py index 9949aca5..be3f9131 100644 --- a/libraries/models.py +++ b/libraries/models.py @@ -100,6 +100,21 @@ class Library(models.Model): self.slug = slugify(self.name) return super().save(*args, **kwargs) + def get_cpp_standard_minimum_display(self): + """Returns the display name for the C++ standard, or the value if not found. + + Source of values is + https://docs.cppalliance.org/user-guide/prev/library_metadata.html""" + display_names = { + "98": "C++98", + "03": "C98/C03", + "11": "C++11", + "14": "C++14", + "17": "C++17", + "20": "C++20", + } + return display_names.get(self.cpp_standard_minimum, self.cpp_standard_minimum) + def github_properties(self): """Returns the owner and repo name for the library""" parts = urlparse(self.github_url) diff --git a/libraries/tests/test_models.py b/libraries/tests/test_models.py index ea4aefcd..179ae31c 100644 --- a/libraries/tests/test_models.py +++ b/libraries/tests/test_models.py @@ -1,6 +1,16 @@ from model_bakery import baker +def test_get_cpp_standard_minimum_display(library): + library.cpp_standard_minimum = "11" + library.save() + assert library.get_cpp_standard_minimum_display() == "C++11" + + library.cpp_standard_minimum = "42" + library.save() + assert library.get_cpp_standard_minimum_display() == "42" + + def test_github_properties(library): properties = library.github_properties() assert properties["owner"] == "boostorg" @@ -52,9 +62,7 @@ def test_library_version_multiple_versions(library, library_version): library_version__version=library_version.version ).exists() other_version = baker.make("versions.Version", name="New Version") - new_library_version = baker.make( - "libraries.LibraryVersion", library=library, version=other_version - ) + baker.make("libraries.LibraryVersion", library=library, version=other_version) assert library.versions.count() == 2 assert library.versions.filter( library_version__version=library_version.version diff --git a/templates/includes/_header.html b/templates/includes/_header.html index dd606d84..f54e8d50 100644 --- a/templates/includes/_header.html +++ b/templates/includes/_header.html @@ -36,7 +36,7 @@ x-transition:leave="transition ease-in duration-75" x-transition:leave-start="transform opacity-100 scale-100" x-transition:leave-end="transform opacity-0 scale-95" - class="absolute -top-[2px] -right-2 z-10" + class="absolute -right-2 z-10 -top-[2px]" x-ref="search-form" x-description="Search" role="menu" diff --git a/templates/libraries/detail.html b/templates/libraries/detail.html index 134faae2..312b73fa 100644 --- a/templates/libraries/detail.html +++ b/templates/libraries/detail.html @@ -33,8 +33,11 @@ Github Issues Source Code Since 2019 - C++11 - Categories: Memory + {{ object.get_cpp_standard_minimum_display }} + Categories: + {% for category in object.categories.all %} + {{ category.name }} + {% endfor %}

{{ object.description }}