Skip to content

Commit b179719

Browse files
committed
Use another structure
1 parent ec529e9 commit b179719

File tree

3 files changed

+45
-26
lines changed

3 files changed

+45
-26
lines changed

readthedocs/search/api.py

+27-16
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from readthedocs.search import tasks
1616
from readthedocs.search.faceted_search import PageSearch
1717

18-
from .serializers import PageSearchSerializer, VersionData
18+
from .serializers import PageSearchSerializer, ProjectData, VersionData
1919

2020
log = logging.getLogger(__name__)
2121

@@ -183,15 +183,21 @@ def _get_all_projects_data(self):
183183
.. code::
184184
185185
{
186-
"requests": VersionData(
187-
"latest",
188-
"sphinx",
189-
"https://requests.readthedocs.io/en/latest/",
186+
"requests": ProjectData(
187+
alias='alias',
188+
version=VersionData(
189+
"latest",
190+
"sphinx",
191+
"https://requests.readthedocs.io/en/latest/",
192+
),
190193
),
191-
"requests-oauth": VersionData(
192-
"latest",
193-
"sphinx_htmldir",
194-
"https://requests-oauth.readthedocs.io/en/latest/",
194+
"requests-oauth": ProjectData(
195+
alias=None,
196+
version=VersionData(
197+
"latest",
198+
"sphinx_htmldir",
199+
"https://requests-oauth.readthedocs.io/en/latest/",
200+
),
195201
),
196202
}
197203
@@ -203,11 +209,13 @@ def _get_all_projects_data(self):
203209
main_project = self._get_project()
204210

205211
projects_data = {
206-
main_project.slug: VersionData(
207-
slug=main_version.slug,
208-
doctype=main_version.documentation_type,
209-
docs_url=main_project.get_docs_url(version_slug=main_version.slug),
210-
project_alias=None,
212+
main_project.slug: ProjectData(
213+
alias=None,
214+
version=VersionData(
215+
slug=main_version.slug,
216+
doctype=main_version.documentation_type,
217+
docs_url=main_project.get_docs_url(version_slug=main_version.slug),
218+
),
211219
)
212220
}
213221

@@ -234,11 +242,14 @@ def _get_all_projects_data(self):
234242
if version and self._has_permission(self.request.user, version):
235243
url = subproject.get_docs_url(version_slug=version.slug)
236244
project_alias = subproject.superprojects.values_list('alias', flat=True).first()
237-
projects_data[subproject.slug] = VersionData(
245+
version_data = VersionData(
238246
slug=version.slug,
239247
doctype=version.documentation_type,
240248
docs_url=url,
241-
project_alias=project_alias,
249+
)
250+
projects_data[subproject.slug] = ProjectData(
251+
alias=project_alias,
252+
version=version_data,
242253
)
243254

244255
return projects_data

readthedocs/search/serializers.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222

2323
# Structure used for storing cached data of a version mostly.
24+
ProjectData = namedtuple('ProjectData', ['version', 'alias'])
2425
VersionData = namedtuple('VersionData', ['slug', 'docs_url', 'doctype', 'project_alias'])
2526

2627

@@ -85,19 +86,22 @@ def _get_project_data(self, obj):
8586
project_alias = project.superprojects.values_list('alias', flat=True).first()
8687

8788
projects_data = self.context.setdefault('projects_data', {})
88-
projects_data[obj.project] = VersionData(
89+
version_data = VersionData(
8990
slug=obj.version,
9091
docs_url=docs_url,
91-
project_alias=project_alias,
9292
doctype=None,
9393
)
94+
projects_data[obj.project] = ProjectData(
95+
alias=project_alias,
96+
version=version_data,
97+
)
9498
return projects_data[obj.project]
9599
return None
96100

97101
def get_project_alias(self, obj):
98102
project_data = self._get_project_data(obj)
99103
if project_data:
100-
return project_data.project_alias
104+
return project_data.alias
101105
return None
102106

103107
def get_domain(self, obj):
@@ -117,12 +121,12 @@ def get_path(self, obj):
117121
def _get_full_path(self, obj):
118122
project_data = self._get_project_data(obj)
119123
if project_data:
120-
docs_url = project_data.docs_url
124+
docs_url = project_data.version.docs_url
121125
path = obj.full_path
122126

123127
# Generate an appropriate link for the doctypes that use htmldir,
124128
# and always end it with / so it goes directly to proxito.
125-
if project_data.doctype in {SPHINX_HTMLDIR, MKDOCS}:
129+
if project_data.version.doctype in {SPHINX_HTMLDIR, MKDOCS}:
126130
path = re.sub('(^|/)index.html$', '/', path)
127131

128132
return docs_url.rstrip('/') + '/' + path.lstrip('/')

readthedocs/search/views.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from .serializers import (
1717
PageSearchSerializer,
18+
ProjectData,
1819
ProjectSearchSerializer,
1920
VersionData,
2021
)
@@ -62,12 +63,15 @@ def _get_project_data(self, project, version_slug):
6263
.get(slug=version_slug)
6364
)
6465
docs_url = project.get_docs_url(version_slug=version_slug)
66+
version_data = VersionData(
67+
slug=version_slug,
68+
docs_url=docs_url,
69+
doctype=version_doctype,
70+
)
6571
project_data = {
66-
project.slug: VersionData(
67-
slug=version_slug,
68-
docs_url=docs_url,
69-
doctype=version_doctype,
70-
project_alias=None,
72+
project.slug: ProjectData(
73+
alias=None,
74+
version=version_data,
7175
)
7276
}
7377
return project_data

0 commit comments

Comments
 (0)