Add field missing_docs to LibraryVersion model

- Add new field to the admin
- Add logic for missing library-version docs to view
- Add tests
This commit is contained in:
Lacey Williams Henschel
2024-01-30 09:55:48 -08:00
committed by Lacey Henschel
parent 6a3f2a5b3a
commit 9e9c6bb6b6
5 changed files with 80 additions and 5 deletions

View File

@@ -122,8 +122,8 @@ class LibraryAdmin(admin.ModelAdmin):
@admin.register(LibraryVersion)
class LibraryVersionAdmin(admin.ModelAdmin):
list_display = ["library", "version", "documentation_url"]
list_filter = ["library", "version"]
list_display = ["library", "version", "missing_docs", "documentation_url"]
list_filter = ["library", "version", "missing_docs"]
ordering = ["library__name", "-version__name"]
search_fields = ["library__name", "version__name"]
change_list_template = "admin/libraryversion_change_list.html"

View File

@@ -0,0 +1,20 @@
# Generated by Django 4.2.2 on 2024-01-30 17:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("libraries", "0017_merge_20230919_2029"),
]
operations = [
migrations.AddField(
model_name="libraryversion",
name="missing_docs",
field=models.BooleanField(
default=False,
help_text="If true, then there are not docs for this version of this library.",
),
),
]

View File

@@ -281,6 +281,10 @@ class LibraryVersion(models.Model):
on_delete=models.CASCADE,
)
maintainers = models.ManyToManyField("users.User", related_name="maintainers")
missing_docs = models.BooleanField(
default=False,
help_text="If true, then there are not docs for this version of this library.",
)
documentation_url = models.CharField(
max_length=255,
blank=True,

View File

@@ -239,7 +239,9 @@ def test_library_detail_context_get_maintainers(tp, user, library_version):
assert response.context["maintainers"][0] == user
def test_library_detail_context_get_documentation_url(tp, user, library_version):
def test_library_detail_context_get_documentation_url_no_docs_link(
tp, user, library_version
):
"""
GET /libraries/{slug}/
Test that the maintainers var appears as expected
@@ -258,6 +260,47 @@ def test_library_detail_context_get_documentation_url(tp, user, library_version)
)
def test_library_detail_context_get_documentation_url_missing_docs_bool(
tp, user, library_version
):
"""
GET /libraries/{slug}/
Test that the maintainers var appears as expected
"""
library_version.documentation_url = None
library_version.missing_docs = True
library_version.save()
library = library_version.library
url = tp.reverse("library-detail", library.slug)
response = tp.get(url)
tp.response_200(response)
assert "documentation_url" in response.context
assert (
response.context["documentation_url"]
== library_version.version.documentation_url
)
def test_library_detail_context_get_documentation_url_docs_present(
tp, user, library_version
):
"""
GET /libraries/{slug}/
Test that the maintainers var appears as expected
"""
library_version.documentation_url = "https://example.com"
library_version.missing_docs = False
library_version.save()
library = library_version.library
url = tp.reverse("library-detail", library.slug)
response = tp.get(url)
tp.response_200(response)
assert "documentation_url" in response.context
assert response.context["documentation_url"] == library_version.documentation_url
def test_libraries_by_version_detail(tp, library_version):
"""GET /libraries/{slug}/{version_slug}/"""
res = tp.get(

View File

@@ -306,9 +306,17 @@ class LibraryDetail(FormMixin, DetailView):
"""Get the documentation URL for the current library."""
obj = self.get_object()
library_version = LibraryVersion.objects.get(library=obj, version=version)
if library_version.documentation_url:
docs_url = version.documentation_url
# If we know the library-version docs are missing, return the version docs
if library_version.missing_docs:
return docs_url
# If we have the library-version docs and believe they are valid, return those
elif library_version.documentation_url:
return library_version.documentation_url
return version.documentation_url
# If we wind up here, return the version docs
else:
return docs_url
def get_github_url(self, version):
"""Get the GitHub URL for the current library."""