Skip to content

Commit 4f1f82f

Browse files
Enable subproject filters for projects with subprojects (#11674)
* Enable subproject filters for projects with subprojects This at least shows the UI element if it makes sense to show. Currently there's no way without knowing the query syntax to get subprojects, which has caused confusion for a few of our users and broke existing behavior. Refs #11638 * Also show on subprojects * Update to support subprojects having the right filter * Fix tests * Apply suggestions from code review Co-authored-by: Manuel Kaufmann <[email protected]> * Check for version --------- Co-authored-by: Manuel Kaufmann <[email protected]>
1 parent ec370d0 commit 4f1f82f

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

readthedocs/proxito/tests/test_hosting.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ def test_number_of_queries_project_version_slug(self):
736736
active=True,
737737
)
738738

739-
with self.assertNumQueries(22):
739+
with self.assertNumQueries(24):
740740
r = self.client.get(
741741
reverse("proxito_readthedocs_docs_addons"),
742742
{
@@ -765,7 +765,7 @@ def test_number_of_queries_url(self):
765765
active=True,
766766
)
767767

768-
with self.assertNumQueries(24):
768+
with self.assertNumQueries(26):
769769
r = self.client.get(
770770
reverse("proxito_readthedocs_docs_addons"),
771771
{
@@ -801,7 +801,7 @@ def test_number_of_queries_url_subproject(self):
801801
active=True,
802802
)
803803

804-
with self.assertNumQueries(31):
804+
with self.assertNumQueries(35):
805805
r = self.client.get(
806806
reverse("proxito_readthedocs_docs_addons"),
807807
{
@@ -827,7 +827,7 @@ def test_number_of_queries_url_translations(self):
827827
language=language,
828828
)
829829

830-
with self.assertNumQueries(60):
830+
with self.assertNumQueries(62):
831831
r = self.client.get(
832832
reverse("proxito_readthedocs_docs_addons"),
833833
{

readthedocs/proxito/views/hosting.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,7 @@ def _v1(self, project, version, build, filename, url, request):
493493
# "Include subprojects",
494494
# f"subprojects:{project.slug}/{version.slug}",
495495
# ],
496-
]
497-
if version
498-
else [],
496+
],
499497
"default_filter": f"project:{project.slug}/{version.slug}"
500498
if version
501499
else None,
@@ -514,6 +512,28 @@ def _v1(self, project, version, build, filename, url, request):
514512
},
515513
}
516514

515+
# Show the subprojects filter on the parent project and subproject
516+
if version:
517+
# TODO: Remove these queries and try to find a way to get this data
518+
# from the resolver, which has already done these queries.
519+
# TODO: Replace this fixed filters with the work proposed in
520+
# https://github.com/readthedocs/addons/issues/22
521+
if project.subprojects.exists():
522+
data["addons"]["search"]["filters"].append(
523+
[
524+
"Include subprojects",
525+
f"subprojects:{project.slug}/{version.slug}",
526+
]
527+
)
528+
if project.superprojects.exists():
529+
superproject = project.superprojects.first().parent
530+
data["addons"]["search"]["filters"].append(
531+
[
532+
"Include subprojects",
533+
f"subprojects:{superproject.slug}/{version.slug}",
534+
]
535+
)
536+
517537
# DocDiff depends on `url=` GET attribute.
518538
# This attribute allows us to know the exact filename where the request was made.
519539
# If we don't know the filename, we cannot return the data required by DocDiff to work.

0 commit comments

Comments
 (0)