File tree 5 files changed +29
-46
lines changed
5 files changed +29
-46
lines changed Original file line number Diff line number Diff line change 1
- # -*- coding: utf-8 -*-
2
-
3
1
"""Models for the builds app."""
4
2
5
3
import datetime
@@ -258,32 +256,25 @@ def get_subdomain_url(self):
258
256
def get_downloads (self , pretty = False ):
259
257
project = self .project
260
258
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
+ )
287
278
return data
288
279
289
280
def get_conf_py_path (self ):
Original file line number Diff line number Diff line change @@ -744,8 +744,6 @@ def has_aliases(self):
744
744
return self .aliases .exists ()
745
745
746
746
def has_pdf (self , version_slug = LATEST ):
747
- if not self .enable_pdf_build :
748
- return False
749
747
path = self .get_production_media_path (
750
748
type_ = 'pdf' , version_slug = version_slug
751
749
)
@@ -755,8 +753,6 @@ def has_pdf(self, version_slug=LATEST):
755
753
return os .path .exists (path ) or storage .exists (storage_path )
756
754
757
755
def has_epub (self , version_slug = LATEST ):
758
- if not self .enable_epub_build :
759
- return False
760
756
path = self .get_production_media_path (
761
757
type_ = 'epub' , version_slug = version_slug
762
758
)
Original file line number Diff line number Diff line change @@ -60,10 +60,8 @@ def test_pdf_build_mentioned_in_footer(self):
60
60
response = self .render ()
61
61
self .assertIn ('pdf' , response .data ['html' ])
62
62
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 ):
67
65
response = self .render ()
68
66
self .assertNotIn ('pdf' , response .data ['html' ])
69
67
@@ -72,10 +70,8 @@ def test_epub_build_mentioned_in_footer(self):
72
70
response = self .render ()
73
71
self .assertIn ('epub' , response .data ['html' ])
74
72
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 ):
79
75
response = self .render ()
80
76
self .assertNotIn ('epub' , response .data ['html' ])
81
77
Original file line number Diff line number Diff line change @@ -55,10 +55,10 @@ def test_has_pdf(self):
55
55
self .assertFalse (self .pip .has_pdf (LATEST ))
56
56
57
57
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`
59
59
self .pip .enable_pdf_build = False
60
60
with fake_paths_by_regex (r'\.pdf$' ):
61
- self .assertFalse (self .pip .has_pdf (LATEST ))
61
+ self .assertTrue (self .pip .has_pdf (LATEST ))
62
62
63
63
def test_has_epub (self ):
64
64
# The project has a epub if the PDF file exists on disk.
@@ -70,10 +70,10 @@ def test_has_epub(self):
70
70
self .assertFalse (self .pip .has_epub (LATEST ))
71
71
72
72
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`
74
74
self .pip .enable_epub_build = False
75
75
with fake_paths_by_regex (r'\.epub$' ):
76
- self .assertFalse (self .pip .has_epub (LATEST ))
76
+ self .assertTrue (self .pip .has_epub (LATEST ))
77
77
78
78
@patch ('readthedocs.projects.models.Project.find' )
79
79
def test_conf_file_found (self , find_method ):
Original file line number Diff line number Diff line change 1
1
{% load i18n %}
2
2
3
3
{% for version, dict in version_data.items %}
4
- {% if dict.pdf and version.project.enable_pdf_build %}
4
+ {% if dict.pdf %}
5
5
< li class ="module-item col-span ">
6
6
< a class ="module-item-title " href ="{{ dict.pdf }} ">
7
7
{{ version.slug }} PDF
17
17
</ li >
18
18
{% endif %}
19
19
20
- {% if dict.epub and version.project.enable_epub_build %}
20
+ {% if dict.epub %}
21
21
< li class ="module-item col-span ">
22
22
< a class ="module-item-title " href ="{{ dict.epub }} ">
23
23
{{ version.slug }} Epub
You can’t perform that action at this time.
0 commit comments