@@ -50,38 +50,29 @@ def get_version_compare_data(project, base_version=None):
50
50
return ret_val
51
51
52
52
53
- @decorators .api_view (['GET' ])
54
- @decorators .permission_classes ((permissions .AllowAny ,))
55
- @decorators .renderer_classes ((JSONRenderer , JSONPRenderer ))
56
- def footer_html (request ):
57
- """Render and return footer markup."""
58
- project_slug = request .GET .get ('project' , None )
59
- version_slug = request .GET .get ('version' , None )
60
- page_slug = request .GET .get ('page' , None )
61
- theme = request .GET .get ('theme' , False )
53
+ def footer_path (main_project , page_slug ):
54
+ if page_slug and page_slug != "index" :
55
+ if main_project .documentation_type in ("sphinx_htmldir" , "mkdocs" ):
56
+ return page_slug + "/"
57
+ elif main_project .documentation_type == "sphinx_singlehtml" :
58
+ return "index.html#document-" + page_slug
59
+ else :
60
+ return page_slug + ".html"
61
+ else :
62
+ return ""
63
+
64
+
65
+ def version_context (project , request ):
66
+ """Derive extra footer context by looking up the requested version."""
67
+ page_slug = request .GET .get ('page' )
68
+ version_slug = request .GET .get ('version' )
62
69
docroot = request .GET .get ('docroot' , '' )
63
- subproject = request .GET .get ('subproject' , False )
64
70
source_suffix = request .GET .get ('source_suffix' , '.rst' )
71
+ main_project = project .main_language_project or project
65
72
66
- new_theme = (theme == "sphinx_rtd_theme" )
67
- using_theme = (theme == "default" )
68
- project = get_object_or_404 (Project , slug = project_slug )
69
73
version = get_object_or_404 (
70
74
Version .objects .public (request .user , project = project , only_active = False ),
71
75
slug = version_slug )
72
- main_project = project .main_language_project or project
73
-
74
- if page_slug and page_slug != "index" :
75
- if (
76
- main_project .documentation_type == "sphinx_htmldir" or
77
- main_project .documentation_type == "mkdocs" ):
78
- path = page_slug + "/"
79
- elif main_project .documentation_type == "sphinx_singlehtml" :
80
- path = "index.html#document-" + page_slug
81
- else :
82
- path = page_slug + ".html"
83
- else :
84
- path = ""
85
76
86
77
if version .type == TAG and version .project .has_pdf (version .slug ):
87
78
print_url = (
@@ -92,35 +83,52 @@ def footer_html(request):
92
83
else :
93
84
print_url = None
94
85
95
- version_compare_data = get_version_compare_data (project , version )
96
-
97
- context = {
98
- 'project' : project ,
86
+ return {
99
87
'version' : version ,
100
- 'path' : path ,
88
+ 'path' : footer_path ( main_project , page_slug ) ,
101
89
'downloads' : version .get_downloads (pretty = True ),
102
- 'current_version' : version .verbose_name ,
103
- 'versions' : project .ordered_active_versions (user = request .user ),
104
90
'main_project' : main_project ,
105
91
'translations' : main_project .translations .all (),
92
+ 'current_version' : version .verbose_name ,
93
+ 'print_url' : print_url ,
94
+ 'github_edit_url' : version .get_github_url (docroot , page_slug , source_suffix , 'edit' ),
95
+ 'github_view_url' : version .get_github_url (docroot , page_slug , source_suffix , 'view' ),
96
+ 'bitbucket_url' : version .get_bitbucket_url (docroot , page_slug , source_suffix ),
97
+ }
98
+
99
+
100
+ @decorators .api_view (['GET' ])
101
+ @decorators .permission_classes ((permissions .AllowAny ,))
102
+ @decorators .renderer_classes ((JSONRenderer , JSONPRenderer ))
103
+ def footer_html (request ):
104
+ """Render and return footer markup."""
105
+ project_slug = request .GET .get ('project' , None )
106
+ theme = request .GET .get ('theme' , False )
107
+ subproject = request .GET .get ('subproject' , False )
108
+
109
+ new_theme = (theme == "sphinx_rtd_theme" )
110
+ using_theme = (theme == "default" )
111
+ project = get_object_or_404 (Project , slug = project_slug )
112
+
113
+ context = {
114
+ 'project' : project ,
115
+ 'versions' : project .ordered_active_versions (user = request .user ),
106
116
'current_language' : project .language ,
107
117
'using_theme' : using_theme ,
108
118
'new_theme' : new_theme ,
109
119
'settings' : settings ,
110
120
'subproject' : subproject ,
111
- 'print_url' : print_url ,
112
- 'github_edit_url' : version .get_github_url (docroot , page_slug , source_suffix , 'edit' ),
113
- 'github_view_url' : version .get_github_url (docroot , page_slug , source_suffix , 'view' ),
114
- 'bitbucket_url' : version .get_bitbucket_url (docroot , page_slug , source_suffix ),
115
121
'theme' : theme ,
116
122
}
123
+ context .update (version_context (project , request ))
117
124
118
125
request_context = RequestContext (request , context )
119
126
html = template_loader .get_template ('restapi/footer.html' ).render (request_context )
127
+ version = context ['version' ]
120
128
resp_data = {
121
129
'html' : html ,
122
130
'version_active' : version .active ,
123
- 'version_compare' : version_compare_data ,
131
+ 'version_compare' : get_version_compare_data ( project , version ) ,
124
132
'version_supported' : version .supported ,
125
133
}
126
134
0 commit comments