/
person.py
2363 lines (2117 loc) · 93.1 KB
/
person.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
#!/usr/bin/env python
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2007 Johan Gonqvist <johan.gronqvist@gmail.com>
# Copyright (C) 2007-2009 Gary Burton <gary.burton@zen.co.uk>
# Copyright (C) 2007-2009 Stephane Charette <stephanecharette@gmail.com>
# Copyright (C) 2008-2009 Brian G. Matherly
# Copyright (C) 2008 Jason M. Simanek <jason@bohemianalps.com>
# Copyright (C) 2008-2011 Rob G. Healey <robhealey1@gmail.com>
# Copyright (C) 2010 Doug Blank <doug.blank@gmail.com>
# Copyright (C) 2010 Jakim Friant
# Copyright (C) 2010- Serge Noiraud
# Copyright (C) 2011 Tim G L Lyons
# Copyright (C) 2013 Benny Malengier
# Copyright (C) 2016 Allen Crider
# Copyright (C) 2018 Theo van Rijn
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
"""
Narrative Web Page generator.
Classe:
PersonPage - Person index page and individual `Person pages
"""
# ------------------------------------------------
# python modules
# ------------------------------------------------
from collections import defaultdict
from operator import itemgetter
from decimal import Decimal, getcontext
import logging
# ------------------------------------------------
# Gramps module
# ------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale
from gramps.gen.lib import (
ChildRefType,
Date,
Name,
Person,
EventRoleType,
Family,
Event,
EventType,
)
from gramps.gen.lib.date import Today
from gramps.gen.mime import is_image_type
from gramps.gen.plug.report import Bibliography
from gramps.gen.plug.report import utils
from gramps.gen.utils.alive import probably_alive
from gramps.gen.constfunc import win
from gramps.gen.display.name import displayer as _nd
from gramps.gen.display.place import displayer as _pd
from gramps.gen.utils.db import get_birth_or_fallback, get_death_or_fallback
from gramps.plugins.lib.libhtml import Html
from gramps.gen.utils.place import conv_lat_lon, coord_formats
from gramps.gen.proxy import LivingProxyDb
from gramps.gen.relationship import get_relationship_calculator
# ------------------------------------------------
# specific narrative web import
# ------------------------------------------------
from gramps.plugins.webreport.basepage import BasePage
from gramps.plugins.webreport.common import (
alphabet_navigation,
add_birthdate,
FULLCLEAR,
_find_birth_date,
_find_death_date,
MARKER_PATH,
OPENLAYER,
OSM_MARKERS,
STAMEN_MARKERS,
GOOGLE_MAPS,
MARKERS,
html_escape,
DROPMASTERS,
FAMILYLINKS,
get_surname_from_person,
AlphabeticIndex,
)
from gramps.plugins.webreport.layout import LayoutTree
from gramps.plugins.webreport.buchheim import buchheim
_ = glocale.translation.sgettext
LOG = logging.getLogger(".NarrativeWeb")
getcontext().prec = 8
_WIDTH = 280
_HEIGHT = 140
_VGAP = 10
_HGAP = 30
_SHADOW = 5
_XOFFSET = 5
_YOFFSET = 5
_LOFFSET = 20
#################################################
#
# creates the Individual List Page and IndividualPages
#
#################################################
class PersonPages(BasePage):
"""
This class is responsible for displaying information about the 'Person'
database objects. It displays this information under the 'Individuals'
tab. It is told by the 'add_instances' call which 'Person's to display,
and remembers the list of persons. A single call to 'display_pages'
displays both the Individual List (Index) page and all the Individual
pages.
The base class 'BasePage' is initialised once for each page that is
displayed.
"""
def __init__(self, report, the_lang, the_title):
"""
@param: report -- The instance of the main report class
for this report
@param: the_lang -- The lang to process
@param: the_title -- The title page related to the language
"""
BasePage.__init__(self, report, the_lang, the_title)
self.ind_dict = defaultdict(set)
self.mapservice = None
self.sort_name = None
self.googleopts = None
self.googlemapkey = None
self.stamenopts = None
self.birthorder = None
self.person = None
self.familymappages = None
self.rel_class = None
self.placemappages = None
self.name = None
self.gender_map = None
def display_pages(self, the_lang, the_title):
"""
Generate and output the pages under the Individuals tab, namely the
individual index and the individual pages.
@param: the_lang -- The lang to process
@param: the_title -- The title page related to the language
"""
LOG.debug("obj_dict[Person]")
for item in self.report.obj_dict[Person].items():
LOG.debug(" %s", str(item))
message = _("Creating individual pages")
progress_title = self.report.pgrs_title(the_lang)
with self.r_user.progress(
progress_title, message, len(self.report.obj_dict[Person]) + 1
) as step:
index = 1
for person_handle in sorted(self.report.obj_dict[Person]):
step()
index += 1
person = self.r_db.get_person_from_handle(person_handle)
self.individualpage(self.report, the_lang, the_title, person)
step()
self.individuallistpage(
self.report, the_lang, the_title, self.report.obj_dict[Person].keys()
)
#################################################
#
# creates the Individual List Page
#
#################################################
def __output_person(
self,
date,
tbody,
bucket_letter,
bucket_link,
showbirth,
showdeath,
showpartner,
showparents,
surname,
surnamed,
first_surname,
first_individual,
person_handle,
):
"""
Generate and output the data for a single person
"""
person = self.r_db.get_person_from_handle(person_handle)
if person.get_change_time() > date:
date = person.get_change_time()
# surname column
trow = Html("tr")
tbody += trow
tcell = Html("td", class_="ColumnSurname", inline=True)
trow += tcell
if first_surname:
first_surname = False
first_individual = False
trow.attr = 'class = "BeginSurname"'
ttle = self._(
"Surnames %(surname)s beginning "
"with letter %(letter)s" % {"surname": surname, "letter": bucket_letter}
)
tcell += Html(
"a",
html_escape(surnamed),
name=bucket_letter,
id_=bucket_link,
title=ttle,
)
elif first_individual:
first_individual = False
tcell += Html(
"a", html_escape(surnamed), title=self._("Surnames") + " " + surname
)
else:
tcell += " "
# firstname column
link = self.new_person_link(person_handle, person=person)
trow += Html("td", link, class_="ColumnName")
# birth column
if showbirth:
tcell = Html("td", class_="ColumnBirth", inline=True)
trow += tcell
birth_date = _find_birth_date(self.r_db, person)
if birth_date is not None:
if birth_date.fallback:
tcell += Html("em", self.rlocale.get_date(birth_date), inline=True)
else:
tcell += self.rlocale.get_date(birth_date)
else:
tcell += " "
# death column
if showdeath:
tcell = Html("td", class_="ColumnDeath", inline=True)
trow += tcell
death_date = _find_death_date(self.r_db, person)
if death_date is not None:
if death_date.fallback:
tcell += Html("em", self.rlocale.get_date(death_date), inline=True)
else:
tcell += self.rlocale.get_date(death_date)
else:
tcell += " "
# partner column
if showpartner:
family_list = person.get_family_handle_list()
first_family = True
# partner_name = None
tcell = ()
if family_list:
for family_handle in family_list:
family = self.r_db.get_family_from_handle(family_handle)
partner_handle = utils.find_spouse(person, family)
if partner_handle:
if not first_family:
# have to do this to get the comma on
# the same line as the link
if isinstance(tcell[-1], Html):
# tcell is an instance of Html (or
# of a subclass thereof)
tcell[-1].inside += ","
else:
tcell = tcell[:-1] + (
# TODO for Arabic, translate?
(tcell[-1] + ", "),
)
# Have to manipulate as tuples so that
# subsequent people are not nested
# within the first link
tcell += (self.new_person_link(partner_handle),)
first_family = False
else:
tcell = " "
trow += Html("td", class_="ColumnPartner") + tcell
# parents column
if showparents:
parent_hdl_list = person.get_parent_family_handle_list()
if parent_hdl_list:
parent_handle = parent_hdl_list[0]
family = self.r_db.get_family_from_handle(parent_handle)
father_handle = family.get_father_handle()
mother_handle = family.get_mother_handle()
if father_handle:
father = self.r_db.get_person_from_handle(father_handle)
else:
father = None
if mother_handle:
mother = self.r_db.get_person_from_handle(mother_handle)
else:
mother = None
if father:
father_name = self.get_name(father)
if mother:
mother_name = self.get_name(mother)
samerow = False
if mother and father:
tcell = (
Html(
"span",
father_name,
class_="father fatherNmother",
inline=True,
),
Html("span", mother_name, class_="mother", inline=True),
)
elif mother:
tcell = Html("span", mother_name, class_="mother", inline=True)
elif father:
tcell = Html("span", father_name, class_="father", inline=True)
else:
tcell = " "
samerow = True
else:
tcell = " "
samerow = True
trow += Html("td", class_="ColumnParents", inline=samerow) + tcell
return (date, first_surname, first_individual)
def individuallistpage(self, report, the_lang, the_title, ppl_handle_list):
"""
Creates an individual page
@param: report -- The instance of the main report class
for this report
@param: the_lang -- The lang to process
@param: the_title -- The title page related to the language
@param: ppl_handle_list -- The list of people for whom we need
to create a page.
"""
BasePage.__init__(self, report, the_lang, the_title)
# plugin variables for this module
showbirth = report.options["showbirth"]
showdeath = report.options["showdeath"]
showpartner = report.options["showpartner"]
showparents = report.options["showparents"]
output_file, sio = self.report.create_file("individuals")
result = self.write_header(self._("Individuals"))
indlistpage, dummy_head, dummy_body, outerwrapper = result
date = 0
# begin Individuals division
with Html("div", class_="content", id="Individuals") as individuallist:
outerwrapper += individuallist
# Individual List page message
msg = self._(
"This page contains an index of all the individuals "
"in the database, sorted by their last names. "
"Selecting the person’s "
"name will take you to that "
"person’s individual page."
)
individuallist += Html("p", msg, id="description")
# add alphabet navigation
# Assemble all the handles for each surname into a dictionary
# We don't call sort_people because we don't care about sorting
# individuals, only surnames
surname_handle_dict = defaultdict(list)
for person_handle in ppl_handle_list:
person = self.r_db.get_person_from_handle(person_handle)
surname = get_surname_from_person(self.r_db, person)
surname_handle_dict[surname].append(person_handle)
# Assemble the alphabeticIndex
index = AlphabeticIndex(self.rlocale)
for surname, handle_list in surname_handle_dict.items():
index.addRecord(surname, handle_list)
# Extract the buckets from the index
index_list = []
index.resetBucketIterator()
while index.nextBucket():
if index.bucketRecordCount != 0:
index_list.append(index.bucketLabel)
# Output the navigation
alpha_nav = alphabet_navigation(index_list, self.rlocale, rtl=self.dir)
if alpha_nav is not None:
individuallist += alpha_nav
# begin table and table head
with Html(
"table", class_="infolist primobjlist IndividualList " + self.dir
) as table:
individuallist += table
thead = Html("thead")
table += thead
trow = Html("tr")
thead += trow
# show surname and first name
trow += Html(
"th", self._("Group as"), class_="ColumnSurname", inline=True
)
trow += Html("th", self._("Name"), class_="ColumnName", inline=True)
if showbirth:
trow += Html(
"th", self._("Birth"), class_="ColumnDate", inline=True
)
if showdeath:
trow += Html(
"th", self._("Death"), class_="ColumnDate", inline=True
)
if showpartner:
trow += Html(
"th", self._("Partner"), class_="ColumnPartner", inline=True
)
if showparents:
trow += Html(
"th", self._("Parents"), class_="ColumnParents", inline=True
)
tbody = Html("tbody")
table += tbody
# for each bucket, output the surnames in that bucket
index.resetBucketIterator()
output = []
dup_index = 0
while index.nextBucket():
if index.bucketRecordCount != 0:
surname_handle_dict = defaultdict(list)
bucket_letter = index.bucketLabel
bucket_link = bucket_letter
if bucket_letter in output:
bucket_link = "%s (%i)" % (bucket_letter, dup_index)
dup_index += 1
output.append(bucket_letter)
while index.nextRecord():
surname = index.recordName
handle_list = index.recordData
for handle in handle_list:
surname_handle_dict[surname].append(handle)
surname_handle_list = list(surname_handle_dict.items())
# sort by surname
surname_handle_list.sort(key=lambda x: self.rlocale.sort_key(x[0]))
name_format = self.report.options["name_format"]
nme_format = _nd.name_formats[name_format][1]
for surname, handle_list in surname_handle_list:
if not surname or surname.isspace():
surname = self._("<absent>")
# In case the user choose a format name like "*SURNAME*"
# We must display this field in upper case. So we use
# the english format of format_name to find if this is
# the case. name_format =
# self.report.options['name_format'] nme_format =
# _nd.name_formats[name_format][1]
if "SURNAME" in nme_format:
surnamed = surname.upper()
else:
surnamed = surname
first_surname = True
first_individual = True
for person_handle in sorted(
handle_list, key=self.sort_on_name_and_grampsid
):
(
date,
first_surname,
first_individual,
) = self.__output_person(
date,
tbody,
bucket_letter,
bucket_link,
showbirth,
showdeath,
showpartner,
showparents,
surname,
surnamed,
first_surname,
first_individual,
person_handle,
)
# create clear line for proper styling
# create footer section
footer = self.write_footer(date)
outerwrapper += (FULLCLEAR, footer)
# send page out for processing
# and close the file
self.xhtml_writer(indlistpage, output_file, sio, date)
#################################################
#
# creates an Individual Page
#
#################################################
def individualpage(self, report, the_lang, the_title, person):
"""
Creates an individual page
@param: report -- The instance of the main report class
for this report
@param: the_lang -- The lang to process
@param: the_title -- The title page related to the language
@param: person -- The person to use for this page.
"""
BasePage.__init__(self, report, the_lang, the_title, person.get_gramps_id())
place_lat_long = []
self.gender_map = {
Person.MALE: self._("male"),
Person.FEMALE: self._("female"),
Person.OTHER: self._("other"),
Person.UNKNOWN: self._("unknown"),
}
self.person = person
self.bibli = Bibliography()
self.sort_name = self.get_name(person)
self.name = self.get_name(person)
date = self.person.get_change_time()
# to be used in the Family Map Pages...
self.familymappages = self.report.options["familymappages"]
self.placemappages = self.report.options["placemappages"]
self.mapservice = self.report.options["mapservice"]
self.googleopts = self.report.options["googleopts"]
self.googlemapkey = self.report.options["googlemapkey"]
self.stamenopts = self.report.options["stamenopts"]
# decide if we will sort the birth order of siblings...
self.birthorder = self.report.options["birthorder"]
# get the Relationship Calculator so that we can determine
# bio, half, step- siblings for use in display_ind_parents() ...
self.rel_class = get_relationship_calculator(reinit=True, clocale=self.rlocale)
output_file, sio = self.report.create_file(person.get_handle(), "ppl")
self.uplink = True
result = self.write_header(self.sort_name)
indivdetpage, head, dummy_body, outerwrapper = result
# begin individualdetail division
with Html("div", class_="content", id="IndividualDetail") as individualdetail:
outerwrapper += individualdetail
# display a person's general data
thumbnail, name, summary = self.display_ind_general()
if thumbnail is not None:
individualdetail += thumbnail
individualdetail += (name, summary)
if self.report.options["notes"]:
# display Narrative Notes
notelist = person.get_note_list()
sect8 = self.display_note_list(notelist, Person)
if sect8 is not None:
individualdetail += sect8
# display a person's events
sect2 = self.display_ind_events(place_lat_long)
if sect2 is not None:
individualdetail += sect2
if self.report.options["relation"]:
# display relationship to the center person
sect3 = self.display_ind_center_person()
if sect3 is not None:
individualdetail += sect3
# display parents
sect4 = self.display_ind_parents()
if sect4 is not None:
individualdetail += sect4
# display relationships
relationships = self.display_relationships(self.person, place_lat_long)
if relationships is not None:
individualdetail += relationships
# display LDS ordinance
sect5 = self.display_lds_ordinance(self.person)
if sect5 is not None:
individualdetail += sect5
# display address(es) and show sources
sect6 = self.display_addr_list(self.person.get_address_list(), True)
if sect6 is not None:
individualdetail += sect6
photo_list = self.person.get_media_list()
media_list = photo_list[:]
# if Family Pages are not being created, then include the Family
# Media objects? There is no reason to add these objects to the
# Individual Pages...
if not self.inc_families:
for handle in self.person.get_family_handle_list():
family = self.r_db.get_family_from_handle(handle)
if family:
media_list += family.get_media_list()
for evt_ref in family.get_event_ref_list():
event = self.r_db.get_event_from_handle(evt_ref.ref)
media_list += event.get_media_list()
# if the Event Pages are not being created, then include the Event
# Media objects? There is no reason to add these objects to the
# Individual Pages...
if not self.inc_events:
for evt_ref in self.person.get_primary_event_ref_list():
event = self.r_db.get_event_from_handle(evt_ref.ref)
if event:
media_list += event.get_media_list()
# display additional images as gallery
if photo_list and self.create_media:
if self.the_lang and not self.usecms:
fname = "/".join(["..", "css", "lightbox.css"])
jsname = "/".join(["..", "css", "lightbox.js"])
else:
fname = "/".join(["css", "lightbox.css"])
jsname = "/".join(["css", "lightbox.js"])
url = self.report.build_url_fname(fname, None, self.uplink)
head += Html(
"link", href=url, type="text/css", media="screen", rel="stylesheet"
)
url = self.report.build_url_fname(jsname, None, self.uplink)
head += Html("script", src=url, type="text/javascript", inline=True)
sect7 = self.disp_add_img_as_gallery(media_list, person)
if sect7 is not None:
individualdetail += sect7
if not self.report.options["notes"]:
# display Narrative Notes
notelist = person.get_note_list()
sect8 = self.display_note_list(notelist, Person)
if sect8 is not None:
individualdetail += sect8
# display attributes
attrlist = person.get_attribute_list()
if attrlist:
attrsection, attrtable = self.display_attribute_header()
self.display_attr_list(attrlist, attrtable)
individualdetail += attrsection
# display web links
sect10 = self.display_url_list(self.person.get_url_list())
if sect10 is not None:
individualdetail += sect10
# display associations
assocs = person.get_person_ref_list()
if assocs:
individualdetail += self.display_ind_associations(assocs)
# for use in family map pages...
if place_lat_long:
if self.report.options["familymappages"]:
# save output_file, string_io and cur_fname
# before creating a new page
sof = output_file
sstring_io = sio
sfname = self.report.cur_fname
individualdetail += self.__display_family_map(
person, place_lat_long
)
# restore output_file, string_io and cur_fname
# after creating a new page
output_file = sof
sio = sstring_io
self.report.cur_fname = sfname
# display pedigree
sect13 = self.display_ind_pedigree()
if sect13 is not None:
individualdetail += sect13
# display ancestor tree
if report.options["ancestortree"]:
sect14 = self.display_tree()
if sect14 is not None:
individualdetail += sect14
# display source references
sect14 = self.display_ind_sources(person)
if sect14 is not None:
individualdetail += sect14
# add clearline for proper styling
# create footer section
footer = self.write_footer(date)
outerwrapper += (FULLCLEAR, footer)
# send page out for processing
# and close the file
self.xhtml_writer(indivdetpage, output_file, sio, date)
def _create_family_tracelife(
self, tracelife, placetitle, latitude, longitude, seq_, links
):
"""
creates individual family tracelife map events
@param: tracelife -- The family event list
@param: placetitle -- The place title to add to the event list
@param: latitude -- The latitude for this place
@param: longitude -- The longitude for this place
@param: seq_ -- The sequence number for this event (googlemap)
@param: links -- Used to add links in the popup html page
"""
# are we using Google?
if self.mapservice == "Google":
# are we creating Family Links?
if self.googleopts == "FamilyLinks":
tracelife += """
new google.maps.LatLng(%s, %s),""" % (
latitude,
longitude,
)
# are we creating Drop Markers or Markers?
elif self.googleopts in ["Drop", "Markers"]:
tracelife += """
['%s', %s, %s, %d, %s],""" % (
placetitle.replace("'", "\\'"),
latitude,
longitude,
seq_,
links,
)
# are we using OpenStreetMap, Stamen...
else:
tracelife += """
[%f, %f, \'%s\', %s],""" % (
float(longitude),
float(latitude),
placetitle.replace("'", "\\'"),
links,
)
return tracelife
def __create_links_tracelife(
self, links, person, placetitle, latitude, longitude, ref, event
):
"""
creates individual family events for a marker
@param: links -- Used to add links in the popup html page
@param: person -- family for this person
@param: placetitle -- The place title to add to the event list
@param: latitude -- The latitude for this place
@param: longitude -- The longitude for this place
@param: event -- The event for which we are working
@param: ref -- The back reference and role for the event
"""
if not person:
return links
url_fct = self.report.build_url_fname_html
ppl_fct = self.r_db.get_person_from_handle
ln_str = "<a href='%s' title='%s' target='_self'>%s</a>"
ppl_lnk = ""
(bkref_class, bkref_hdle, role) = ref
if role == "Marriage" or role == "Divorce" or role == "Family":
url = url_fct(bkref_hdle, "fam", self.uplink)
fam_fct = self.r_db.get_family_from_handle
fam = fam_fct(bkref_hdle)
fam_name = self.report.get_family_name(fam)
ppl_lnk = ln_str % (url, fam.get_gramps_id(), fam_name)
if "<p>" in links:
links += ' + "<br>%s"' % ppl_lnk
else:
links = '"<p>%s"' % ppl_lnk
elif bkref_class == Person: # and role == "Primary":
pers = ppl_fct(bkref_hdle)
url = url_fct(bkref_hdle, "ppl", self.uplink)
ppl_lnk = ln_str % (url, pers.get_gramps_id(), self.get_name(pers))
ppl_lnk = ln_str % (url, pers.get_gramps_id(), self.get_name(pers))
evt_type = self._(event.get_type().xml_str())
evt_date = self.rlocale.get_date(event.get_date_object())
url = url_fct(event.get_handle(), "evt", self.uplink)
evt_lnk = ln_str % (url, evt_date, evt_type)
evt_lnk += " (" + evt_date + ")"
if "<p>" in links:
links += ' + "<br>%s"' % (ppl_lnk + self._(":") + evt_lnk)
else:
links = '"<p>%s"' % (ppl_lnk + self._(":") + evt_lnk)
return links
def __create_family_map(self, person, place_lat_long):
"""
creates individual family map page
@param: person -- person from database
@param: place_lat_long -- for use in Family Map Pages
"""
if not place_lat_long:
return
output_file, sio = self.report.create_file(person.get_handle(), "maps")
self.uplink = True
result = self.write_header(self._("Family Map"))
familymappage, head, body, outerwrapper = result
minx, maxx = Decimal("0.00000001"), Decimal("0.00000001")
miny, maxy = Decimal("0.00000001"), Decimal("0.00000001")
xwidth, yheight = [], []
midx_, midy_, dummy_spanx, spany = [None] * 4
number_markers = len(place_lat_long)
if number_markers > 1:
for latitude, longitude, placetitle, handle, event in place_lat_long:
xwidth.append(latitude)
yheight.append(longitude)
xwidth.sort()
yheight.sort()
minx = xwidth[0] if xwidth[0] else minx
maxx = xwidth[-1] if xwidth[-1] else maxx
minx, maxx = Decimal(minx), Decimal(maxx)
midx_ = str(Decimal((minx + maxx) / 2))
miny = yheight[0] if yheight[0] else miny
maxy = yheight[-1] if yheight[-1] else maxy
miny, maxy = Decimal(miny), Decimal(maxy)
midy_ = str(Decimal((miny + maxy) / 2))
midx_, midy_ = conv_lat_lon(
midx_, midy_, coord_formats[self.report.options["coord_format"]]
)
# get the integer span of latitude and longitude
dummy_spanx = int(maxx - minx)
spany = int(maxy - miny)
# set zoom level based on span of Longitude?
tinyset = [value for value in (-3, -2, -1, 0, 1, 2, 3)]
smallset = [value for value in (-4, -5, -6, -7, 4, 5, 6, 7)]
middleset = [value for value in (-8, -9, -10, -11, 8, 9, 10, 11)]
largeset = [
value
for value in (-11, -12, -13, -14, -15, -16, -17, 11, 12, 13, 14, 15, 16, 17)
]
if spany in tinyset or spany in smallset:
zoomlevel = 6
elif spany in middleset:
zoomlevel = 5
elif spany in largeset:
zoomlevel = 4
else:
zoomlevel = 3
# 0 = latitude, 1 = longitude, 2 = place title,
# 3 = handle, and 4 = date, 5 = event type...
# being sorted by place_title
place_lat_long = sorted(place_lat_long, key=itemgetter(2))
# for all plugins
# if family_detail_page
# if active
# call_(report, up, head)
# add narrative-maps style sheet
if self.the_lang and not self.usecms:
fname = "/".join(["..", "css", "narrative-maps.css"])
else:
fname = "/".join(["css", "narrative-maps.css"])
url = self.report.build_url_fname(fname, None, self.uplink)
head += Html(
"link", href=url, type="text/css", media="screen", rel="stylesheet"
)
# add MapService specific javascript code
if self.mapservice == "Google":
src_js = GOOGLE_MAPS + "api/js"
if self.googlemapkey:
src_js += "?key=" + self.googlemapkey
head += Html("script", type="text/javascript", src=src_js, inline=True)
else: # OpenStreetMap, Stamen...
src_js = self.secure_mode
src_js += "ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"
head += Html("script", type="text/javascript", src=src_js, inline=True)
olv = self.report.options["ol_version"]
build = "legacy"
if olv < "v7.0.0":
build = "build"
if olv == "latest":
build = "legacy"
src_js = ("https://openlayers.org/en/" "%(ver)s/%(bld)s/ol.js") % {
"ver": olv,
"bld": build,
}
head += Html("script", type="text/javascript", src=src_js, inline=True)
css = "legacy"
if olv < "v7.0.0":
css = "css"
if olv == "latest":
css = "legacy"
url = ("https://openlayers.org/en/" "%(ver)s/%(css)s/ol.css") % {
"ver": olv,
"css": css,
}
head += Html("link", href=url, type="text/css", rel="stylesheet")
if number_markers > 0:
tracelife = "["
seq_ = 0
old_place_title = ""
links = "''"
for index in range(0, number_markers):
(latitude, longitude, placetitle, handle, event) = place_lat_long[index]
# Do we have several events for this place?
evthdle = event.get_handle()
bkref_list = self.report.bkref_dict[Event][evthdle]
if bkref_list:
if placetitle == old_place_title:
for ref in bkref_list:
links = self.__create_links_tracelife(
links,
person,
placetitle,
latitude,
longitude,
ref,
event,
)
# break
# continue
elif old_place_title != "" and index != 0:
(
lat,
lng,
plcetitle,
dummy_handle,
dummy_event,
) = place_lat_long[index - 1]
tracelife = self._create_family_tracelife(
tracelife, old_place_title, lat, lng, seq_, links
)
old_place_title = placetitle
links = "''"
for ref in bkref_list:
(bkref_class, bkref_hdle, role) = ref
links = self.__create_links_tracelife(
links,
person,
placetitle,
latitude,
longitude,
ref,
event,
)
else:
for ref in bkref_list:
(bkref_class, bkref_hdle, role) = ref
links = self.__create_links_tracelife(
links,
person,
placetitle,
latitude,
longitude,
ref,
event,
)
old_place_title = placetitle
seq_ += 1
tracelife = self._create_family_tracelife(
tracelife, placetitle, latitude, longitude, seq_, links
)
# (lat, lng, plcetitle, dummy_handle,