def add_party(self, party): """ Add a party entity to the collection of STR parties. .. versionadded:: 1.5 :param party: Party entity in STR relationship :type party: str or Entity :return: Returns True if the party was successfully added, otherwise False. If there is an existing party in the STR definition with the same name then the function returns False. :rtype: bool """ party_entity = self._obj_from_str(party) if party_entity is None: return False if self._party_in_parties(party_entity): return False fk_col_name = self._foreign_key_column_name(party_entity) party_fk = ForeignKeyColumn(fk_col_name, self) party_fk.on_delete_action = ForeignKeyColumn.CASCADE party_fk.set_entity_relation_attr('parent', party_entity) party_fk.set_entity_relation_attr('parent_column', 'id') self._party_fk_columns[fk_col_name] = party_fk self.add_column(party_fk) LOGGER.debug('%s entity has been successfully added as a party in ' 'the %s profile social tenure relationship.', party_entity.name, self.profile.name) return True
def add_spatial_unit(self, spatial_unit): """ Add a spatial unit entity to the collection of STR parties. .. versionadded:: 1.7 :param spatial_unit: Spatial unit entity in STR relationship. :type spatial_unit: str or Entity :return: Returns True if the spatial unit was successfully added, otherwise False. If there is an existing spatial unit in the STR definition with the same name or no geometry column then the function returns False. :rtype: bool """ sp_unit_entity = self._obj_from_str(spatial_unit) if sp_unit_entity is None: return False if self._sp_unit_in_sp_units(sp_unit_entity): return False if not sp_unit_entity.has_geometry_column(): return False fk_col_name = self._foreign_key_column_name(sp_unit_entity) sp_unit_fk = ForeignKeyColumn(fk_col_name, self) sp_unit_fk.on_delete_action = ForeignKeyColumn.CASCADE sp_unit_fk.set_entity_relation_attr('parent', sp_unit_entity) sp_unit_fk.set_entity_relation_attr('parent_column', 'id') self._spatial_unit_fk_columns[fk_col_name] = sp_unit_fk self.add_column(sp_unit_fk) # Link spatial unit to the default tenure type lookup self.add_spatial_tenure_mapping( sp_unit_entity, self.tenure_type_collection ) LOGGER.debug('%s entity has been successfully added as a spatial ' 'unit in the %s profile social tenure relationship.', sp_unit_entity.name, self.profile.name) return True