def rows(self): data = ExpectedCallback.by_domain( self.domain, start_date=self.datespan.startdate_utc, end_date=self.datespan.enddate_utc ).order_by('date') result = [] status_descriptions = { CALLBACK_PENDING : _("Pending"), CALLBACK_RECEIVED : _("Received"), CALLBACK_MISSED : _("Missed"), } # Store the results of lookups for faster loading username_map = {} for event in data: recipient_id = event.couch_recipient if recipient_id in [None, ""]: username = "******" elif recipient_id in username_map: username = username_map.get(recipient_id) else: username = "******" try: if event.couch_recipient_doc_type == "CommCareCase": username = CommCareCase.get(recipient_id).name else: username = CouchUser.get_by_user_id(recipient_id).username except Exception: pass username_map[recipient_id] = username timestamp = ServerTime(event.date).user_time(self.timezone).done() row = [ self._fmt_timestamp(timestamp), self._fmt(username), self._fmt(status_descriptions.get(event.status, "-")), ] result.append(row) return result
def rows(self): data = ExpectedCallback.by_domain( self.domain, start_date=self.datespan.startdate_utc, end_date=self.datespan.enddate_utc).order_by('date') result = [] status_descriptions = { CALLBACK_PENDING: _("Pending"), CALLBACK_RECEIVED: _("Received"), CALLBACK_MISSED: _("Missed"), } # Store the results of lookups for faster loading username_map = {} for event in data: recipient_id = event.couch_recipient if recipient_id in [None, ""]: username = "******" elif recipient_id in username_map: username = username_map.get(recipient_id) else: username = "******" try: if event.couch_recipient_doc_type == "CommCareCase": username = CommCareCase.get(recipient_id).name else: username = CouchUser.get_by_user_id( recipient_id).username except Exception: pass username_map[recipient_id] = username timestamp = ServerTime(event.date).user_time(self.timezone).done() row = [ self._fmt_timestamp(timestamp), self._fmt(username), self._fmt(status_descriptions.get(event.status, "-")), ] result.append(row) return result
def rows(self): group_id = None if self.request.couch_user.is_commcare_user(): group_ids = self.request.couch_user.get_group_ids() if len(group_ids) > 0: group_id = group_ids[0] data = {} for case in get_cases_in_domain(self.domain, type='participant'): if case.closed: continue # If a site coordinator is viewing the report, only show participants from that site (group) if group_id is None or group_id == case.owner_id: timezone = pytz.timezone(case.get_case_property("time_zone")) data[case._id] = { "name": case.name, "time_zone": timezone, "dates": [None] * 14, } dates = self.get_past_two_weeks() date_strings = [json_format_date(date) for date in dates] start_date = dates[0] - timedelta(days=1) end_date = dates[-1] + timedelta(days=2) expected_callback_events = ExpectedCallback.by_domain( self.domain, start_date=datetime.combine(start_date, time(0, 0)), end_date=datetime.combine(end_date, time(0, 0))).order_by('date') for event in expected_callback_events: if event.couch_recipient in data: timezone = data[event.couch_recipient]["time_zone"] event_date = (ServerTime( event.date).user_time(timezone).ui_string("%Y-%m-%d")) if event_date in date_strings: data[event.couch_recipient]["dates"][date_strings.index( event_date)] = event.status result = [] for case_id, data_dict in data.items(): row = [ self._fmt(data_dict["name"]), None, None, None, ] total_no_response = 0 total_indicated = 0 total_pending = 0 for date_status in data_dict["dates"]: if date_status == CALLBACK_PENDING: total_indicated += 1 total_pending += 1 row.append(self._fmt(_("pending"))) elif date_status == CALLBACK_RECEIVED: total_indicated += 1 row.append(self._fmt(_("OK"))) elif date_status == CALLBACK_MISSED: total_indicated += 1 total_no_response += 1 row.append(self._fmt_highlight(_("No Response"))) else: row.append(self._fmt(_("not indicated"))) if total_no_response > 0: row[1] = self._fmt_highlight(total_no_response) else: row[1] = self._fmt(total_no_response) row[2] = self._fmt(total_indicated) row[3] = self._fmt(total_pending) result.append(row) return result
def rows(self): group_id = None if self.request.couch_user.is_commcare_user(): group_ids = self.request.couch_user.get_group_ids() if len(group_ids) > 0: group_id = group_ids[0] data = {} for case in get_cases_in_domain(self.domain, type='participant'): if case.closed: continue # If a site coordinator is viewing the report, only show participants from that site (group) if group_id is None or group_id == case.owner_id: timezone = pytz.timezone(case.get_case_property("time_zone")) data[case._id] = { "name": case.name, "time_zone": timezone, "dates": [None] * 14, } dates = self.get_past_two_weeks() date_strings = [json_format_date(date) for date in dates] start_date = dates[0] - timedelta(days=1) end_date = dates[-1] + timedelta(days=2) expected_callback_events = ExpectedCallback.by_domain( self.domain, start_date=datetime.combine(start_date, time(0, 0)), end_date=datetime.combine(end_date, time(0, 0)) ).order_by('date') for event in expected_callback_events: if event.couch_recipient in data: timezone = data[event.couch_recipient]["time_zone"] event_date = (ServerTime(event.date).user_time(timezone) .ui_string("%Y-%m-%d")) if event_date in date_strings: data[event.couch_recipient]["dates"][date_strings.index(event_date)] = event.status result = [] for case_id, data_dict in data.items(): row = [ self._fmt(data_dict["name"]), None, None, None, ] total_no_response = 0 total_indicated = 0 total_pending = 0 for date_status in data_dict["dates"]: if date_status == CALLBACK_PENDING: total_indicated += 1 total_pending += 1 row.append(self._fmt(_("pending"))) elif date_status == CALLBACK_RECEIVED: total_indicated += 1 row.append(self._fmt(_("OK"))) elif date_status == CALLBACK_MISSED: total_indicated += 1 total_no_response += 1 row.append(self._fmt_highlight(_("No Response"))) else: row.append(self._fmt(_("not indicated"))) if total_no_response > 0: row[1] = self._fmt_highlight(total_no_response) else: row[1] = self._fmt(total_no_response) row[2] = self._fmt(total_indicated) row[3] = self._fmt(total_pending) result.append(row) return result