def rows(self): for row in self.get_data(): display = CaseDisplay(self, row['_case']) yield [ display.case_id, display._dateprop('opened_on', iso=False), display._dateprop('closed_on', iso=False), self.lead_time(display.case['closed_on'], display.case['opened_on']), display.case['requisition_status'] ]
def anc_completed(self): lmp = self.lmp anc_date_1 = self.anc_date_1 if lmp != EMPTY_FIELD and anc_date_1 != EMPTY_FIELD: try: return _("yes") if CaseDisplay.parse_date(self, self.anc_date_1) < (CaseDisplay.parse_date(self, self.lmp) + timedelta(days=12*7)) else _("no") except AttributeError: return _("Bad date format!") else: return EMPTY_FIELD
def rows(self): checkbox = mark_safe('<input type="checkbox" class="selected-commcare-case" data-bind="event: {change: updateCaseSelection}" data-caseid="%(case_id)s" data-owner="%(owner)s" data-ownertype="%(owner_type)s" />') for row in self.es_results['hits'].get('hits', []): case = self.get_case(row) display = CaseDisplay(self, case) yield [ checkbox % dict(case_id=case['_id'], owner=display.owner_id, owner_type=display.owner_type), display.case_link, display.case_type, display.owner_display, util.format_relative_date(display.parse_date(display.case['modified_on']))['html'], ]
def rows(self): checkbox = mark_safe('<input type="checkbox" class="selected-commcare-case" data-caseid="%(case_id)s" data-owner="%(owner)s" data-ownertype="%(owner_type)s" />') for row in self.es_results['hits'].get('hits', []): case = self.get_case(row) display = CaseDisplay(self, case) yield [ checkbox % dict(case_id=case['_id'], owner=display.owner_id, owner_type=display.owner_type), display.case_link, display.case_type, display.owner_display, naturaltime(display.parse_date(display.case['modified_on'])), ]
def test_bad_case_display(): case_dict = { 'name': "It's a trap", 'modified_on': 'broken', } case_display = CaseDisplay(case_dict) assert_equal(case_display.modified_on, '')
def test_happy_case_display(): case_dict = { 'name': 'Foo', 'modified_on': '2022-04-06T12:13:14Z', } case_display = CaseDisplay(case_dict) assert_equal(case_display.modified_on, 'Apr 06, 2022 12:13:14 UTC')
def parse_date(self, date_string): if date_string != EMPTY_FIELD and date_string != '' and date_string is not None: try: return self.report.date_to_json(CaseDisplay.parse_date(self, date_string)) except AttributeError: return _("Bad date format!") else: return EMPTY_FIELD
def parse_date(self, date_string): if date_string != EMPTY_FIELD and date_string != '' and date_string is not None: try: return str(self.report.date_to_json(CaseDisplay.parse_date(self, date_string))) except AttributeError: return _("Bad date format!") except TypeError: return _("Bad date format!") else: return EMPTY_FIELD
def dob_age(self): if "mother_dob" in self.case and self.case["mother_dob"]: try: mother_dob = self.case["mother_dob"] if type(mother_dob) is dict: mother_dob = mother_dob["#value"] days = (date.today() - CaseDisplay.parse_date(self, mother_dob).date()).days mother_dob = self.parse_date(mother_dob) return "%s, %s" % (mother_dob, days/365) except AttributeError: return _("Bad date format!") else: return EMPTY_FIELD
def dob_age(self): if "dob" in self.case and self.case["dob"]: try: dob = self.case["dob"] if type(dob) is dict: dob = dob["#value"] days = (date.today() - CaseDisplay.parse_date(self, dob).date()).days dob = self.parse_date(dob) return "%s, %s" % (dob, int(days/365.25)) except AttributeError: return _("Bad date format!") else: return EMPTY_FIELD
def test_parse_date_noniso_datetime(): parsed = CaseDisplay({}).parse_date('Apr 06, 2022 12:13:14 UTC') assert_equal(parsed, datetime(2022, 4, 6, 12, 13, 14)) assert_not_equal(parsed, datetime(2022, 4, 6, 12, 13, 14, tzinfo=timezone.utc))
def test_parse_date_date(): parsed = CaseDisplay({}).parse_date('2022-04-06') assert_equal(parsed, datetime(2022, 4, 6, 0, 0, 0))
def test_parse_date_str(): parsed = CaseDisplay({}).parse_date('broken') assert_equal(parsed, 'broken')
def test_parse_date_none(): parsed = CaseDisplay({}).parse_date(None) assert_equal(parsed, None)
def test_parse_date_int(): parsed = CaseDisplay({}).parse_date(4) assert_equal(parsed, 4)
def test_parse_date_iso_datetime(): parsed = CaseDisplay({}).parse_date('2022-04-06T12:13:14Z') assert_equal(parsed, datetime(2022, 4, 6, 12, 13, 14)) # `date` is timezone naive assert_not_equal(parsed, datetime(2022, 4, 6, 12, 13, 14, tzinfo=timezone.utc))
def test_null_owner_id(): # previously this would error owner_type, meta = CaseDisplay({'owner_id': None}).owner assert_equal(owner_type, 'user') assert_equal(meta, {'id': None, 'name': None})
def test_blank_owner_id(): # previously this would error owner_type, meta = CaseDisplay({}).owner assert_equal(owner_type, 'user') assert_equal(meta, {'id': '', 'name': ''})