Skip to content

Commit 2b9d0fb

Browse files
authored
Extra features: allow to display them conditionally (#7715)
1 parent 74e2ca7 commit 2b9d0fb

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<p class="empty">
2+
This is a beta feature, it can be enabled by <a href="mailto:{{ SUPPORT_EMAIL }}">asking support</a>.
3+
</p>

readthedocs/templates/projects/project_traffic_analytics.html

+8-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@
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+
{% include 'projects/includes/feature_disabled.html' %}
18+
{% endblock %}
19+
{% endif %}
20+
1421
<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>
22+
1823
<div class="module-list">
1924
<div class="module-list-wrapper">
2025
<ul class="long-list-overflow">

readthedocs/templates/projects/projects_search_analytics.html

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

1313
{% block project_edit_content %}
1414

15+
{% if not enabled %}
16+
{% block disabled %}
17+
{% include 'projects/includes/feature_disabled.html' with project=project %}
18+
{% endblock %}
19+
{% endif %}
20+
1521
<h3>{% trans "Top queries" %}</h3>
1622
<div class="module-list">
1723
<div class="module-list-wrapper">

0 commit comments

Comments
 (0)