Skip to content

Extra features: allow to display them conditionally #7715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions readthedocs/projects/views/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand All @@ -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(
Expand Down Expand Up @@ -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']
Expand All @@ -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
13 changes: 10 additions & 3 deletions readthedocs/templates/projects/project_traffic_analytics.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@
{% block project_edit_content_header %}{% trans "Traffic Analytics" %}{% endblock %}

{% block project_edit_content %}

{% if not enabled %}
{% block disabled %}
<p class="empty">
This beta feature can be enabled by <a href="mailto:{{ SUPPORT_EMAIL }}">asking support</a>.
</p>
{% endblock %}
{% endif %}

<h3>{% trans "Top viewed pages of the past month" %}</h3>
<p>
This beta feature can be enabled by <a href="mailto:{{ SUPPORT_EMAIL }}">asking support</a>.
</p>

<div class="module-list">
<div class="module-list-wrapper">
<ul class="long-list-overflow">
Expand Down
5 changes: 5 additions & 0 deletions readthedocs/templates/projects/projects_search_analytics.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

{% block project_edit_content %}

{% if not enabled %}
{% block disabled %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably put the same This beta feature can be enabled by <a href="mailto:{{ SUPPORT_EMAIL }}">asking support</a>. block here for when its disabled, even if that isn't normally happening. I wonder if this should be in a base template, instead of one-off for each feature.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved it to an include 👍

{% endblock %}
{% endif %}

<h3>{% trans "Top queries" %}</h3>
<div class="module-list">
<div class="module-list-wrapper">
Expand Down