Skip to content

Commit a639939

Browse files
authored
Merge pull request #5502 from stsewd/fix-downloads-display
Don't depend of enabled pdf/epub to show downloads
2 parents caa8b6c + a29ec1f commit a639939

File tree

5 files changed

+29
-46
lines changed

5 files changed

+29
-46
lines changed

readthedocs/builds/models.py

+19-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
"""Models for the builds app."""
42

53
import datetime
@@ -258,32 +256,25 @@ def get_subdomain_url(self):
258256
def get_downloads(self, pretty=False):
259257
project = self.project
260258
data = {}
261-
if pretty:
262-
if project.has_pdf(self.slug):
263-
data['PDF'] = project.get_production_media_url('pdf', self.slug)
264-
if project.has_htmlzip(self.slug):
265-
data['HTML'] = project.get_production_media_url(
266-
'htmlzip',
267-
self.slug,
268-
)
269-
if project.has_epub(self.slug):
270-
data['Epub'] = project.get_production_media_url(
271-
'epub',
272-
self.slug,
273-
)
274-
else:
275-
if project.has_pdf(self.slug):
276-
data['pdf'] = project.get_production_media_url('pdf', self.slug)
277-
if project.has_htmlzip(self.slug):
278-
data['htmlzip'] = project.get_production_media_url(
279-
'htmlzip',
280-
self.slug,
281-
)
282-
if project.has_epub(self.slug):
283-
data['epub'] = project.get_production_media_url(
284-
'epub',
285-
self.slug,
286-
)
259+
260+
def prettify(k):
261+
return k if pretty else k.lower()
262+
263+
if project.has_pdf(self.slug):
264+
data[prettify('PDF')] = project.get_production_media_url(
265+
'pdf',
266+
self.slug,
267+
)
268+
if project.has_htmlzip(self.slug):
269+
data[prettify('HTML')] = project.get_production_media_url(
270+
'htmlzip',
271+
self.slug,
272+
)
273+
if project.has_epub(self.slug):
274+
data[prettify('Epub')] = project.get_production_media_url(
275+
'epub',
276+
self.slug,
277+
)
287278
return data
288279

289280
def get_conf_py_path(self):

readthedocs/projects/models.py

-4
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,6 @@ def has_aliases(self):
744744
return self.aliases.exists()
745745

746746
def has_pdf(self, version_slug=LATEST):
747-
if not self.enable_pdf_build:
748-
return False
749747
path = self.get_production_media_path(
750748
type_='pdf', version_slug=version_slug
751749
)
@@ -755,8 +753,6 @@ def has_pdf(self, version_slug=LATEST):
755753
return os.path.exists(path) or storage.exists(storage_path)
756754

757755
def has_epub(self, version_slug=LATEST):
758-
if not self.enable_epub_build:
759-
return False
760756
path = self.get_production_media_path(
761757
type_='epub', version_slug=version_slug
762758
)

readthedocs/rtd_tests/tests/test_footer.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ def test_pdf_build_mentioned_in_footer(self):
6060
response = self.render()
6161
self.assertIn('pdf', response.data['html'])
6262

63-
def test_pdf_not_mentioned_in_footer_when_build_is_disabled(self):
64-
self.pip.enable_pdf_build = False
65-
self.pip.save()
66-
with fake_paths_by_regex(r'\.pdf$'):
63+
def test_pdf_not_mentioned_in_footer_when_doesnt_exists(self):
64+
with fake_paths_by_regex(r'\.pdf$', exists=False):
6765
response = self.render()
6866
self.assertNotIn('pdf', response.data['html'])
6967

@@ -72,10 +70,8 @@ def test_epub_build_mentioned_in_footer(self):
7270
response = self.render()
7371
self.assertIn('epub', response.data['html'])
7472

75-
def test_epub_not_mentioned_in_footer_when_build_is_disabled(self):
76-
self.pip.enable_epub_build = False
77-
self.pip.save()
78-
with fake_paths_by_regex(r'\.epub$'):
73+
def test_epub_not_mentioned_in_footer_when_doesnt_exists(self):
74+
with fake_paths_by_regex(r'\.epub$', exists=False):
7975
response = self.render()
8076
self.assertNotIn('epub', response.data['html'])
8177

readthedocs/rtd_tests/tests/test_project.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ def test_has_pdf(self):
5555
self.assertFalse(self.pip.has_pdf(LATEST))
5656

5757
def test_has_pdf_with_pdf_build_disabled(self):
58-
# The project has NO pdf if pdf builds are disabled
58+
# The project doesn't depend on `enable_pdf_build`
5959
self.pip.enable_pdf_build = False
6060
with fake_paths_by_regex(r'\.pdf$'):
61-
self.assertFalse(self.pip.has_pdf(LATEST))
61+
self.assertTrue(self.pip.has_pdf(LATEST))
6262

6363
def test_has_epub(self):
6464
# The project has a epub if the PDF file exists on disk.
@@ -70,10 +70,10 @@ def test_has_epub(self):
7070
self.assertFalse(self.pip.has_epub(LATEST))
7171

7272
def test_has_epub_with_epub_build_disabled(self):
73-
# The project has NO epub if epub builds are disabled
73+
# The project doesn't depend on `enable_epub_build`
7474
self.pip.enable_epub_build = False
7575
with fake_paths_by_regex(r'\.epub$'):
76-
self.assertFalse(self.pip.has_epub(LATEST))
76+
self.assertTrue(self.pip.has_epub(LATEST))
7777

7878
@patch('readthedocs.projects.models.Project.find')
7979
def test_conf_file_found(self, find_method):

readthedocs/templates/core/project_downloads.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% load i18n %}
22

33
{% for version, dict in version_data.items %}
4-
{% if dict.pdf and version.project.enable_pdf_build %}
4+
{% if dict.pdf %}
55
<li class="module-item col-span">
66
<a class="module-item-title" href="{{ dict.pdf }}">
77
{{ version.slug }} PDF
@@ -17,7 +17,7 @@
1717
</li>
1818
{% endif %}
1919

20-
{% if dict.epub and version.project.enable_epub_build %}
20+
{% if dict.epub %}
2121
<li class="module-item col-span">
2222
<a class="module-item-title" href="{{ dict.epub }}">
2323
{{ version.slug }} Epub

0 commit comments

Comments
 (0)