4545#-------------------------------------------------------------------------
4646from gramps .gen .lib import (Person , Family , Note , Media , Place , Citation ,
4747 Source , Tag , Event , Repository , Name , Location ,
48- PlaceName )
48+ PlaceType )
49+ from gramps .gen .lib .placetype import DM_NAME
4950from gramps .gen .db import DbTxn
5051from gramps .gen .const import GRAMPS_LOCALE as glocale
5152try :
@@ -187,7 +188,7 @@ def get_child_ref_list(self, sql, from_type, from_handle):
187188 (frel0 , frel1 ), (mrel0 , mrel1 )))
188189 return retval
189190
190- def get_datamap_list (self , sql , from_type , from_handle ):
191+ def get_datamap_list (self , sql , _from_type , from_handle ):
191192 datamap = []
192193 rows = sql .query ("select * from datamap where from_handle = ?;" ,
193194 from_handle )
@@ -312,7 +313,7 @@ def pack_lds(self, sql, data):
312313 return (citation_list , note_list , date , type_ , place ,
313314 famc , temple , status , bool (private ))
314315
315- def pack_surnames (self , sql , data ):
316+ def pack_surnames (self , _sql , data ):
316317 (_handle ,
317318 surname ,
318319 prefix ,
@@ -355,7 +356,7 @@ def pack_repository_ref(self, sql, data):
355356 (source_media_type0 , source_media_type1 ),
356357 bool (private ))
357358
358- def pack_url (self , sql , data ):
359+ def pack_url (self , _sql , data ):
359360 (_handle ,
360361 path ,
361362 desc ,
@@ -451,7 +452,7 @@ def pack_name(self, sql, data):
451452 (name_type0 , name_type1 ),
452453 group_as , sort_as , display_as , call , nick , famnick )
453454
454- def pack_location (self , sql , data , with_parish ):
455+ def pack_location (self , _sql , data , with_parish ):
455456 (_handle , street , locality , city , county , state , country , postal ,
456457 phone , parish ) = data
457458 if with_parish :
@@ -476,15 +477,27 @@ def get_place_from_handle(self, sql, ref_handle):
476477 " returned %d records." % (ref_handle , len (place_row )))
477478 return ''
478479
479- def get_alt_place_name_list (self , sql , handle ):
480+ def get_place_name_list (self , sql , handle ):
480481 place_name_list = sql .query (
481482 """select * from place_name where from_handle = ?;""" , handle )
482483 retval = []
483484 for place_name_data in place_name_list :
484485 ref_handle , handle , value , lang = place_name_data
485486 date_handle = self .get_link (sql , "place_name" , ref_handle , "date" )
486487 date = self .get_date (sql , date_handle )
487- retval .append ((value , date , lang ))
488+ abbr_list = self .get_place_abbr_list (sql , ref_handle )
489+ citation_list = self .get_citation_list (sql , "place_name" ,
490+ ref_handle )
491+ retval .append ((value , date , lang , abbr_list , citation_list ))
492+ return retval
493+
494+ def get_place_abbr_list (self , sql , handle ):
495+ place_abbr_list = sql .query (
496+ """select * from place_abbrev where from_handle = ?;""" , handle )
497+ retval = []
498+ for place_abbr_data in place_abbr_list :
499+ _r_handle , handle , value , abbr_type0 , abbr_type1 = place_abbr_data
500+ retval .append ((value , (abbr_type0 , abbr_type1 )))
488501 return retval
489502
490503 def get_place_ref_list (self , sql , handle ):
@@ -493,11 +506,45 @@ def get_place_ref_list(self, sql, handle):
493506 place_ref_list = sql .query (
494507 """select * from place_ref where from_place_handle = ?;""" , handle )
495508 retval = []
496- for place_ref_data in place_ref_list :
497- ref_handle , handle , to_place_handle = place_ref_data
509+ for ref_data in place_ref_list :
510+ ref_handle , handle , to_place_handle , h_type0 , h_type1 = ref_data
498511 date_handle = self .get_link (sql , "place_ref" , ref_handle , "date" )
499512 date = self .get_date (sql , date_handle )
500- retval .append ((to_place_handle , date ))
513+ citation_list = self .get_citation_list (sql , "place_ref" ,
514+ ref_handle )
515+ retval .append ((to_place_handle , date , citation_list ,
516+ (h_type0 , h_type1 )))
517+ return retval
518+
519+ def get_place_type_list (self , sql , handle ):
520+ place_type_list = sql .query (
521+ """select * from place_type where from_handle = ?;""" ,
522+ handle )
523+ retval = []
524+ for place_type_data in place_type_list :
525+ ref_handle , handle , type0 , type1 = place_type_data
526+ date_handle = self .get_link (sql , "place_type" , ref_handle , "date" )
527+ date = self .get_date (sql , date_handle )
528+ citation_list = self .get_citation_list (sql , "place_type" ,
529+ ref_handle )
530+ retval .append ((type0 , date , citation_list ))
531+ if type0 in PlaceType .DATAMAP :
532+ # if the number is already there, we are done
533+ continue
534+ if type0 < PlaceType .CUSTOM :
535+ # number is not definitive, check for already there by name
536+ for tup in PlaceType .DATAMAP .values ():
537+ if type1 .lower () == tup [DM_NAME ].lower ():
538+ break
539+ else :
540+ PlaceType .DATAMAP [type0 ] = (type1 ,
541+ PlaceType .G_PLACE , # groups
542+ True ) # visible
543+ else :
544+ # not found, so store the new definition
545+ PlaceType .DATAMAP [type0 ] = (type1 ,
546+ PlaceType .G_PLACE , # groups
547+ True ) # visible
501548 return retval
502549
503550 def get_main_location (self , sql , from_handle , with_parish ):
@@ -784,8 +831,7 @@ def _process(self, count, total, sql):
784831 places = sql .query ("""select * from place;""" )
785832 for place in places :
786833 count += 1
787- (handle , gid , title , value , the_type0 , the_type1 , code , long , lat ,
788- lang , change , private ) = place
834+ (handle , gid , title , long , lat , change , private ) = place
789835
790836 # We could look this up by "place_main", but we have the handle:
791837 #main_loc = self.get_main_location(sql, handle, with_parish=True)
@@ -796,14 +842,15 @@ def _process(self, count, total, sql):
796842 citation_list = self .get_citation_list (sql , "place" , handle )
797843 note_list = self .get_note_list (sql , "place" , handle )
798844 tags = self .get_links (sql , "place" , handle , "tag" )
799- place_type = ( the_type0 , the_type1 )
800- alt_place_name_list = self .get_alt_place_name_list (sql , handle )
845+ place_type_list = self . get_place_type_list ( sql , handle )
846+ place_name_list = self .get_place_name_list (sql , handle )
801847 place_ref_list = self .get_place_ref_list (sql , handle )
848+ eventref_list = self .get_event_ref_list (sql , "place" , handle )
849+ attr_list = self .get_attribute_list (sql , "place" , handle )
802850 data = (handle , gid , title , long , lat , place_ref_list ,
803- PlaceName (value = value , lang = lang ).serialize (),
804- alt_place_name_list , place_type , code , alt_loc_list ,
805- urls , media_list , citation_list , note_list ,
806- change , tags , private )
851+ place_name_list , place_type_list , eventref_list ,
852+ alt_loc_list , urls , media_list , citation_list , note_list ,
853+ change , tags , private , attr_list )
807854 g_plac = Place ()
808855 g_plac .unserialize (data )
809856 self .db .commit_place (g_plac , self .trans )
@@ -900,3 +947,4 @@ def importData(db, filename, user):
900947 g = SQLReader (db , filename , user )
901948 g .process ()
902949 g .cleanup ()
950+ return _ ("Import finished..." )
0 commit comments