@@ -34,11 +34,8 @@ def get_version_compare_data(project, base_version=None, user=None):
34
34
:param base_version: We assert whether or not the base_version is also the
35
35
highest version in the resulting "is_highest" value.
36
36
"""
37
- if (
38
- not project .show_version_warning or
39
- (base_version and base_version .is_external )
40
- ):
41
- return {'is_highest' : False }
37
+ if not project .show_version_warning or (base_version and base_version .is_external ):
38
+ return {"is_highest" : False }
42
39
43
40
versions_qs = Version .internal .public (project = project , user = user ).filter (
44
41
built = True , active = True
@@ -49,21 +46,21 @@ def get_version_compare_data(project, base_version=None, user=None):
49
46
versions_qs = versions_qs .filter (type = TAG )
50
47
51
48
# Optimization
52
- versions_qs = versions_qs .select_related (' project' )
49
+ versions_qs = versions_qs .select_related (" project" )
53
50
54
51
highest_version_obj , highest_version_comparable = highest_version (
55
52
versions_qs ,
56
53
)
57
54
ret_val = {
58
- ' project' : str (highest_version_obj ),
59
- ' version' : str (highest_version_comparable ),
60
- ' is_highest' : True ,
55
+ " project" : str (highest_version_obj ),
56
+ " version" : str (highest_version_comparable ),
57
+ " is_highest" : True ,
61
58
}
62
59
if highest_version_obj :
63
60
# Never link to the dashboard,
64
61
# users reading the docs may don't have access to the dashboard.
65
- ret_val [' url' ] = highest_version_obj .get_absolute_url ()
66
- ret_val [' slug' ] = highest_version_obj .slug
62
+ ret_val [" url" ] = highest_version_obj .get_absolute_url ()
63
+ ret_val [" slug" ] = highest_version_obj .slug
67
64
if base_version and base_version .slug != LATEST :
68
65
try :
69
66
base_version_comparable = parse_version_failsafe (
@@ -72,13 +69,13 @@ def get_version_compare_data(project, base_version=None, user=None):
72
69
if base_version_comparable :
73
70
# This is only place where is_highest can get set. All error
74
71
# cases will be set to True, for non- standard versions.
75
- ret_val [' is_highest' ] = (
72
+ ret_val [" is_highest" ] = (
76
73
base_version_comparable >= highest_version_comparable
77
74
)
78
75
else :
79
- ret_val [' is_highest' ] = True
76
+ ret_val [" is_highest" ] = True
80
77
except (Version .DoesNotExist , TypeError ):
81
- ret_val [' is_highest' ] = True
78
+ ret_val [" is_highest" ] = True
82
79
return ret_val
83
80
84
81
@@ -105,24 +102,24 @@ class BaseFooterHTML(CDNCacheTagsMixin, APIView):
105
102
are called many times, so a basic cache is implemented.
106
103
"""
107
104
108
- http_method_names = [' get' ]
105
+ http_method_names = [" get" ]
109
106
permission_classes = [IsAuthorizedToViewVersion ]
110
107
renderer_classes = [JSONRenderer , JSONPRenderer ]
111
- project_cache_tag = ' rtd-footer'
108
+ project_cache_tag = " rtd-footer"
112
109
113
110
@lru_cache (maxsize = 1 )
114
111
def _get_project (self ):
115
- project_slug = self .request .GET .get (' project' , None )
112
+ project_slug = self .request .GET .get (" project" , None )
116
113
project = get_object_or_404 (Project , slug = project_slug )
117
114
return project
118
115
119
116
@lru_cache (maxsize = 1 )
120
117
def _get_version (self ):
121
- version_slug = self .request .GET .get (' version' , None )
118
+ version_slug = self .request .GET .get (" version" , None )
122
119
123
120
# Hack in a fix for missing version slug deploy
124
121
# that went out a while back
125
- if version_slug == '' :
122
+ if version_slug == "" :
126
123
version_slug = LATEST
127
124
128
125
project = self ._get_project ()
@@ -142,23 +139,23 @@ def _get_active_versions_sorted(self):
142
139
return versions
143
140
144
141
def _get_context (self ):
145
- theme = self .request .GET .get (' theme' , False )
146
- docroot = self .request .GET .get (' docroot' , '' )
147
- source_suffix = self .request .GET .get (' source_suffix' , ' .rst' )
142
+ theme = self .request .GET .get (" theme" , False )
143
+ docroot = self .request .GET .get (" docroot" , "" )
144
+ source_suffix = self .request .GET .get (" source_suffix" , " .rst" )
148
145
149
- new_theme = ( theme == ' sphinx_rtd_theme' )
146
+ new_theme = theme == " sphinx_rtd_theme"
150
147
151
148
project = self ._get_project ()
152
149
main_project = project .main_language_project or project
153
150
version = self ._get_version ()
154
151
155
- page_slug = self .request .GET .get (' page' , '' )
156
- path = ''
157
- if page_slug and page_slug != ' index' :
152
+ page_slug = self .request .GET .get (" page" , "" )
153
+ path = ""
154
+ if page_slug and page_slug != " index" :
158
155
if version .documentation_type in {SPHINX_HTMLDIR , MKDOCS }:
159
- path = re .sub (' /index$' , '' , page_slug ) + '/'
156
+ path = re .sub (" /index$" , "" , page_slug ) + "/"
160
157
else :
161
- path = page_slug + ' .html'
158
+ path = page_slug + " .html"
162
159
163
160
context = {
164
161
"project" : project ,
@@ -176,27 +173,27 @@ def _get_context(self):
176
173
docroot ,
177
174
page_slug ,
178
175
source_suffix ,
179
- ' edit' ,
176
+ " edit" ,
180
177
),
181
- ' github_view_url' : version .get_github_url (
178
+ " github_view_url" : version .get_github_url (
182
179
docroot ,
183
180
page_slug ,
184
181
source_suffix ,
185
- ' view' ,
182
+ " view" ,
186
183
),
187
- ' gitlab_edit_url' : version .get_gitlab_url (
184
+ " gitlab_edit_url" : version .get_gitlab_url (
188
185
docroot ,
189
186
page_slug ,
190
187
source_suffix ,
191
- ' edit' ,
188
+ " edit" ,
192
189
),
193
- ' gitlab_view_url' : version .get_gitlab_url (
190
+ " gitlab_view_url" : version .get_gitlab_url (
194
191
docroot ,
195
192
page_slug ,
196
193
source_suffix ,
197
- ' view' ,
194
+ " view" ,
198
195
),
199
- ' bitbucket_url' : version .get_bitbucket_url (
196
+ " bitbucket_url" : version .get_bitbucket_url (
200
197
docroot ,
201
198
page_slug ,
202
199
source_suffix ,
@@ -214,22 +211,19 @@ def get(self, request, format=None):
214
211
)
215
212
216
213
context = self ._get_context ()
217
- html = template_loader .get_template (' restapi/footer.html' ).render (
214
+ html = template_loader .get_template (" restapi/footer.html" ).render (
218
215
context ,
219
216
request ,
220
217
)
221
218
222
- show_version_warning = (
223
- project .show_version_warning and
224
- not version .is_external
225
- )
219
+ show_version_warning = project .show_version_warning and not version .is_external
226
220
227
221
resp_data = {
228
- ' html' : html ,
229
- ' show_version_warning' : show_version_warning ,
230
- ' version_active' : version .active ,
231
- ' version_compare' : version_compare_data ,
232
- ' version_supported' : version .supported ,
222
+ " html" : html ,
223
+ " show_version_warning" : show_version_warning ,
224
+ " version_active" : version .active ,
225
+ " version_compare" : version_compare_data ,
226
+ " version_supported" : version .supported ,
233
227
}
234
228
235
229
return Response (resp_data )
0 commit comments