diff --git a/readthedocs/proxito/tests/test_hosting.py b/readthedocs/proxito/tests/test_hosting.py index fdc19e0eefd..bcda4a0383f 100644 --- a/readthedocs/proxito/tests/test_hosting.py +++ b/readthedocs/proxito/tests/test_hosting.py @@ -736,7 +736,7 @@ def test_number_of_queries_project_version_slug(self): active=True, ) - with self.assertNumQueries(22): + with self.assertNumQueries(24): r = self.client.get( reverse("proxito_readthedocs_docs_addons"), { @@ -765,7 +765,7 @@ def test_number_of_queries_url(self): active=True, ) - with self.assertNumQueries(24): + with self.assertNumQueries(26): r = self.client.get( reverse("proxito_readthedocs_docs_addons"), { @@ -801,7 +801,7 @@ def test_number_of_queries_url_subproject(self): active=True, ) - with self.assertNumQueries(31): + with self.assertNumQueries(35): r = self.client.get( reverse("proxito_readthedocs_docs_addons"), { @@ -827,7 +827,7 @@ def test_number_of_queries_url_translations(self): language=language, ) - with self.assertNumQueries(60): + with self.assertNumQueries(62): r = self.client.get( reverse("proxito_readthedocs_docs_addons"), { diff --git a/readthedocs/proxito/views/hosting.py b/readthedocs/proxito/views/hosting.py index b74f9c4ab71..564ee05f928 100644 --- a/readthedocs/proxito/views/hosting.py +++ b/readthedocs/proxito/views/hosting.py @@ -493,9 +493,7 @@ def _v1(self, project, version, build, filename, url, request): # "Include subprojects", # f"subprojects:{project.slug}/{version.slug}", # ], - ] - if version - else [], + ], "default_filter": f"project:{project.slug}/{version.slug}" if version else None, @@ -514,6 +512,28 @@ def _v1(self, project, version, build, filename, url, request): }, } + # Show the subprojects filter on the parent project and subproject + if version: + # TODO: Remove these queries and try to find a way to get this data + # from the resolver, which has already done these queries. + # TODO: Replace this fixed filters with the work proposed in + # https://github.com/readthedocs/addons/issues/22 + if project.subprojects.exists(): + data["addons"]["search"]["filters"].append( + [ + "Include subprojects", + f"subprojects:{project.slug}/{version.slug}", + ] + ) + if project.superprojects.exists(): + superproject = project.superprojects.first().parent + data["addons"]["search"]["filters"].append( + [ + "Include subprojects", + f"subprojects:{superproject.slug}/{version.slug}", + ] + ) + # DocDiff depends on `url=` GET attribute. # This attribute allows us to know the exact filename where the request was made. # If we don't know the filename, we cannot return the data required by DocDiff to work.