1
1
import logging
2
+ import os
2
3
from pprint import pformat
3
4
4
- from rest_framework import generics
5
- from rest_framework import serializers
5
+ from rest_framework import generics , serializers
6
6
from rest_framework .exceptions import ValidationError
7
7
from rest_framework .pagination import PageNumberPagination
8
8
9
9
from readthedocs .search .faceted_search import PageSearch
10
10
from readthedocs .search .utils import get_project_list_or_404
11
11
12
+
12
13
log = logging .getLogger (__name__ )
13
14
14
15
@@ -23,10 +24,29 @@ class PageSearchSerializer(serializers.Serializer):
23
24
version = serializers .CharField ()
24
25
title = serializers .CharField ()
25
26
path = serializers .CharField ()
27
+ # Doc url without extension
26
28
link = serializers .SerializerMethodField ()
29
+ # Doc url with extension
30
+ url = serializers .SerializerMethodField ()
27
31
highlight = serializers .SerializerMethodField ()
28
32
29
33
def get_link (self , obj ):
34
+ """
35
+ Gets the url without extension.
36
+
37
+ .. warning::
38
+ This is only used to keep compatibility with
39
+ the previous search implementation.
40
+ Use `url` instead.
41
+ """
42
+ projects_url = self .context .get ('projects_url' )
43
+ if projects_url :
44
+ docs_url = projects_url [obj .project ]
45
+ path = os .path .splitext (obj .path )[0 ]
46
+ return docs_url + path
47
+
48
+ def get_url (self , obj ):
49
+ """Gets the full url."""
30
50
projects_url = self .context .get ('projects_url' )
31
51
if projects_url :
32
52
docs_url = projects_url [obj .project ]
0 commit comments