From 9c32099341e2f131478916030097e8b3b018c63d Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Mon, 30 Nov 2020 17:55:15 -0500 Subject: [PATCH 1/3] Extra features: allow to display conditionally We need this for .com mainly. --- readthedocs/projects/views/private.py | 30 +++++++++++++++---- .../projects/project_traffic_analytics.html | 13 ++++++-- .../projects/projects_search_analytics.html | 5 ++++ 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/readthedocs/projects/views/private.py b/readthedocs/projects/views/private.py index 7c99000c6bf..a6685e83602 100644 --- a/readthedocs/projects/views/private.py +++ b/readthedocs/projects/views/private.py @@ -39,10 +39,7 @@ Version, VersionAutomationRule, ) -from readthedocs.core.mixins import ( - ListViewWithForm, - PrivateViewMixin, -) +from readthedocs.core.mixins import ListViewWithForm, PrivateViewMixin from readthedocs.core.utils import broadcast, trigger_build from readthedocs.core.utils.extend import SettingsOverrideObject from readthedocs.integrations.models import HttpExchange, Integration @@ -976,7 +973,7 @@ class RegexAutomationRuleUpdate(RegexAutomationRuleMixin, UpdateView): pass -class SearchAnalytics(ProjectAdminMixin, PrivateViewMixin, TemplateView): +class SearchAnalyticsBase(ProjectAdminMixin, PrivateViewMixin, TemplateView): template_name = 'projects/projects_search_analytics.html' http_method_names = ['get'] @@ -990,6 +987,10 @@ def get(self, request, *args, **kwargs): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) project = self.get_project() + enabled = self._is_enabled(project) + context.update({'enabled': enabled}) + if not enabled: + return context # data for plotting the line-chart query_count_of_1_month = SearchQuery.generate_queries_count_of_one_month( @@ -1054,8 +1055,16 @@ def _search_analytics_csv_data(self): response['Content-Disposition'] = f'attachment; filename="{file_name}"' return response + def _is_enabled(self, project): + """Should we show search analytics for this project?""" + return True + + +class SearchAnalytics(SettingsOverrideObject): + _default_class = SearchAnalyticsBase + -class TrafficAnalyticsView(ProjectAdminMixin, PrivateViewMixin, TemplateView): +class TrafficAnalyticsViewBase(ProjectAdminMixin, PrivateViewMixin, TemplateView): template_name = 'projects/project_traffic_analytics.html' http_method_names = ['get'] @@ -1079,6 +1088,15 @@ def get_context_data(self, **kwargs): context.update({ 'top_viewed_pages': top_viewed_pages, 'page_data': page_data, + 'enabled': self._is_enabled(project), }) return context + + def _is_enabled(self, project): + """Should we show traffic analytics for this project?""" + return project.has_feature(Feature.STORE_PAGEVIEWS) + + +class TrafficAnalyticsView(SettingsOverrideObject): + _default_class = TrafficAnalyticsViewBase diff --git a/readthedocs/templates/projects/project_traffic_analytics.html b/readthedocs/templates/projects/project_traffic_analytics.html index bf4a89e1466..353ab71b722 100644 --- a/readthedocs/templates/projects/project_traffic_analytics.html +++ b/readthedocs/templates/projects/project_traffic_analytics.html @@ -11,10 +11,17 @@ {% block project_edit_content_header %}{% trans "Traffic Analytics" %}{% endblock %} {% block project_edit_content %} + + {% if not enabled %} + {% block disabled %} +

+ This beta feature can be enabled by asking support. +

+ {% endblock %} + {% endif %} +

{% trans "Top viewed pages of the past month" %}

-

- This beta feature can be enabled by asking support. -

+
    diff --git a/readthedocs/templates/projects/projects_search_analytics.html b/readthedocs/templates/projects/projects_search_analytics.html index b02635fd549..e1b0bbf84f1 100644 --- a/readthedocs/templates/projects/projects_search_analytics.html +++ b/readthedocs/templates/projects/projects_search_analytics.html @@ -12,6 +12,11 @@ {% block project_edit_content %} + {% if not enabled %} + {% block disabled %} + {% endblock %} + {% endif %} +

    {% trans "Top queries" %}

    From 2ef8c300b4f440a6b8095fa859a153e69edd366d Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Mon, 7 Dec 2020 13:31:03 -0500 Subject: [PATCH 2/3] Move to include --- readthedocs/templates/projects/includes/feature_disabled.html | 3 +++ readthedocs/templates/projects/project_traffic_analytics.html | 4 +--- readthedocs/templates/projects/projects_search_analytics.html | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 readthedocs/templates/projects/includes/feature_disabled.html diff --git a/readthedocs/templates/projects/includes/feature_disabled.html b/readthedocs/templates/projects/includes/feature_disabled.html new file mode 100644 index 00000000000..58f77958f19 --- /dev/null +++ b/readthedocs/templates/projects/includes/feature_disabled.html @@ -0,0 +1,3 @@ +

    + This is a beta feature, it can be enabled by asking support. +

    diff --git a/readthedocs/templates/projects/project_traffic_analytics.html b/readthedocs/templates/projects/project_traffic_analytics.html index 353ab71b722..a8ce102b291 100644 --- a/readthedocs/templates/projects/project_traffic_analytics.html +++ b/readthedocs/templates/projects/project_traffic_analytics.html @@ -14,9 +14,7 @@ {% if not enabled %} {% block disabled %} -

    - This beta feature can be enabled by asking support. -

    + {% include 'projects/includes/feature_disabled.html' %} {% endblock %} {% endif %} diff --git a/readthedocs/templates/projects/projects_search_analytics.html b/readthedocs/templates/projects/projects_search_analytics.html index e1b0bbf84f1..b125293e2ea 100644 --- a/readthedocs/templates/projects/projects_search_analytics.html +++ b/readthedocs/templates/projects/projects_search_analytics.html @@ -14,6 +14,7 @@ {% if not enabled %} {% block disabled %} + {% include 'projects/includes/feature_disabled.html' %} {% endblock %} {% endif %} From ad550b64c14ffbc59f0f05fe0eec31f6a23d99c6 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Mon, 7 Dec 2020 13:47:16 -0500 Subject: [PATCH 3/3] Pass project to include This is needed for .com to show the plan link --- readthedocs/templates/projects/projects_search_analytics.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readthedocs/templates/projects/projects_search_analytics.html b/readthedocs/templates/projects/projects_search_analytics.html index b125293e2ea..c0f608c44f5 100644 --- a/readthedocs/templates/projects/projects_search_analytics.html +++ b/readthedocs/templates/projects/projects_search_analytics.html @@ -14,7 +14,7 @@ {% if not enabled %} {% block disabled %} - {% include 'projects/includes/feature_disabled.html' %} + {% include 'projects/includes/feature_disabled.html' with project=project %} {% endblock %} {% endif %}