Skip to content

Commit 9c32099

Browse files
committed
Extra features: allow to display conditionally
We need this for .com mainly.
1 parent 02a81dd commit 9c32099

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

readthedocs/projects/views/private.py

+24-6
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@
3939
Version,
4040
VersionAutomationRule,
4141
)
42-
from readthedocs.core.mixins import (
43-
ListViewWithForm,
44-
PrivateViewMixin,
45-
)
42+
from readthedocs.core.mixins import ListViewWithForm, PrivateViewMixin
4643
from readthedocs.core.utils import broadcast, trigger_build
4744
from readthedocs.core.utils.extend import SettingsOverrideObject
4845
from readthedocs.integrations.models import HttpExchange, Integration
@@ -976,7 +973,7 @@ class RegexAutomationRuleUpdate(RegexAutomationRuleMixin, UpdateView):
976973
pass
977974

978975

979-
class SearchAnalytics(ProjectAdminMixin, PrivateViewMixin, TemplateView):
976+
class SearchAnalyticsBase(ProjectAdminMixin, PrivateViewMixin, TemplateView):
980977

981978
template_name = 'projects/projects_search_analytics.html'
982979
http_method_names = ['get']
@@ -990,6 +987,10 @@ def get(self, request, *args, **kwargs):
990987
def get_context_data(self, **kwargs):
991988
context = super().get_context_data(**kwargs)
992989
project = self.get_project()
990+
enabled = self._is_enabled(project)
991+
context.update({'enabled': enabled})
992+
if not enabled:
993+
return context
993994

994995
# data for plotting the line-chart
995996
query_count_of_1_month = SearchQuery.generate_queries_count_of_one_month(
@@ -1054,8 +1055,16 @@ def _search_analytics_csv_data(self):
10541055
response['Content-Disposition'] = f'attachment; filename="{file_name}"'
10551056
return response
10561057

1058+
def _is_enabled(self, project):
1059+
"""Should we show search analytics for this project?"""
1060+
return True
1061+
1062+
1063+
class SearchAnalytics(SettingsOverrideObject):
1064+
_default_class = SearchAnalyticsBase
1065+
10571066

1058-
class TrafficAnalyticsView(ProjectAdminMixin, PrivateViewMixin, TemplateView):
1067+
class TrafficAnalyticsViewBase(ProjectAdminMixin, PrivateViewMixin, TemplateView):
10591068

10601069
template_name = 'projects/project_traffic_analytics.html'
10611070
http_method_names = ['get']
@@ -1079,6 +1088,15 @@ def get_context_data(self, **kwargs):
10791088
context.update({
10801089
'top_viewed_pages': top_viewed_pages,
10811090
'page_data': page_data,
1091+
'enabled': self._is_enabled(project),
10821092
})
10831093

10841094
return context
1095+
1096+
def _is_enabled(self, project):
1097+
"""Should we show traffic analytics for this project?"""
1098+
return project.has_feature(Feature.STORE_PAGEVIEWS)
1099+
1100+
1101+
class TrafficAnalyticsView(SettingsOverrideObject):
1102+
_default_class = TrafficAnalyticsViewBase

readthedocs/templates/projects/project_traffic_analytics.html

+10-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@
1111
{% block project_edit_content_header %}{% trans "Traffic Analytics" %}{% endblock %}
1212

1313
{% block project_edit_content %}
14+
15+
{% if not enabled %}
16+
{% block disabled %}
17+
<p class="empty">
18+
This beta feature can be enabled by <a href="mailto:{{ SUPPORT_EMAIL }}">asking support</a>.
19+
</p>
20+
{% endblock %}
21+
{% endif %}
22+
1423
<h3>{% trans "Top viewed pages of the past month" %}</h3>
15-
<p>
16-
This beta feature can be enabled by <a href="mailto:{{ SUPPORT_EMAIL }}">asking support</a>.
17-
</p>
24+
1825
<div class="module-list">
1926
<div class="module-list-wrapper">
2027
<ul class="long-list-overflow">

readthedocs/templates/projects/projects_search_analytics.html

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
{% block project_edit_content %}
1414

15+
{% if not enabled %}
16+
{% block disabled %}
17+
{% endblock %}
18+
{% endif %}
19+
1520
<h3>{% trans "Top queries" %}</h3>
1621
<div class="module-list">
1722
<div class="module-list-wrapper">

0 commit comments

Comments
 (0)