diff --git a/seed/audit_template/audit_template.py b/seed/audit_template/audit_template.py index 586baa3ea7..a3ab482ebc 100644 --- a/seed/audit_template/audit_template.py +++ b/seed/audit_template/audit_template.py @@ -390,10 +390,9 @@ def _batch_get_city_submission_xml(org_id, city_id, view_ids, progress_key): # however that could return multiple views across many cycles # filtering by custom_id and 'updated_at' will require looping through results to query views - property_views = PropertyView.objects.filter(id__in=view_ids) if view_ids else PropertyView.objects - # for development use - found_views = 0 - no_text_key = 0 + property_views = PropertyView.objects.filter(state__organization_id=org_id) + if view_ids: + property_views = property_views.filter(id__in=view_ids) xml_data_by_cycle = {} for sub in submissions: @@ -415,7 +414,6 @@ def _batch_get_city_submission_xml(org_id, city_id, view_ids, progress_key): progress_data.step("Getting XML for submissions...") if view: - found_views += 1 # for development use xml, _ = audit_template.get_submission(sub["id"], "xml") if hasattr(xml, "text"): @@ -425,28 +423,10 @@ def _batch_get_city_submission_xml(org_id, city_id, view_ids, progress_key): xml_data_by_cycle[view.cycle.id].append( {"property_view": view.id, "matching_field": custom_id_1, "xml": xml.text, "updated_at": sub["updated_at"]} ) - else: # for development use - no_text_key += 1 property_view_set = PropertyViewSet() # Update is cycle based, going to have update in cycle specific batches - combined_results = { - "success": 0, - "failure": 0, - "data": [], - # for development use - "cycles": list(xml_data_by_cycle.keys()), - "property_views": str(type(property_views)), - "view_count": property_views.count(), - "found_views": found_views, - "no_text_key": no_text_key, - "submissions": len(submissions), - "org_id": org_id, - "city_id": city_id, - "view_ids": view_ids, - "status_types": status_types, - "progress_data.total": progress_data.total, - } + combined_results = {"success": 0, "failure": 0, "data": []} try: for cycle, xmls in xml_data_by_cycle.items(): # does progress_data need to be recursively passed? diff --git a/seed/models/property_measures.py b/seed/models/property_measures.py index a7674a2e1c..b3ca8990d2 100644 --- a/seed/models/property_measures.py +++ b/seed/models/property_measures.py @@ -151,48 +151,42 @@ class Meta: @classmethod def str_to_impl_status(cls, impl_status): + default = cls._meta.get_field("implementation_status").default if not impl_status: - return None + return default if isinstance(impl_status, int): if impl_status in [(t[0]) for t in cls.IMPLEMENTATION_TYPES]: return impl_status - return None + return default - value = [y[0] for x, y in enumerate(cls.IMPLEMENTATION_TYPES) if y[1] == impl_status] - if len(value) == 1: - return value[0] - else: - return None + value = next((y[0] for x, y in enumerate(cls.IMPLEMENTATION_TYPES) if y[1] == impl_status), default) + return value @classmethod def str_to_category_affected(cls, category): + default = cls._meta.get_field("category_affected").default if not category: - return None + return default if isinstance(category, int): if category in [(t[0]) for t in cls.CATEGORY_AFFECTED_TYPE]: return category - return None + return default - value = [y[0] for x, y in enumerate(cls.CATEGORY_AFFECTED_TYPE) if y[1] == category] - if len(value) == 1: - return value[0] - else: - return None + value = next((y[0] for x, y in enumerate(cls.CATEGORY_AFFECTED_TYPE) if y[1] == category), default) + return value @classmethod def str_to_application_scale(cls, app_scale): + default = cls._meta.get_field("application_scale").default if not app_scale: - return None + return default if isinstance(app_scale, int): if app_scale in [(t[0]) for t in cls.APPLICATION_SCALE_TYPES]: return app_scale - return None + return default - value = [y[0] for x, y in enumerate(cls.APPLICATION_SCALE_TYPES) if y[1] == app_scale] - if len(value) == 1: - return value[0] - else: - return None + value = next((y[0] for x, y in enumerate(cls.APPLICATION_SCALE_TYPES) if y[1] == app_scale), default) + return value diff --git a/seed/tests/test_measures.py b/seed/tests/test_measures.py index d2e360ae45..90e2e55b07 100644 --- a/seed/tests/test_measures.py +++ b/seed/tests/test_measures.py @@ -86,19 +86,19 @@ def setUp(self): def test_lookups(self): self.assertEqual(PropertyMeasure.str_to_impl_status(PropertyMeasure.MEASURE_DISCARDED), 5) - self.assertEqual(PropertyMeasure.str_to_impl_status("measure discarded"), None) + self.assertEqual(PropertyMeasure.str_to_impl_status("measure discarded"), 1) self.assertEqual(PropertyMeasure.str_to_impl_status("Discarded"), 5) - self.assertEqual(PropertyMeasure.str_to_impl_status(None), None) + self.assertEqual(PropertyMeasure.str_to_impl_status(None), 1) self.assertEqual(PropertyMeasure.str_to_category_affected(PropertyMeasure.CATEGORY_DOMESTIC_HOT_WATER), 5) - self.assertEqual(PropertyMeasure.str_to_category_affected("domestic nothing"), None) + self.assertEqual(PropertyMeasure.str_to_category_affected("domestic nothing"), 27) self.assertEqual(PropertyMeasure.str_to_category_affected("Domestic Hot Water"), 5) - self.assertEqual(PropertyMeasure.str_to_category_affected(None), None) + self.assertEqual(PropertyMeasure.str_to_category_affected(None), 27) self.assertEqual(PropertyMeasure.str_to_application_scale(PropertyMeasure.SCALE_ENTIRE_FACILITY), 5) - self.assertEqual(PropertyMeasure.str_to_application_scale("Nothing entirely"), None) + self.assertEqual(PropertyMeasure.str_to_application_scale("Nothing entirely"), 5) self.assertEqual(PropertyMeasure.str_to_application_scale("Entire facility"), 5) - self.assertEqual(PropertyMeasure.str_to_application_scale(None), None) + self.assertEqual(PropertyMeasure.str_to_application_scale(None), 5) def test_populate_measures(self): self.assertEqual(Measure.objects.count(), 222)