def validate_detail_columns(self, columns): from corehq.apps.app_manager.suite_xml.const import FIELD_TYPE_LOCATION from corehq.apps.locations.util import parent_child from corehq.apps.locations.fixtures import should_sync_hierarchical_fixture hierarchy = None for column in columns: if column.field_type == FIELD_TYPE_LOCATION: domain = self.module.get_app().domain domain_obj = Domain.get_by_name(domain) try: if not should_sync_hierarchical_fixture(domain_obj, self.module.get_app()): # discontinued feature on moving to flat fixture format raise LocationXpathValidationError( _('That format is no longer supported. To reference the location hierarchy you need to' ' use the "Custom Calculations in Case List" feature preview. For more information ' 'see: https://confluence.dimagi.com/pages/viewpage.action?pageId=38276915')) hierarchy = hierarchy or parent_child(domain) LocationXpath('').validate(column.field_property, hierarchy) except LocationXpathValidationError as e: yield { 'type': 'invalid location xpath', 'details': str(e), 'module': self.get_module_info(), 'column': column, }
def validate(self, ref, hierarchy): my_type, ref_type, property = self._parse_input(ref) types = self._ordered_types(hierarchy) for type in [my_type, ref_type]: if type not in types: raise LocationXpathValidationError( _('Type {type} must be in list of domain types: {list}'). format(type=type, list=', '.join(types))) if types.index(ref_type) > types.index(my_type): raise LocationXpathValidationError( _('Reference type {ref} cannot be a child of primary type {main}.' .format( ref=ref_type, main=my_type, )))
def _parse_input(self, input): try: my_type, ref = input.split(':') ref_type, property = ref.split('/') return my_type, ref_type, property except ValueError: raise LocationXpathValidationError( _('Property not correctly formatted. ' 'Must be formatted like: loacation:mytype:referencetype/property. ' 'For example: location:outlet:state/name'))