def message_log_report(request): show_dates = True datespan = request.datespan domains = Domain.get_all() for dom in domains: dom.sms_incoming = SMSLog.count_incoming_by_domain(dom.name, datespan.startdate_param, datespan.enddate_param) dom.sms_outgoing = SMSLog.count_outgoing_by_domain(dom.name, datespan.startdate_param, datespan.enddate_param) dom.sms_total = SMSLog.count_by_domain(dom.name, datespan.startdate_param, datespan.enddate_param) context = get_hqadmin_base_context(request) headers = DataTablesHeader( DataTablesColumn("Domain"), DataTablesColumn("Incoming Messages", sort_type=DTSortType.NUMERIC), DataTablesColumn("Outgoing Messages", sort_type=DTSortType.NUMERIC), DataTablesColumn("Total Messages", sort_type=DTSortType.NUMERIC), ) context["headers"] = headers context["aoColumns"] = headers.render_aoColumns context.update({"domains": domains, "show_dates": show_dates, "datespan": datespan}) context["layout_flush_content"] = True return render(request, "hqadmin/message_log_report.html", context)
def message_log_report(request): show_dates = True datespan = request.datespan domains = Domain.get_all() for dom in domains: dom.sms_incoming = SMSLog.count_incoming_by_domain( dom.name, datespan.startdate_param, datespan.enddate_param) dom.sms_outgoing = SMSLog.count_outgoing_by_domain( dom.name, datespan.startdate_param, datespan.enddate_param) dom.sms_total = SMSLog.count_by_domain(dom.name, datespan.startdate_param, datespan.enddate_param) context = get_hqadmin_base_context(request) headers = DataTablesHeader( DataTablesColumn("Domain"), DataTablesColumn("Incoming Messages", sort_type=DTSortType.NUMERIC), DataTablesColumn("Outgoing Messages", sort_type=DTSortType.NUMERIC), DataTablesColumn("Total Messages", sort_type=DTSortType.NUMERIC)) context["headers"] = headers context["aoColumns"] = headers.render_aoColumns context.update({ "domains": domains, "show_dates": show_dates, "datespan": datespan }) context['layout_flush_content'] = True return render(request, "hqadmin/message_log_report.html", context)
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': SMSLog.count_incoming_by_domain(self.domain), 'outbound_messages': SMSLog.count_outgoing_by_domain(self.domain) } 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
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__iexact='FACILITY') for web_user in web_users: role = web_user.get_domain_membership(self.domain).role if role and role.name.lower().startswith('admin'): web_users_admins += 1 else: web_users_read_only += 1 main_context = super(GlobalStats, self).main_context location_types = Domain.get_by_name(self.domain).location_types administrative_types = [ location_type.name for location_type in location_types if not location_type.administrative ] entities_reported_stock = SQLLocation.objects.filter( domain=self.domain, location_type__in=administrative_types ).count() context = { 'root_name': self.root_name, 'country': SQLLocation.objects.filter(domain=self.domain, location_type__iexact=self.root_name).count(), 'region': SQLLocation.objects.filter(domain=self.domain, location_type__iexact='region').count(), 'district': SQLLocation.objects.filter(domain=self.domain, location_type__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).count(), 'product_stocks': StockState.objects.filter(sql_product__domain=self.domain).count(), 'stock_transactions': StockTransaction.objects.filter(report__domain=self.domain).count(), 'inbound_messages': SMSLog.count_incoming_by_domain(self.domain), 'outbound_messages': SMSLog.count_outgoing_by_domain(self.domain) } if self.show_supply_point_types: counts = SQLLocation.objects.values('location_type').filter(domain=self.domain).annotate( Count('location_type') ).order_by('location_type') context['location_types'] = counts main_context.update(context) return main_context
def main_context(self): contacts = CommCareUser.by_domain(self.domain, reduce=True) web_users = WebUser.by_domain(self.domain, reduce=True) main_context = super(GlobalStats, self).main_context context = { 'supply_points': SQLLocation.objects.filter(domain=self.domain).count(), 'facilities': SQLLocation.objects.filter(domain=self.domain, location_type__iexact='FACILITY').count(), 'contacts': contacts[0]['value'] if contacts else 0, 'web_users': web_users[0]['value'] if web_users else 0, 'products': SQLProduct.objects.filter(domain=self.domain).count(), 'product_stocks': StockState.objects.filter(sql_product__domain=self.domain).count(), 'stock_transactions': StockTransaction.objects.filter(report__domain=self.domain).count(), 'inbound_messages': SMSLog.count_incoming_by_domain(self.domain), 'outbound_messages': SMSLog.count_outgoing_by_domain(self.domain) } main_context.update(context) return main_context
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': SMSLog.count_incoming_by_domain(self.domain), 'outbound_messages': SMSLog.count_outgoing_by_domain(self.domain) } 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