Skip to content

Fixed ticket_6217 #6245

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 0 additions & 2 deletions docs/guides/feature-flags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,3 @@ e.g. python-reno release notes manager is known to do that
``USE_TESTING_BUILD_IMAGE``: :featureflags:`USE_TESTING_BUILD_IMAGE`

``EXTERNAL_VERSION_BUILD``: :featureflags:`EXTERNAL_VERSION_BUILD`

``SEARCH_ANALYTICS``: :featureflags:`SEARCH_ANALYTICS`
6 changes: 0 additions & 6 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1443,8 +1443,6 @@ def add_features(sender, **kwargs):
EXTERNAL_VERSION_BUILD = 'external_version_build'
UPDATE_CONDA_STARTUP = 'update_conda_startup'
CONDA_APPEND_CORE_REQUIREMENTS = 'conda_append_core_requirements'
SEARCH_ANALYTICS = 'search_analytics'

FEATURES = (
(USE_SPHINX_LATEST, _('Use latest version of Sphinx')),
(ALLOW_DEPRECATED_WEBHOOKS, _('Allow deprecated webhook views')),
Expand Down Expand Up @@ -1495,10 +1493,6 @@ def add_features(sender, **kwargs):
CONDA_APPEND_CORE_REQUIREMENTS,
_('Append Read the Docs core requirements to environment.yml file'),
),
(
SEARCH_ANALYTICS,
_('Enable search analytics'),
)
)

projects = models.ManyToManyField(
Expand Down
6 changes: 0 additions & 6 deletions readthedocs/projects/urls/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
ProjectUsersDelete,
ProjectVersionDeleteHTML,
ProjectVersionDetail,
SearchAnalytics,
)

urlpatterns = [
Expand Down Expand Up @@ -129,11 +128,6 @@
r'^(?P<project_slug>[-\w]+)/advertising/$',
ProjectAdvertisingUpdate.as_view(), name='projects_advertising',
),
url(
r'^(?P<project_slug>[-\w]+)/search-analytics/$',
SearchAnalytics.as_view(),
name='projects_search_analytics',
Copy link
Member

Choose a reason for hiding this comment

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

Only the flag should be removed, not the functionality

),
]

domain_urls = [
Expand Down
83 changes: 0 additions & 83 deletions readthedocs/projects/views/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,86 +930,3 @@ class EnvironmentVariableDelete(EnvironmentVariableMixin, DeleteView):
http_method_names = ['post']


class SearchAnalytics(ProjectAdminMixin, PrivateViewMixin, TemplateView):

template_name = 'projects/projects_search_analytics.html'
http_method_names = ['get']

def get(self, request, *args, **kwargs):
download_data = request.GET.get('download', False)
if download_data:
return self._search_analytics_csv_data()
return super().get(request, *args, **kwargs)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
project = self.get_project()

context['show_analytics'] = project.has_feature(
Feature.SEARCH_ANALYTICS,
)
if not context['show_analytics']:
return context

# data for plotting the line-chart
query_count_of_1_month = SearchQuery.generate_queries_count_of_one_month(
project.slug,
)

queries = []
qs = SearchQuery.objects.filter(project=project)
if qs.exists():
qs = (
qs.values('query')
.annotate(count=Count('id'))
.order_by('-count', 'query')
.values_list('query', 'count')
)

# only show top 100 queries
queries = qs[:100]

context.update(
{
'queries': queries,
'query_count_of_1_month': query_count_of_1_month,
},
)
return context

def _search_analytics_csv_data(self):
"""Generate raw csv data of search queries."""
project = self.get_project()
now = timezone.now().date()
last_3_month = now - timezone.timedelta(days=90)

data = (
SearchQuery.objects.filter(
project=project,
created__date__gte=last_3_month,
created__date__lte=now,
)
.order_by('-created')
.values_list('created', 'query')
)

file_name = '{project_slug}_from_{start}_to_{end}.csv'.format(
project_slug=project.slug,
start=timezone.datetime.strftime(last_3_month, '%Y-%m-%d'),
end=timezone.datetime.strftime(now, '%Y-%m-%d'),
)
# remove any spaces in filename.
file_name = '-'.join([text for text in file_name.split() if text])

csv_data = (
[timezone.datetime.strftime(time, '%Y-%m-%d %H:%M:%S'), query]
for time, query in data
)
pseudo_buffer = Echo()
writer = csv.writer(pseudo_buffer)
response = StreamingHttpResponse(
(writer.writerow(row) for row in csv_data),
content_type="text/csv",
)
response['Content-Disposition'] = f'attachment; filename="{file_name}"'
return response
3 changes: 1 addition & 2 deletions readthedocs/rtd_tests/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,11 @@ def setUp(self):
self.client.login(username='eric', password='test')
self.pip = Project.objects.get(slug='pip')
self.version = self.pip.versions.order_by('id').first()
self.analyics_page = reverse('projects_search_analytics', args=[self.pip.slug])

test_time = timezone.datetime(2019, 8, 2, 12, 0)
self.test_time = timezone.make_aware(test_time)

get(Feature, projects=[self.pip], feature_id=Feature.SEARCH_ANALYTICS)
get(Feature, projects=[self.pip])

def test_top_queries(self):
with mock.patch('django.utils.timezone.now') as test_time:
Expand Down
1 change: 0 additions & 1 deletion readthedocs/templates/projects/project_edit_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<li class="{% block project-integrations-active %}{% endblock %}"><a href="{% url "projects_integrations" project.slug %}">{% trans "Integrations" %}</a></li>
<li class="{% block project-environment-variables-active %}{% endblock %}"><a href="{% url "projects_environmentvariables" project.slug %}">{% trans "Environment Variables" %}</a></li>
<li class="{% block project-notifications-active %}{% endblock %}"><a href="{% url "projects_notifications" project.slug %}">{% trans "Notifications" %}</a></li>
<li class="{% block project-search-analytics-active %}{% endblock %}"><a href="{% url "projects_search_analytics" project.slug %}">{% trans "Search Analytics" %}</a></li>
{% if USE_PROMOS %}
<li class="{% block project-ads-active %}{% endblock %}"><a href="{% url "projects_advertising" project.slug %}">{% trans "Advertising" %} </a></li>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ <h2>{% trans "Overview of the past 1 month:" %}</h2>
{% blocktrans trimmed %}
Hey there! This feature is currently in beta state and is available under a
<a href='https://docs.readthedocs.io/page/guides/feature-flags.html#available-flags'>feature flag</a>.
In case you want to test this feature and help giving us feedback,
please contact us via
<a href='https://github.com/readthedocs/readthedocs.org/issues/new?title=Request%20to%20enable%20SEARCH_ANALYTICS%20feature%20flag%20for%20project%20{{ project }}'>GitHub issues</a>.

{% endblocktrans %}
</p>
{% endif %}
Expand Down