Skip to content

Commit bb3c353

Browse files
authored
Merge pull request #4387 from rtfd/davidfischer/ad-free-nag-fix
Do not access database from builds to check ad-free
2 parents a6fa012 + 38059ed commit bb3c353

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

readthedocs/doc_builder/backends/mkdocs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def generate_rtd_data(self, docs_dir, mkdocs_config):
172172
'docroot': docs_dir,
173173
'source_suffix': ".md",
174174
'api_host': getattr(settings, 'PUBLIC_API_URL', 'https://readthedocs.org'),
175-
'ad_free': self.project.ad_free or self.project.gold_owners.exists(),
175+
'ad_free': not self.project.show_advertising,
176176
'commit': self.version.project.vcs_repo(self.version.slug).commit,
177177
'global_analytics_code': getattr(settings, 'GLOBAL_ANALYTICS_CODE', 'UA-17997319-1'),
178178
'user_analytics_code': analytics_code,

readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ context = {
115115
'using_theme': (html_theme == "default"),
116116
'new_theme': (html_theme == "sphinx_rtd_theme"),
117117
'source_suffix': SUFFIX,
118-
'ad_free': {% if project.gold_owners.exists or project.ad_free %}True{% else %}False{% endif %},
118+
'ad_free': {% if project.show_advertising %}False{% else %}True{% endif %},
119119
'user_analytics_code': '{{ project.analytics_code|default_if_none:'' }}',
120120
'global_analytics_code': '{{ settings.GLOBAL_ANALYTICS_CODE }}',
121121
'commit': {% if project.repo_type == 'git' %}'{{ commit|slice:"8" }}'{% else %}'{{ commit }}'{% endif %},

readthedocs/projects/models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,18 @@ def get_feature_value(self, feature, positive, negative):
849849
"""
850850
return positive if self.has_feature(feature) else negative
851851

852+
@property
853+
def show_advertising(self):
854+
"""
855+
Whether this project is ad-free
856+
857+
:return: ``True`` if advertising should be shown and ``False`` otherwise
858+
"""
859+
if self.ad_free or self.gold_owners.exists():
860+
return False
861+
862+
return True
863+
852864

853865
class APIProject(Project):
854866

readthedocs/restapi/serializers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class ProjectAdminSerializer(ProjectSerializer):
4343
slug_field='feature_id',
4444
)
4545

46+
show_advertising = serializers.SerializerMethodField()
47+
48+
def get_show_advertising(self, obj):
49+
return obj.show_advertising
50+
4651
class Meta(ProjectSerializer.Meta):
4752
fields = ProjectSerializer.Meta.fields + (
4853
'enable_epub_build',
@@ -62,7 +67,7 @@ class Meta(ProjectSerializer.Meta):
6267
'features',
6368
'has_valid_clone',
6469
'has_valid_webhook',
65-
'ad_free',
70+
'show_advertising',
6671
)
6772

6873

readthedocs/rtd_tests/tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,6 @@ def test_get_version_by_id(self):
906906
'id': 18,
907907
'active': True,
908908
'project': {
909-
'ad_free': False,
910909
'analytics_code': None,
911910
'canonical_url': 'http://readthedocs.org/docs/pip/en/latest/',
912911
'cdn_enabled': False,
@@ -932,6 +931,7 @@ def test_get_version_by_id(self):
932931
'repo': 'https://github.com/pypa/pip',
933932
'repo_type': 'git',
934933
'requirements_file': None,
934+
'show_advertising': True,
935935
'skip': False,
936936
'slug': 'pip',
937937
'suffix': '.rst',

0 commit comments

Comments
 (0)