@@ -51,14 +51,11 @@ def subscription_trial_plan_ended(self):
51
51
stripe_subscription__items__price__id = settings .RTD_ORG_DEFAULT_STRIPE_SUBSCRIPTION_PRICE ,
52
52
)
53
53
54
- def disable_soon (self , days , exact = False ):
54
+ def subscription_ended (self , days , exact = False ):
55
55
"""
56
- Filter organizations that will eventually be marked as disabled .
56
+ Filter organizations which their subscription has ended .
57
57
58
- This will return organizations that the paid/trial subscription has
59
- ended ``days`` ago.
60
-
61
- Organizations to be disabled are which their subscription has been canceled,
58
+ This will return organizations which their subscription has been canceled,
62
59
or hasn't been paid for ``days``.
63
60
64
61
:param days: Days after the subscription has ended
@@ -102,16 +99,27 @@ def disable_soon(self, days, exact=False):
102
99
)
103
100
)
104
101
105
- orgs = (
106
- subscription_ended
102
+ return subscription_ended .distinct ()
103
+
104
+ def disable_soon (self , days , exact = False ):
105
+ """
106
+ Filter organizations that will eventually be marked as disabled.
107
+
108
+ These are organizations which their subscription has ended,
109
+ excluding organizations that can't be disabled, or are already disabled.
110
+
111
+ :param days: Days after the subscription has ended
112
+ :param exact: Make the ``days`` date to match exactly that day after the
113
+ subscription has ended (useful to send emails only once)
114
+ """
115
+ return (
116
+ self .subscription_ended (days = days , exact = exact )
107
117
# Exclude organizations that can't be disabled.
108
118
.exclude (never_disable = True )
109
119
# Exclude organizations that are already disabled
110
120
.exclude (disabled = True )
111
121
)
112
122
113
- return orgs .distinct ()
114
-
115
123
def clean_artifacts (self ):
116
124
"""
117
125
Filter organizations which their artifacts can be cleaned up.
@@ -120,13 +128,11 @@ def clean_artifacts(self):
120
128
are disabled and their artifacts weren't cleaned already. We should be
121
129
safe to cleanup all their artifacts at this point.
122
130
"""
123
- end_date = timezone .now ().date () - timedelta (days = 3 * DISABLE_AFTER_DAYS )
124
- orgs = self .filter (
131
+ return self .subscription_ended (days = 3 * DISABLE_AFTER_DAYS , exact = True ).filter (
125
132
disabled = True ,
126
- subscription__end_date__lt = end_date ,
127
133
artifacts_cleaned = False ,
128
134
)
129
- return orgs . distinct ()
135
+
130
136
131
137
def single_owner (self , user ):
132
138
"""Returns organizations where `user` is the only owner."""
0 commit comments