def obj_get_list(self, bundle, **kwargs): custom_fields = [] domain = bundle.request.GET.get('domain') case_type = bundle.request.GET.get('case_type') create = bundle.request.GET.get('create') if not domain or not case_type: return [] custom_fields.append( CustomField( dict(type='unicode', key='case_name', label='Case name'))) if create == "False": custom_fields.append( CustomField( dict(type='unicode', key='case_id', label='Case ID'))) for prop in get_case_properties_for_case_type(domain, case_type): custom_fields.append( CustomField( dict(type='unicode', key=prop, label=self._build_label(prop)))) return custom_fields
def test_get_case_properties_for_case_type(self): schema = CaseExportDataSchema( group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ ExportItem( path=[PathNode(name='name')], label='name', last_occurrences={}, ), ExportItem( path=[PathNode(name='color')], label='color', last_occurrences={}, ), ], last_occurrences={}, ), ], ) with mock.patch( 'corehq.apps.export.models.new.CaseExportDataSchema.generate_schema_from_builds', return_value=schema): case_types = get_case_properties_for_case_type('test-domain', 'case-type') self.assertEqual(sorted(case_types), ['color', 'name'])
def test_get_case_properties_for_case_type(self): schema = CaseExportDataSchema( group_schemas=[ ExportGroupSchema( path=MAIN_TABLE, items=[ ExportItem( path=[PathNode(name='name')], label='name', last_occurrences={}, ), ExportItem( path=[PathNode(name='color')], label='color', last_occurrences={}, ), ], last_occurrences={}, ), ], ) with mock.patch( 'corehq.apps.export.models.new.CaseExportDataSchema.generate_schema_from_builds', return_value=schema): case_types = get_case_properties_for_case_type('test-domain', 'case-type') self.assertEqual(sorted(case_types), ['color', 'name'])
def get_suggested_case_fields(domain, case_type, exclude=None): exclude_fields = set(RESERVED_FIELDS) | set(exclude or []) special_field_specs = (field_spec for field_spec in get_special_fields()) dynamic_field_specs = (FieldSpec(field=field, show_in_menu=True) for field in get_case_properties_for_case_type(domain, case_type)) return _combine_field_specs( itertools.chain(special_field_specs, dynamic_field_specs), exclude_fields=exclude_fields )
def get_suggested_case_fields(domain, case_type, exclude=None): exclude_fields = set(RESERVED_FIELDS) | set(exclude or []) special_field_specs = (field_spec for field_spec in get_special_fields()) dynamic_field_specs = ( FieldSpec(field=field, show_in_menu=True) for field in get_case_properties_for_case_type(domain, case_type)) return _combine_field_specs(itertools.chain(special_field_specs, dynamic_field_specs), exclude_fields=exclude_fields)
def obj_get_list(self, bundle, **kwargs): custom_fields = [] domain = bundle.request.GET.get('domain') case_type = bundle.request.GET.get('case_type') for prop in get_case_properties_for_case_type(domain, case_type): custom_fields.append( CustomField( dict(type='unicode', key="properties__" + prop, label=self._build_label(prop)))) for case_prop, case_prop_zapier_name in CASE_PROPERTIES.iteritems(): custom_fields.append( CustomField( dict(type='unicode', key=case_prop, label=case_prop_zapier_name))) return custom_fields