def get_content_string(self, content, name): """Get user visible string of the content value. Args: content: dict with keys and values. name: dict key that we want to read. Returns: User visible string representation of a content value. """ value_map = self._content_value_map.get(self.child_type, {}).get(name) if value_map: return value_map.get(content.get(name), u"") if name in self.DATE_FIELDS: val = content.get(name) if not val: return u"" if "T" in val or " " in val: # values in format of "YYYY-MM-DDThh:mm:ss" and "YYYY-MM-DD hh:mm:ss" # since we only need date we will leave the time part behind val, _ = val.replace("T", " ").split(" ") return utils.iso_to_us_date(val) elif AttributeInfo.ALIASES_PREFIX in name: _, role_name = name.split(":") return "\n".join( self._access_control_map[content["id"]].get(role_name, []) ) return self.get_value_string(content.get(name))
def get_content_string(self, content, name): """Get user visible string of the content value. Args: content: dict with keys and values. name: dict key that we want to read. Returns: User visible string representation of a content value. """ value_map = self._content_value_map.get(self.child_type, {}).get(name) if value_map: return value_map.get(content.get(name), u"") if name in self.DATE_FIELDS: val = content.get(name) if not val: return u"" if "T" in val or " " in val: # values in format of "YYYY-MM-DDThh:mm:ss" and "YYYY-MM-DD hh:mm:ss" return val.replace("T", " ") return utils.iso_to_us_date(val) elif AttributeInfo.ALIASES_PREFIX in name: _, role_name = name.split(":") return "\n".join(self._access_control_map[content["id"]].get( role_name, [])) return self.get_value_string(content.get(name))
def test_control_export_with_ecad(self, attribute_type, multi_choice_options, attribute_value): """Test exporting of control with filtering by external cad.""" with factories.single_commit(): cad = factories.ExternalCustomAttributeDefinitionFactory( definition_type="control", attribute_type=attribute_type, multi_choice_options=multi_choice_options, ) control = factories.ControlFactory(slug="Control 1") factories.ExternalCustomAttributeValueFactory( attributable=control, custom_attribute=cad, attribute_value=attribute_value, ) search_request = [{ "object_name": "Control", "filters": { "expression": { "left": cad.title, "op": {"name": "="}, "right": attribute_value, }, }, }] parsed_data = self.export_parsed_csv(search_request)["Control"][0] self.assertIn(cad.title, parsed_data) if attribute_type == "Date": attribute_value = iso_to_us_date(attribute_value) self.assertEqual(parsed_data[cad.title], attribute_value)
def get_cav_value_string(self, value): """Get string representation of a custom attribute value.""" if value is None: return u"" cad = self._cad_map[value["custom_attribute_id"]] val = value.get("attribute_value") or u"" if cad["attribute_type"] == "Map:Person": return self._stub_cache.get(val, {}).get( value.get("attribute_object_id"), u"") if cad["attribute_type"] == "Checkbox": return self.BOOLEAN_ALIASES.get(val, u"") if cad["attribute_type"] == "Date" and val: return utils.iso_to_us_date(val) return val
def get_cav_value_string(self, value): """Get string representation of a custom attribute value.""" if value is None: return u"" cad = self._cad_map[value["custom_attribute_id"]] cav_value = value.get("attribute_value") or u"" if cad["attribute_type"] == "Map:Person": attribute_object_id = value.get("attribute_object")["id"] \ if value.get("attribute_object") else u"" return self._stub_cache.get(cav_value, {}).get(attribute_object_id, u"") if cad["attribute_type"] == "Checkbox": return self.BOOLEAN_ALIASES.get(cav_value, u"") if cad["attribute_type"] == "Date" and cav_value: return utils.iso_to_us_date(cav_value) return cav_value
def get_cav_value_string(self, value): """Get string representation of a custom attribute value.""" if value is None: return u"" cad = self._cad_map[value["custom_attribute_id"]] cav_value = value.get("attribute_value") or u"" if cad["attribute_type"] == "Map:Person": attribute_object_id = value.get("attribute_object")["id"] \ if value.get("attribute_object") else u"" return self._stub_cache.get(cav_value, {}).get(attribute_object_id, u"") if cad["attribute_type"] == "Checkbox": return self.BOOLEAN_ALIASES.get(cav_value, u"") if cad["attribute_type"] == "Date" and cav_value: return utils.iso_to_us_date(cav_value) return self.get_value_string(cav_value)
def get_content_string(self, content, name): """Get user visible string of the content value. Args: content: dict with keys and values. name: dict key that we want to read. Returns: User visible string representation of a content value. """ value_map = self._content_value_map.get(self.child_type, {}).get(name) if value_map: return value_map.get(content.get(name), u"") if name in self.DATE_FIELDS: val = content.get(name) if not val: return u"" if "T" in val or " " in val: # values in format of "YYYY-MM-DDThh:mm:ss" and "YYYY-MM-DD hh:mm:ss" return val.replace("T", " ") return utils.iso_to_us_date(val) return self.get_value_string(content.get(name))
def test_iso_to_us_date(self): """Test ISO to US date format conversion.""" self.assertEqual(utils.iso_to_us_date("2002-07-11"), "07/11/2002") with self.assertRaises(ValueError): utils.iso_to_us_date("1002-07-11")