本文整理汇总了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