def add_sms_status_info(self, result): if len(self.domain_object.restricted_sms_times) > 0: result['uses_restricted_time_windows'] = True result['within_allowed_sms_times'] = time_within_windows( self.domain_now, self.domain_object.restricted_sms_times) if not result['within_allowed_sms_times']: for i in range(1, 7 * 24 * 60): # This is a very fast check so it's ok to iterate this many times. resume_time = self.domain_now + timedelta(minutes=i) if time_within_windows( resume_time, self.domain_object.restricted_sms_times): result['sms_resume_time'] = resume_time.strftime( '%Y-%m-%d %H:%M') break else: result['uses_restricted_time_windows'] = False result['within_allowed_sms_times'] = True result.update({ 'queued_sms_count': QueuedSMS.objects.filter(domain=self.domain).count(), 'outbound_sms_sent_today': OutboundDailyCounter(self.domain_object).current_usage, 'daily_outbound_sms_limit': self.domain_object.get_daily_outbound_sms_limit(), })
def add_sms_status_info(self, result): if len(self.domain_object.restricted_sms_times) > 0: result['uses_restricted_time_windows'] = True sms_allowed = result['within_allowed_sms_times'] = time_within_windows( self.domain_now, self.domain_object.restricted_sms_times ) # find next restricted window transition for i in range(1, 7 * 24 * 60): # This is a very fast check so it's ok to iterate this many times. future_time = self.domain_now + timedelta(minutes=i) future_allowed = time_within_windows(future_time, self.domain_object.restricted_sms_times) if sms_allowed != future_allowed: result['sms_resume_time'] = future_time.strftime('%Y-%m-%d %H:%M') break else: result['uses_restricted_time_windows'] = False result['within_allowed_sms_times'] = True result.update({ 'queued_sms_count': QueuedSMS.objects.filter(domain=self.domain).count(), 'outbound_sms_sent_today': OutboundDailyCounter(self.domain_object).current_usage, 'daily_outbound_sms_limit': self.domain_object.get_daily_outbound_sms_limit(), })