39
39
Version ,
40
40
VersionAutomationRule ,
41
41
)
42
- from readthedocs .core .mixins import (
43
- ListViewWithForm ,
44
- PrivateViewMixin ,
45
- )
42
+ from readthedocs .core .mixins import ListViewWithForm , PrivateViewMixin
46
43
from readthedocs .core .utils import broadcast , trigger_build
47
44
from readthedocs .core .utils .extend import SettingsOverrideObject
48
45
from readthedocs .integrations .models import HttpExchange , Integration
@@ -976,7 +973,7 @@ class RegexAutomationRuleUpdate(RegexAutomationRuleMixin, UpdateView):
976
973
pass
977
974
978
975
979
- class SearchAnalytics (ProjectAdminMixin , PrivateViewMixin , TemplateView ):
976
+ class SearchAnalyticsBase (ProjectAdminMixin , PrivateViewMixin , TemplateView ):
980
977
981
978
template_name = 'projects/projects_search_analytics.html'
982
979
http_method_names = ['get' ]
@@ -990,6 +987,10 @@ def get(self, request, *args, **kwargs):
990
987
def get_context_data (self , ** kwargs ):
991
988
context = super ().get_context_data (** kwargs )
992
989
project = self .get_project ()
990
+ enabled = self ._is_enabled (project )
991
+ context .update ({'enabled' : enabled })
992
+ if not enabled :
993
+ return context
993
994
994
995
# data for plotting the line-chart
995
996
query_count_of_1_month = SearchQuery .generate_queries_count_of_one_month (
@@ -1054,8 +1055,16 @@ def _search_analytics_csv_data(self):
1054
1055
response ['Content-Disposition' ] = f'attachment; filename="{ file_name } "'
1055
1056
return response
1056
1057
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
+
1057
1066
1058
- class TrafficAnalyticsView (ProjectAdminMixin , PrivateViewMixin , TemplateView ):
1067
+ class TrafficAnalyticsViewBase (ProjectAdminMixin , PrivateViewMixin , TemplateView ):
1059
1068
1060
1069
template_name = 'projects/project_traffic_analytics.html'
1061
1070
http_method_names = ['get' ]
@@ -1079,6 +1088,15 @@ def get_context_data(self, **kwargs):
1079
1088
context .update ({
1080
1089
'top_viewed_pages' : top_viewed_pages ,
1081
1090
'page_data' : page_data ,
1091
+ 'enabled' : self ._is_enabled (project ),
1082
1092
})
1083
1093
1084
1094
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
0 commit comments