本文整理匯總了Python中corehq.apps.sms.models.SMS.count_by_domain方法的典型用法代碼示例。如果您正苦於以下問題:Python SMS.count_by_domain方法的具體用法?Python SMS.count_by_domain怎麽用?Python SMS.count_by_domain使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類corehq.apps.sms.models.SMS
的用法示例。
在下文中一共展示了SMS.count_by_domain方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main_context
# 需要導入模塊: from corehq.apps.sms.models import SMS [as 別名]
# 或者: from corehq.apps.sms.models.SMS import count_by_domain [as 別名]
def main_context(self):
contacts = CommCareUser.by_domain(self.domain, reduce=True)
web_users = WebUser.by_domain(self.domain)
web_users_admins = web_users_read_only = 0
facilities = SQLLocation.objects.filter(domain=self.domain, location_type__name__iexact='FACILITY')
admin_role_list = UserRole.by_domain_and_name(self.domain, 'Administrator')
if admin_role_list:
admin_role = admin_role_list[0]
else:
admin_role = None
for web_user in web_users:
dm = web_user.get_domain_membership(self.domain)
if admin_role and dm.role_id == admin_role.get_id:
web_users_admins += 1
else:
web_users_read_only += 1
main_context = super(GlobalStats, self).main_context
entities_reported_stock = SQLLocation.objects.filter(
domain=self.domain,
location_type__administrative=False
).count()
context = {
'root_name': self.root_name,
'country': SQLLocation.objects.filter(domain=self.domain,
location_type__name__iexact=self.root_name).count(),
'region': SQLLocation.objects.filter(domain=self.domain, location_type__name__iexact='region').count(),
'district': SQLLocation.objects.filter(
domain=self.domain,
location_type__name__iexact='district'
).count(),
'entities_reported_stock': entities_reported_stock,
'facilities': len(facilities),
'contacts': contacts[0]['value'] if contacts else 0,
'web_users': len(web_users),
'web_users_admins': web_users_admins,
'web_users_read_only': web_users_read_only,
'products': SQLProduct.objects.filter(domain=self.domain, is_archived=False).count(),
'product_stocks': StockState.objects.filter(sql_product__domain=self.domain).count(),
'stock_transactions': StockTransaction.objects.filter(report__domain=self.domain).count(),
'inbound_messages': SMS.count_by_domain(self.domain, direction=INCOMING),
'outbound_messages': SMS.count_by_domain(self.domain, direction=OUTGOING),
}
if self.show_supply_point_types:
counts = SQLLocation.objects.values('location_type__name').filter(domain=self.domain).annotate(
Count('location_type')
).order_by('location_type__name')
context['location_types'] = counts
main_context.update(context)
return main_context