1
1
"""Project views for authenticated users."""
2
2
3
3
import structlog
4
-
5
4
from allauth .socialaccount .models import SocialAccount
6
5
from django .conf import settings
7
6
from django .contrib import messages
39
38
VersionAutomationRule ,
40
39
)
41
40
from readthedocs .core .history import UpdateChangeReasonPostView
42
- from readthedocs .core .mixins import ListViewWithForm , PrivateViewMixin
43
- from readthedocs .core .utils .extend import SettingsOverrideObject
41
+ from readthedocs .core .mixins import ListViewWithForm , PrivateViewMixin , FeaturedView
44
42
from readthedocs .integrations .models import HttpExchange , Integration
45
43
from readthedocs .oauth .services import registry
46
44
from readthedocs .oauth .tasks import attach_webhook
79
77
ProjectRelationListMixin ,
80
78
)
81
79
from readthedocs .search .models import SearchQuery
80
+ from readthedocs .subscriptions .models import PlanFeature
81
+
82
82
83
83
log = structlog .get_logger (__name__ )
84
84
@@ -743,10 +743,11 @@ def post(self, request, *args, **kwargs):
743
743
return HttpResponseRedirect (self .get_success_url ())
744
744
745
745
746
- class DomainMixin (ProjectAdminMixin , PrivateViewMixin ):
746
+ class DomainMixin (FeaturedView , ProjectAdminMixin , PrivateViewMixin ):
747
747
model = Domain
748
748
form_class = DomainForm
749
749
lookup_url_kwarg = 'domain_pk'
750
+ feature_type = PlanFeature .TYPE_CNAME
750
751
751
752
def get_success_url (self ):
752
753
return reverse ('projects_domains' , args = [self .get_project ().slug ])
@@ -757,12 +758,8 @@ def get_context_data(self, **kwargs):
757
758
context ['enabled' ] = self ._is_enabled (project )
758
759
return context
759
760
760
- def _is_enabled (self , project ):
761
- """Should we allow custom domains for this project?"""
762
- return True
763
-
764
761
765
- class DomainListBase (DomainMixin , ListViewWithForm ):
762
+ class DomainList (DomainMixin , ListViewWithForm ):
766
763
767
764
def get_context_data (self , ** kwargs ):
768
765
ctx = super ().get_context_data (** kwargs )
@@ -777,12 +774,7 @@ def get_context_data(self, **kwargs):
777
774
return ctx
778
775
779
776
780
- class DomainList (SettingsOverrideObject ):
781
-
782
- _default_class = DomainListBase
783
-
784
-
785
- class DomainCreateBase (DomainMixin , CreateView ):
777
+ class DomainCreate (DomainMixin , CreateView ):
786
778
787
779
def post (self , request , * args , ** kwargs ):
788
780
project = self .get_project ()
@@ -801,12 +793,7 @@ def get_success_url(self):
801
793
)
802
794
803
795
804
- class DomainCreate (SettingsOverrideObject ):
805
-
806
- _default_class = DomainCreateBase
807
-
808
-
809
- class DomainUpdateBase (DomainMixin , UpdateView ):
796
+ class DomainUpdate (DomainMixin , UpdateView ):
810
797
811
798
def post (self , request , * args , ** kwargs ):
812
799
project = self .get_project ()
@@ -815,11 +802,6 @@ def post(self, request, *args, **kwargs):
815
802
return HttpResponse ('Action not allowed' , status = 401 )
816
803
817
804
818
- class DomainUpdate (SettingsOverrideObject ):
819
-
820
- _default_class = DomainUpdateBase
821
-
822
-
823
805
class DomainDelete (DomainMixin , DeleteView ):
824
806
825
807
pass
@@ -1062,10 +1044,16 @@ class RegexAutomationRuleUpdate(RegexAutomationRuleMixin, UpdateView):
1062
1044
pass
1063
1045
1064
1046
1065
- class SearchAnalyticsBase (ProjectAdminMixin , PrivateViewMixin , TemplateView ):
1047
+ class SearchAnalytics (
1048
+ FeaturedView ,
1049
+ ProjectAdminMixin ,
1050
+ PrivateViewMixin ,
1051
+ TemplateView ,
1052
+ ):
1066
1053
1067
1054
template_name = 'projects/projects_search_analytics.html'
1068
1055
http_method_names = ['get' ]
1056
+ feature_type = PlanFeature .TYPE_SEARCH_ANALYTICS
1069
1057
1070
1058
def get (self , request , * args , ** kwargs ):
1071
1059
download_data = request .GET .get ('download' , False )
@@ -1149,21 +1137,22 @@ def _get_csv_data(self):
1149
1137
1150
1138
def _get_retention_days_limit (self , project ):
1151
1139
"""From how many days we need to show data for this project?"""
1152
- return settings .RTD_ANALYTICS_DEFAULT_RETENTION_DAYS
1153
-
1154
- def _is_enabled (self , project ):
1155
- """Should we show search analytics for this project?"""
1156
- return True
1157
-
1158
-
1159
- class SearchAnalytics (SettingsOverrideObject ):
1160
- _default_class = SearchAnalyticsBase
1140
+ return self ._get_feature_value (
1141
+ project ,
1142
+ default = settings .RTD_ANALYTICS_DEFAULT_RETENTION_DAYS ,
1143
+ )
1161
1144
1162
1145
1163
- class TrafficAnalyticsViewBase (ProjectAdminMixin , PrivateViewMixin , TemplateView ):
1146
+ class TrafficAnalyticsView (
1147
+ FeaturedView ,
1148
+ ProjectAdminMixin ,
1149
+ PrivateViewMixin ,
1150
+ TemplateView ,
1151
+ ):
1164
1152
1165
1153
template_name = 'projects/project_traffic_analytics.html'
1166
1154
http_method_names = ['get' ]
1155
+ feature_type = PlanFeature .TYPE_PAGEVIEW_ANALYTICS
1167
1156
1168
1157
def get (self , request , * args , ** kwargs ):
1169
1158
download_data = request .GET .get ('download' , False )
@@ -1239,12 +1228,7 @@ def _get_csv_data(self):
1239
1228
1240
1229
def _get_retention_days_limit (self , project ):
1241
1230
"""From how many days we need to show data for this project?"""
1242
- return settings .RTD_ANALYTICS_DEFAULT_RETENTION_DAYS
1243
-
1244
- def _is_enabled (self , project ):
1245
- """Should we show traffic analytics for this project?"""
1246
- return True
1247
-
1248
-
1249
- class TrafficAnalyticsView (SettingsOverrideObject ):
1250
- _default_class = TrafficAnalyticsViewBase
1231
+ return self ._get_feature_value (
1232
+ project ,
1233
+ default = settings .RTD_ANALYTICS_DEFAULT_RETENTION_DAYS ,
1234
+ )
0 commit comments