本文整理匯總了Python中corehq.apps.sms.models.SMS.by_domain方法的典型用法代碼示例。如果您正苦於以下問題:Python SMS.by_domain方法的具體用法?Python SMS.by_domain怎麽用?Python SMS.by_domain使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類corehq.apps.sms.models.SMS
的用法示例。
在下文中一共展示了SMS.by_domain方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setUp
# 需要導入模塊: from corehq.apps.sms.models import SMS [as 別名]
# 或者: from corehq.apps.sms.models.SMS import by_domain [as 別名]
def setUp(self):
self.domain = Domain(name='mockdomain')
self.domain.save()
SMS.by_domain(self.domain.name).delete()
self.user = 'username-unicel'
self.password = 'password'
self.number = 5555551234
self.couch_user = WebUser.create(self.domain.name, self.user, self.password)
self.couch_user.add_phone_number(self.number)
self.couch_user.save()
self.message_ascii = 'It Works'
self.message_utf_hex = '0939093F0928094D092609400020091509300924093E00200939094800200907093800200938092E092F00200915093E092E002009390948003F'
示例2: tearDown
# 需要導入模塊: from corehq.apps.sms.models import SMS [as 別名]
# 或者: from corehq.apps.sms.models.SMS import by_domain [as 別名]
def tearDown(self):
SmsBillable.objects.all().delete()
SmsGatewayFee.objects.all().delete()
SmsGatewayFeeCriteria.objects.all().delete()
SmsUsageFee.objects.all().delete()
SmsUsageFeeCriteria.objects.all().delete()
self.currency_usd.delete()
self.other_currency.delete()
SMS.by_domain(generator.TEST_DOMAIN).delete()
for api_id, backend_id in self.backend_ids.iteritems():
SQLMobileBackend.load(backend_id, is_couch_id=True).delete()
示例3: handle
# 需要導入模塊: from corehq.apps.sms.models import SMS [as 別名]
# 或者: from corehq.apps.sms.models.SMS import by_domain [as 別名]
def handle(self, domains, **options):
for domain in domains:
print("*** Processing Domain %s ***" % domain)
user_cache = {}
for msg in SMS.by_domain(domain):
if msg.couch_recipient:
if msg.couch_recipient_doc_type != "CommCareCase":
user = None
if msg.couch_recipient in user_cache:
user = user_cache[msg.couch_recipient]
else:
try:
user = CouchUser.get_by_user_id(msg.couch_recipient)
except Exception:
user = None
if user is None:
print("Could not find user %s" % msg.couch_recipient)
user_cache[msg.couch_recipient] = user
if user and msg.couch_recipient_doc_type != user.doc_type:
msg.couch_recipient_doc_type = user.doc_type
msg.save()
else:
if msg.couch_recipient_doc_type is not None or msg.couch_recipient is not None:
msg.couch_recipient = None
msg.couch_recipient_doc_type = None
msg.save()
示例4: handle
# 需要導入模塊: from corehq.apps.sms.models import SMS [as 別名]
# 或者: from corehq.apps.sms.models.SMS import by_domain [as 別名]
def handle(self, *args, **options):
if len(args) == 0:
raise CommandError("Usage: python manage.py fix_smslog_recipient_doc_type <domain1 domain2 ...>")
for domain in args:
print "*** Processing Domain %s ***" % domain
user_cache = {}
for msg in SMS.by_domain(domain):
if msg.couch_recipient:
if msg.couch_recipient_doc_type != "CommCareCase":
user = None
if msg.couch_recipient in user_cache:
user = user_cache[msg.couch_recipient]
else:
try:
user = CouchUser.get_by_user_id(msg.couch_recipient)
except Exception:
user = None
if user is None:
print "Could not find user %s" % msg.couch_recipient
user_cache[msg.couch_recipient] = user
if user and msg.couch_recipient_doc_type != user.doc_type:
msg.couch_recipient_doc_type = user.doc_type
msg.save()
else:
if msg.couch_recipient_doc_type is not None or msg.couch_recipient is not None:
msg.couch_recipient = None
msg.couch_recipient_doc_type = None
msg.save()
示例5: tearDown
# 需要導入模塊: from corehq.apps.sms.models import SMS [as 別名]
# 或者: from corehq.apps.sms.models.SMS import by_domain [as 別名]
def tearDown(self):
SmsBillable.objects.all().delete()
SmsGatewayFee.objects.all().delete()
SmsGatewayFeeCriteria.objects.all().delete()
SmsUsageFee.objects.all().delete()
SmsUsageFeeCriteria.objects.all().delete()
self.currency_usd.delete()
self.other_currency.delete()
SMS.by_domain(generator.TEST_DOMAIN).delete()
for api_id, backend_id in self.backend_ids.iteritems():
SQLMobileBackend.load(backend_id, is_couch_id=True).delete()
FakeTwilioMessageFactory.backend_message_id_to_price = {}
super(TestGatewayFee, self).tearDown()
示例6: rows
# 需要導入模塊: from corehq.apps.sms.models import SMS [as 別名]
# 或者: from corehq.apps.sms.models.SMS import by_domain [as 別名]
def rows(self):
data = SMS.by_domain(
self.domain,
start_date=self.datespan.startdate_utc,
end_date=self.datespan.enddate_utc
).exclude(
direction=OUTGOING,
processed=False
).order_by('date')
if self.show_only_survey_traffic():
data = data.filter(
xforms_session_couch_id__isnull=False
)
result = []
direction_map = {
INCOMING: _("Incoming"),
OUTGOING: _("Outgoing"),
}
message_bank_messages = get_message_bank(self.domain, for_comparing=True)
FormProcessorInterface(self.domain).casedb_cache(
domain=self.domain, strip_history=False, deleted_ok=True
)
user_cache = UserCache()
for message in data:
# Add metadata from the message bank if it has not been added already
if (message.direction == OUTGOING) and (not message.fri_message_bank_lookup_completed):
add_metadata(message, message_bank_messages)
if message.couch_recipient_doc_type == "CommCareCase":
recipient = case_cache.get(message.couch_recipient)
else:
recipient = user_cache.get(message.couch_recipient)
if message.chat_user_id:
sender = user_cache.get(message.chat_user_id)
else:
sender = None
study_arm = None
if message.couch_recipient_doc_type == "CommCareCase":
study_arm = case_cache.get(message.couch_recipient).get_case_property("study_arm")
timestamp = ServerTime(message.date).user_time(self.timezone).done()
result.append([
self._fmt(self._participant_id(recipient)),
self._fmt(study_arm or "-"),
self._fmt(self._originator(message, recipient, sender)),
self._fmt_timestamp(timestamp),
self._fmt(message.text),
self._fmt(message.fri_id or "-"),
self._fmt(direction_map.get(message.direction,"-")),
])
return result
示例7: rows
# 需要導入模塊: from corehq.apps.sms.models import SMS [as 別名]
# 或者: from corehq.apps.sms.models.SMS import by_domain [as 別名]
def rows(self):
data = (SMS.by_domain(self.config['domain'])
.filter(location_id=self.config['location_id'])
.order_by('date'))
messages = []
for message in data:
timestamp = ServerTime(message.date).user_time(self.config['timezone']).done()
messages.append([
_fmt_timestamp(timestamp),
_fmt(message.direction),
_fmt(message.text),
])
return messages
示例8: rows
# 需要導入模塊: from corehq.apps.sms.models import SMS [as 別名]
# 或者: from corehq.apps.sms.models.SMS import by_domain [as 別名]
def rows(self):
data = (SMS.by_domain(self.config['domain'])
.filter(location_id=self.config['location_id'])
.exclude(processed=False, direction=OUTGOING)
.order_by('-date'))
messages = []
for message in data:
recipient = message.recipient
timestamp = ServerTime(message.date).user_time(self.config['timezone']).done()
messages.append([
_fmt_timestamp(timestamp),
recipient.full_name,
message.phone_number,
_fmt(message.direction),
_fmt(message.text),
])
return messages
示例9: handle
# 需要導入模塊: from corehq.apps.sms.models import SMS [as 別名]
# 或者: from corehq.apps.sms.models.SMS import by_domain [as 別名]
def handle(self, start_datetime, end_datetime, **options):
num_sms = 0
for domain in Domain.get_all():
result = SMS.by_domain(
domain.name,
start_date=start_datetime,
end_date=end_datetime,
)
for sms_log in result:
if options.get('create', False):
SmsBillable.create(sms_log)
print('Created billable for SMS %s in domain %s from %s' \
% (sms_log.couch_id, domain.name, sms_log.date))
else:
print('Found SMS %s in domain %s from %s' \
% (sms_log.couch_id, domain.name, sms_log.date))
num_sms += 1
print('Number of SMSs in datetime range: %d' % num_sms)
示例10: rows
# 需要導入模塊: from corehq.apps.sms.models import SMS [as 別名]
# 或者: from corehq.apps.sms.models.SMS import by_domain [as 別名]
def rows(self):
data = SMS.by_domain(
self.domain,
start_date=self.datespan.startdate_utc,
end_date=self.datespan.enddate_utc
).filter(
workflow__iexact=WORKFLOW_DEFAULT
).exclude(
direction=OUTGOING,
processed=False,
).order_by('date')
result = []
direction_map = {
INCOMING: _("Incoming"),
OUTGOING: _("Outgoing"),
}
reporting_locations_id = self.get_location_filter()
contact_cache = {}
for message in data:
if reporting_locations_id and message.location_id not in reporting_locations_id:
continue
doc_info = self.get_recipient_info(message, contact_cache)
phone_number = message.phone_number
timestamp = ServerTime(message.date).user_time(self.timezone).done()
result.append([
self._fmt_timestamp(timestamp),
self._fmt_contact_link(message, doc_info),
_fmt(phone_number),
_fmt(direction_map.get(message.direction, "-")),
_fmt(message.text)
])
return result
示例11: handle
# 需要導入模塊: from corehq.apps.sms.models import SMS [as 別名]
# 或者: from corehq.apps.sms.models.SMS import by_domain [as 別名]
def handle(self, *args, **options):
num_sms = 0
start_datetime = datetime.datetime(*str_to_int_tuple(args[0:6]))
end_datetime = datetime.datetime(*str_to_int_tuple(args[6:12]))
for domain in Domain.get_all():
result = SMS.by_domain(
domain.name,
start_date=start_datetime,
end_date=end_datetime
)
for sms_log in result:
if options.get('create', False):
SmsBillable.create(sms_log)
print 'Created billable for SMS %s in domain %s from %s' \
% (sms_log.couch_id, domain.name, sms_log.date)
else:
print 'Found SMS %s in domain %s from %s' \
% (sms_log.couch_id, domain.name, sms_log.date)
num_sms += 1
print 'Number of SMSs in datetime range: %d' % num_sms
示例12: setUp
# 需要導入模塊: from corehq.apps.sms.models import SMS [as 別名]
# 或者: from corehq.apps.sms.models.SMS import by_domain [as 別名]
def setUp(self):
SMS.by_domain(self.domain.name).delete()