def from_db_to_plr_record(self, params, public_law_restriction_from_db, legend_entries_from_db): thresholds = self._plr_info.get('thresholds') min_length = thresholds.get('length').get('limit') length_unit = thresholds.get('length').get('unit') min_area = thresholds.get('area').get('limit') area_unit = thresholds.get('area').get('unit') legend_entry_record = self.from_db_to_legend_entry_record( public_law_restriction_from_db.legend_entry) legend_entry_records = self.from_db_to_legend_entry_records( legend_entries_from_db, legend_entry_record.theme.sub_code) symbol = ImageRecord( b64.decode( binascii.b2a_base64( public_law_restriction_from_db.legend_entry.symbol).decode( 'ascii'))) view_service_record = self.from_db_to_view_service_record( public_law_restriction_from_db.view_service, legend_entry_records, self._plr_info.get('code')) theme = Config.get_theme_by_code_sub_code( public_law_restriction_from_db.legend_entry.theme, public_law_restriction_from_db.legend_entry.sub_theme) document_records = eliminate_duplicated_document_records( theme.document_records, self.get_document_records(params, public_law_restriction_from_db)) geometry_records = self.from_db_to_geometry_records( public_law_restriction_from_db.geometries) law_status = Config.get_law_status_by_data_code( self._plr_info.get('code'), public_law_restriction_from_db.law_status) sub_theme_legend_entry_record = \ legend_entry_record.theme if legend_entry_record.theme.sub_code else None plr_record = self._plr_record_class( Config.get_theme_by_code_sub_code(legend_entry_record.theme.code), legend_entry_record, law_status, public_law_restriction_from_db.published_from, public_law_restriction_from_db.published_until, self.from_db_to_office_record( public_law_restriction_from_db.responsible_office), symbol, view_service_record, geometry_records, sub_theme=sub_theme_legend_entry_record, type_code=public_law_restriction_from_db.legend_entry.type_code, type_code_list=public_law_restriction_from_db.legend_entry. type_code_list, documents=document_records, min_area=min_area, min_length=min_length, area_unit=area_unit, length_unit=length_unit, view_service_id=public_law_restriction_from_db.view_service.t_id) return plr_record
def from_db_to_geometry_records(self, geometries_from_db): geometry_records = [] for geometry_from_db in geometries_from_db: # Create law status record law_status = Config.get_law_status_by_data_code( self._plr_info.get('code'), geometry_from_db.law_status) # Create geometry records geometry_records.extend( self.create_geometry_records_(law_status, geometry_from_db.published_from, geometry_from_db.published_until, to_shape(geometry_from_db.geom), geometry_from_db.geo_metadata)) return geometry_records
def from_db_to_document_records(self, documents_from_db): document_records = [] for document in documents_from_db: office_record = self.from_db_to_office_record( document.responsible_office) law_status = Config.get_law_status_by_data_code( self._plr_info.get('code'), document.law_status) document_records.append( self._documents_record_class( document_type=Config.get_document_type_by_data_code( self._plr_info.get('code'), document.document_type), index=document.index, law_status=law_status, title=from_multilingual_text_to_dict(de=document.title_de, fr=document.title_fr, it=document.title_it, rm=document.title_rm, en=document.title_en), responsible_office=office_record, published_from=document.published_from, published_until=document.published_until, text_at_web=from_multilingual_uri_to_dict( document.multilingual_uri), abbreviation=from_multilingual_text_to_dict( de=document.abbreviation_de, fr=document.abbreviation_fr, it=document.abbreviation_it, rm=document.abbreviation_rm, en=document.abbreviation_en), official_number=from_multilingual_text_to_dict( de=document.official_number_de, fr=document.official_number_fr, it=document.official_number_it, rm=document.official_number_rm, en=document.official_number_en), only_in_municipality=document.only_in_municipality, article_numbers=None, file=None)) return document_records
def from_db_to_document_records(self, documents_from_db): document_records = [] for document in documents_from_db: office_record = self.from_db_to_office_record( document.responsible_office) law_status = Config.get_law_status_by_data_code( self._plr_info.get('code'), document.law_status) document_records.append( self._documents_record_class( document_type=Config.get_document_type_by_data_code( self._plr_info.get('code'), document.document_type), index=document.index, law_status=law_status, title=document.title, responsible_office=office_record, published_from=document.published_from, published_until=document.published_until, text_at_web=document.text_at_web, abbreviation=document.abbreviation, official_number=document.official_number, only_in_municipality=document.only_in_municipality, article_numbers=None, file=document.file)) return document_records