|
2 | 2 |
|
3 | 3 | import csv
|
4 | 4 | import logging
|
| 5 | +from urllib.parse import urlparse |
| 6 | +from readthedocs.core.resolver import resolve, resolve_path |
5 | 7 |
|
6 | 8 | from allauth.socialaccount.models import SocialAccount
|
7 | 9 | from django.conf import settings
|
@@ -462,8 +464,36 @@ class ProjectRelationshipList(ProjectRelationshipMixin, ListView):
|
462 | 464 | def get_context_data(self, **kwargs):
|
463 | 465 | ctx = super().get_context_data(**kwargs)
|
464 | 466 | ctx['superproject'] = self.project.superprojects.first()
|
| 467 | + ctx['subprojects_and_urls'] = self.get_subprojects_and_urls() |
465 | 468 | return ctx
|
466 | 469 |
|
| 470 | + def get_subprojects_and_urls(self): |
| 471 | + """ |
| 472 | + Get a tuple of subprojects and its absolute URls. |
| 473 | +
|
| 474 | + All subprojects share the domain from the parent, |
| 475 | + so instead of resolving the domain and path of each subproject, |
| 476 | + we only resolve the path of each one. |
| 477 | + """ |
| 478 | + subprojects_and_urls = [] |
| 479 | + |
| 480 | + main_domain = resolve(self.project) |
| 481 | + parsed_main_domain = urlparse(main_domain) |
| 482 | + |
| 483 | + subprojects = self.object_list.select_related('child') |
| 484 | + for subproject in subprojects: |
| 485 | + subproject_path = resolve_path(subproject.child) |
| 486 | + parsed_subproject_domain = parsed_main_domain._replace( |
| 487 | + path=subproject_path, |
| 488 | + ) |
| 489 | + subprojects_and_urls.append( |
| 490 | + ( |
| 491 | + subproject, |
| 492 | + parsed_subproject_domain.geturl(), |
| 493 | + ) |
| 494 | + ) |
| 495 | + return subprojects_and_urls |
| 496 | + |
467 | 497 |
|
468 | 498 | class ProjectRelationshipCreate(ProjectRelationshipMixin, CreateView):
|
469 | 499 |
|
|
0 commit comments