45
45
#-------------------------------------------------------------------------
46
46
from gramps .gen .lib import (Person , Family , Note , Media , Place , Citation ,
47
47
Source , Tag , Event , Repository , Name , Location ,
48
- PlaceName )
48
+ PlaceType )
49
+ from gramps .gen .lib .placetype import DM_NAME
49
50
from gramps .gen .db import DbTxn
50
51
from gramps .gen .const import GRAMPS_LOCALE as glocale
51
52
try :
@@ -187,7 +188,7 @@ def get_child_ref_list(self, sql, from_type, from_handle):
187
188
(frel0 , frel1 ), (mrel0 , mrel1 )))
188
189
return retval
189
190
190
- def get_datamap_list (self , sql , from_type , from_handle ):
191
+ def get_datamap_list (self , sql , _from_type , from_handle ):
191
192
datamap = []
192
193
rows = sql .query ("select * from datamap where from_handle = ?;" ,
193
194
from_handle )
@@ -312,7 +313,7 @@ def pack_lds(self, sql, data):
312
313
return (citation_list , note_list , date , type_ , place ,
313
314
famc , temple , status , bool (private ))
314
315
315
- def pack_surnames (self , sql , data ):
316
+ def pack_surnames (self , _sql , data ):
316
317
(_handle ,
317
318
surname ,
318
319
prefix ,
@@ -355,7 +356,7 @@ def pack_repository_ref(self, sql, data):
355
356
(source_media_type0 , source_media_type1 ),
356
357
bool (private ))
357
358
358
- def pack_url (self , sql , data ):
359
+ def pack_url (self , _sql , data ):
359
360
(_handle ,
360
361
path ,
361
362
desc ,
@@ -451,7 +452,7 @@ def pack_name(self, sql, data):
451
452
(name_type0 , name_type1 ),
452
453
group_as , sort_as , display_as , call , nick , famnick )
453
454
454
- def pack_location (self , sql , data , with_parish ):
455
+ def pack_location (self , _sql , data , with_parish ):
455
456
(_handle , street , locality , city , county , state , country , postal ,
456
457
phone , parish ) = data
457
458
if with_parish :
@@ -476,15 +477,27 @@ def get_place_from_handle(self, sql, ref_handle):
476
477
" returned %d records." % (ref_handle , len (place_row )))
477
478
return ''
478
479
479
- def get_alt_place_name_list (self , sql , handle ):
480
+ def get_place_name_list (self , sql , handle ):
480
481
place_name_list = sql .query (
481
482
"""select * from place_name where from_handle = ?;""" , handle )
482
483
retval = []
483
484
for place_name_data in place_name_list :
484
485
ref_handle , handle , value , lang = place_name_data
485
486
date_handle = self .get_link (sql , "place_name" , ref_handle , "date" )
486
487
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 )))
488
501
return retval
489
502
490
503
def get_place_ref_list (self , sql , handle ):
@@ -493,11 +506,45 @@ def get_place_ref_list(self, sql, handle):
493
506
place_ref_list = sql .query (
494
507
"""select * from place_ref where from_place_handle = ?;""" , handle )
495
508
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
498
511
date_handle = self .get_link (sql , "place_ref" , ref_handle , "date" )
499
512
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
501
548
return retval
502
549
503
550
def get_main_location (self , sql , from_handle , with_parish ):
@@ -784,8 +831,7 @@ def _process(self, count, total, sql):
784
831
places = sql .query ("""select * from place;""" )
785
832
for place in places :
786
833
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
789
835
790
836
# We could look this up by "place_main", but we have the handle:
791
837
#main_loc = self.get_main_location(sql, handle, with_parish=True)
@@ -796,14 +842,15 @@ def _process(self, count, total, sql):
796
842
citation_list = self .get_citation_list (sql , "place" , handle )
797
843
note_list = self .get_note_list (sql , "place" , handle )
798
844
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 )
801
847
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 )
802
850
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 )
807
854
g_plac = Place ()
808
855
g_plac .unserialize (data )
809
856
self .db .commit_place (g_plac , self .trans )
@@ -900,3 +947,4 @@ def importData(db, filename, user):
900
947
g = SQLReader (db , filename , user )
901
948
g .process ()
902
949
g .cleanup ()
950
+ return _ ("Import finished..." )
0 commit comments