def write_person(self, count): if count != 0: self.doc.page_break() self.bibli = Bibliography(Bibliography.MODE_DATE | Bibliography.MODE_PAGE) text = self._name_display.display(self.person) # feature request 2356: avoid genitive form title = self._("Summary of %s") % text mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.start_paragraph("IDS-Title") self.doc.write_text(title, mark) self.doc.end_paragraph() self.doc.start_paragraph("IDS-Normal") self.doc.end_paragraph() name = self.person.get_primary_name() text = self.get_name(self.person) mark = ReportUtils.get_person_mark(self._db, self.person) endnotes = self._cite_endnote(self.person) endnotes = self._cite_endnote(name, prior=endnotes) family_handle = self.person.get_main_parents_family_handle() if family_handle: family = self._db.get_family_from_handle(family_handle) father_inst_id = family.get_father_handle() if father_inst_id: father_inst = self._db.get_person_from_handle(father_inst_id) father = self.get_name(father_inst) fmark = ReportUtils.get_person_mark(self._db, father_inst) else: father = "" fmark = None mother_inst_id = family.get_mother_handle() if mother_inst_id: mother_inst = self._db.get_person_from_handle(mother_inst_id) mother = self.get_name(mother_inst) mmark = ReportUtils.get_person_mark(self._db, mother_inst) else: mother = "" mmark = None else: father = "" fmark = None mother = "" mmark = None media_list = self.person.get_media_list() p_style = 'IDS-PersonTable2' if self.use_images and len(media_list) > 0: media0 = media_list[0] media_handle = media0.get_reference_handle() media = self._db.get_object_from_handle(media_handle) mime_type = media.get_mime_type() if mime_type and mime_type.startswith("image"): image_filename = media_path_full(self._db, media.get_path()) if os.path.exists(image_filename): p_style = 'IDS-PersonTable' # this is tested for, also else: self._user.warn( _("Could not add photo to page"), # translators: for French, else ignore _("%(str1)s: %(str2)s") % { 'str1': image_filename, 'str2': _('File does not exist') }) self.doc.start_table('person', p_style) self.doc.start_row() self.doc.start_cell('IDS-NormalCell') # translators: needed for French, ignore otherwise ignore4 = self._("%s:") self.write_paragraph(self._("%s:") % self._("Name")) self.write_paragraph(self._("%s:") % self._("Gender")) self.write_paragraph(self._("%s:") % self._("Father")) self.write_paragraph(self._("%s:") % self._("Mother")) self.doc.end_cell() self.doc.start_cell('IDS-NormalCell') self.write_paragraph(text, endnotes, mark) if self.person.get_gender() == Person.MALE: self.write_paragraph(self._("Male")) elif self.person.get_gender() == Person.FEMALE: self.write_paragraph(self._("Female")) else: self.write_paragraph(self._("Unknown")) self.write_paragraph(father, mark=fmark) self.write_paragraph(mother, mark=mmark) self.doc.end_cell() if p_style == 'IDS-PersonTable': self.doc.start_cell('IDS-NormalCell') self.doc.add_media_object(image_filename, "right", 4.0, 4.0, crop=media0.get_rectangle()) endnotes = self._cite_endnote(media0) attr_list = media0.get_attribute_list() if len(attr_list) == 0: text = _('(image)') else: for attr in attr_list: attr_type = self._get_type(attr.get_type()) # translators: needed for French, ignore otherwise text = self._("%(str1)s: %(str2)s") % { 'str1': self._(attr_type), 'str2': attr.get_value() } endnotes = self._cite_endnote(attr, prior=endnotes) self.write_paragraph("(%s)" % text, endnotes=endnotes, style='IDS-ImageNote') endnotes = '' if endnotes and len(attr_list) == 0: self.write_paragraph(text, endnotes=endnotes, style='IDS-ImageNote') self.doc.end_cell() self.doc.end_row() self.doc.end_table() self.doc.start_paragraph("IDS-Normal") self.doc.end_paragraph() self.write_alt_names() self.write_events() self.write_alt_parents() self.write_families() self.write_addresses() self.write_associations() self.write_attributes() self.write_LDS_ordinances() self.write_note() if self.use_srcs: if self.use_pagebreak and self.bibli.get_citation_count(): self.doc.page_break() Endnotes.write_endnotes(self.bibli, self._db, self.doc, printnotes=self.use_srcs_notes, elocale=self._locale)
def __init__(self, database, options, user): """ Create the DetDescendantReport object that produces the report. The arguments are: database - the GRAMPS database instance options - instance of the Options class for this report user - a gen.user.User() instance This report needs the following parameters (class variables) that come in the options class. gen - Maximum number of generations to include. pagebgg - Whether to include page breaks between generations. pageben - Whether to include page break before End Notes. fulldates - Whether to use full dates instead of just year. listc - Whether to list children. incnotes - Whether to include notes. usecall - Whether to use the call name as the first name. repplace - Whether to replace missing Places with ___________. repdate - Whether to replace missing Dates with ___________. computeage - Whether to compute age. omitda - Whether to omit duplicate ancestors (e.g. when distant cousins marry). verbose - Whether to use complete sentences. numbering - The descendancy numbering system to be utilized. desref - Whether to add descendant references in child list. incphotos - Whether to include images. incnames - Whether to include other names. incevents - Whether to include events. incaddresses - Whether to include addresses. incsrcnotes - Whether to include source notes in the Endnotes section. Only works if Include sources is selected. incmates - Whether to include information about spouses incattrs - Whether to include attributes incpaths - Whether to include the path of descendancy from the start-person to each descendant. incssign - Whether to include a sign ('+') before the descendant number in the child-list to indicate a child has succession. pid - The Gramps ID of the center person for the report. name_format - Preferred format to display names incmateref - Whether to print mate information or reference incl_private - Whether to include private data """ Report.__init__(self, database, options, user) self.map = {} self._user = user menu = options.menu get_option_by_name = menu.get_option_by_name get_value = lambda name: get_option_by_name(name).get_value() stdoptions.run_private_data_option(self, menu) self.db = self.database self.max_generations = get_value('gen') self.pgbrk = get_value('pagebbg') self.pgbrkenotes = get_value('pageben') self.fulldate = get_value('fulldates') use_fulldate = self.fulldate self.listchildren = get_value('listc') self.inc_notes = get_value('incnotes') use_call = get_value('usecall') blankplace = get_value('repplace') blankdate = get_value('repdate') self.calcageflag = get_value('computeage') self.dubperson = get_value('omitda') self.verbose = get_value('verbose') self.numbering = get_value('numbering') self.childref = get_value('desref') self.addimages = get_value('incphotos') self.inc_names = get_value('incnames') self.inc_events = get_value('incevents') self.inc_addr = get_value('incaddresses') self.inc_sources = get_value('incsources') self.inc_srcnotes = get_value('incsrcnotes') self.inc_mates = get_value('incmates') self.inc_attrs = get_value('incattrs') self.inc_paths = get_value('incpaths') self.inc_ssign = get_value('incssign') self.inc_materef = get_value('incmateref') pid = get_value('pid') self.center_person = self.db.get_person_from_gramps_id(pid) if (self.center_person == None): raise ReportError(_("Person %s is not in the Database") % pid) self.gen_handles = {} self.prev_gen_handles = {} self.gen_keys = [] self.dnumber = {} self.dmates = {} if blankdate: empty_date = EMPTY_ENTRY else: empty_date = "" if blankplace: empty_place = EMPTY_ENTRY else: empty_place = "" self._locale = self.set_locale(get_value('trans')) stdoptions.run_name_format_option(self, menu) self.__narrator = Narrator(self.db, self.verbose, use_call, use_fulldate, empty_date, empty_place, nlocale=self._locale, get_endnote_numbers=self.endnotes) self.bibli = Bibliography(Bibliography.MODE_DATE | Bibliography.MODE_PAGE)
def __init__(self, database, options, user): """ Create the DetAncestorReport object that produces the report. The arguments are: database - the Gramps database instance options - instance of the Options class for this report user - a gen.user.User() instance This report needs the following parameters (class variables) that come in the options class. gen - Maximum number of generations to include. inc_id - Whether to include Gramps IDs pagebgg - Whether to include page breaks between generations. pageben - Whether to include page break before End Notes. firstName - Whether to use first names instead of pronouns. fulldate - Whether to use full dates instead of just year. listchildren - Whether to list children. list_children_spouses - Whether to list the spouses of the children includenotes - Whether to include notes. incattrs - Whether to include attributes blankplace - Whether to replace missing Places with ___________. blankDate - Whether to replace missing Dates with ___________. calcageflag - Whether to compute age. dupperson - Whether to omit duplicate ancestors (e.g. when distant cousins marry). verbose - Whether to use complete sentences childref - Whether to add descendant references in child list. addimages - Whether to include images. pid - The Gramps ID of the center person for the report. name_format - Preferred format to display names other_events - Whether to include other events. incl_private - Whether to include private data living_people - How to handle living people years_past_death - Consider as living this many years after death """ Report.__init__(self, database, options, user) self.map = {} self._user = user menu = options.menu get_option_by_name = menu.get_option_by_name get_value = lambda name: get_option_by_name(name).get_value() self.set_locale(menu.get_option_by_name('trans').get_value()) stdoptions.run_date_format_option(self, menu) stdoptions.run_private_data_option(self, menu) stdoptions.run_living_people_option(self, menu, self._locale) self.database = CacheProxyDb(self.database) self._db = self.database self.max_generations = get_value('gen') self.pgbrk = get_value('pagebbg') self.pgbrkenotes = get_value('pageben') self.fulldate = get_value('fulldates') use_fulldate = self.fulldate self.listchildren = get_value('listc') self.list_children_spouses = get_value('listc_spouses') self.includenotes = get_value('incnotes') use_call = get_value('usecall') blankplace = get_value('repplace') blankdate = get_value('repdate') self.calcageflag = get_value('computeage') self.dupperson = get_value('omitda') self.verbose = get_value('verbose') self.childref = get_value('desref') self.addimages = get_value('incphotos') self.inc_names = get_value('incnames') self.inc_events = get_value('incevents') self.inc_addr = get_value('incaddresses') self.inc_sources = get_value('incsources') self.inc_srcnotes = get_value('incsrcnotes') self.inc_attrs = get_value('incattrs') self.initial_sosa = get_value('initial_sosa') self.want_ids = get_value('inc_id') pid = get_value('pid') self.other_events = get_value('incotherevents') self.center_person = self._db.get_person_from_gramps_id(pid) if self.center_person is None: raise ReportError(_("Person %s is not in the Database") % pid) stdoptions.run_name_format_option(self, menu) self._nd = self._name_display self.gen_handles = {} self.prev_gen_handles = {} if blankdate: empty_date = EMPTY_ENTRY else: empty_date = "" if blankplace: empty_place = EMPTY_ENTRY else: empty_place = "" self.__narrator = Narrator(self._db, self.verbose, use_call, use_fulldate, empty_date, empty_place, nlocale=self._locale, get_endnote_numbers=self.endnotes) self.bibli = Bibliography(Bibliography.MODE_DATE|Bibliography.MODE_PAGE)
def __init__(self, report, title, step): """ @param: report -- The instance of the main report class for this report @param: title -- Is the title of the web page """ import posixpath BasePage.__init__(self, report, title) self.bibli = Bibliography() self.uplink = False self.report = report # set the file name and open file output_file, sio = self.report.create_file("statistics") addressbookpage, head, body = self.write_header(_("Statistics")) (males, females, unknown) = self.get_gender(report.database.iter_person_handles()) step() mobjects = report.database.get_number_of_media() npersons = report.database.get_number_of_people() nfamilies = report.database.get_number_of_families() nsurnames = len(set(report.database.surname_list)) notfound = [] total_media = 0 mbytes = "0" chars = 0 for media in report.database.iter_media(): total_media += 1 fullname = media_path_full(report.database, media.get_path()) try: chars += posixpath.getsize(fullname) length = len(str(chars)) if chars <= 999999: mbytes = _("less than 1") else: mbytes = str(chars)[:(length - 6)] except OSError: notfound.append(media.get_path()) with Html("div", class_="content", id='EventDetail') as section: section += Html("h3", self._("Database overview"), inline=True) body += section with Html("div", class_="content", id='subsection narrative') as sec11: sec11 += Html("h4", self._("Individuals"), inline=True) body += sec11 with Html("div", class_="content", id='subsection narrative') as sec1: sec1 += Html("br", self._("Number of individuals") + self.colon + "%d" % npersons, inline=True) sec1 += Html("br", self._("Males") + self.colon + "%d" % males, inline=True) sec1 += Html("br", self._("Females") + self.colon + "%d" % females, inline=True) sec1 += Html("br", self._("Individuals with unknown gender") + self.colon + "%d" % unknown, inline=True) body += sec1 with Html("div", class_="content", id='subsection narrative') as sec2: sec2 += Html("h4", self._("Family Information"), inline=True) sec2 += Html("br", self._("Number of families") + self.colon + "%d" % nfamilies, inline=True) sec2 += Html("br", self._("Unique surnames") + self.colon + "%d" % nsurnames, inline=True) body += sec2 with Html("div", class_="content", id='subsection narrative') as sec3: sec3 += Html("h4", self._("Media Objects"), inline=True) sec3 += Html("br", self._("Total number of media object references") + self.colon + "%d" % total_media, inline=True) sec3 += Html("br", self._("Number of unique media objects") + self.colon + "%d" % mobjects, inline=True) sec3 += Html("br", self._("Total size of media objects") + self.colon + "%8s %s" % (mbytes, self._("Megabyte|MB")), inline=True) sec3 += Html("br", self._("Missing Media Objects") + self.colon + "%d" % len(notfound), inline=True) body += sec3 with Html("div", class_="content", id='subsection narrative') as sec4: sec4 += Html("h4", self._("Miscellaneous"), inline=True) sec4 += Html("br", self._("Number of events") + self.colon + "%d" % report.database.get_number_of_events(), inline=True) sec4 += Html("br", self._("Number of places") + self.colon + "%d" % report.database.get_number_of_places(), inline=True) nsources = report.database.get_number_of_sources() sec4 += Html("br", self._("Number of sources") + self.colon + "%d" % nsources, inline=True) ncitations = report.database.get_number_of_citations() sec4 += Html("br", self._("Number of citations") + self.colon + "%d" % ncitations, inline=True) nrepo = report.database.get_number_of_repositories() sec4 += Html("br", self._("Number of repositories") + self.colon + "%d" % nrepo, inline=True) body += sec4 (males, females, unknown) = self.get_gender(self.report.bkref_dict[Person].keys()) origin = " :<br/>" + report.filter.get_name(self.rlocale) with Html("div", class_="content", id='EventDetail') as section: section += Html("h3", self._("Narrative web content report for") + origin, inline=True) body += section with Html("div", class_="content", id='subsection narrative') as sec5: sec5 += Html("h4", self._("Individuals"), inline=True) sec5 += Html("br", self._("Number of individuals") + self.colon + "%d" % len(self.report.bkref_dict[Person]), inline=True) sec5 += Html("br", self._("Males") + self.colon + "%d" % males, inline=True) sec5 += Html("br", self._("Females") + self.colon + "%d" % females, inline=True) sec5 += Html("br", self._("Individuals with unknown gender") + self.colon + "%d" % unknown, inline=True) body += sec5 with Html("div", class_="content", id='subsection narrative') as sec6: sec6 += Html("h4", self._("Family Information"), inline=True) sec6 += Html("br", self._("Number of families") + self.colon + "%d" % len(self.report.bkref_dict[Family]), inline=True) body += sec6 with Html("div", class_="content", id='subsection narrative') as sec7: sec7 += Html("h4", self._("Miscellaneous"), inline=True) sec7 += Html("br", self._("Number of events") + self.colon + "%d" % len(self.report.bkref_dict[Event]), inline=True) sec7 += Html("br", self._("Number of places") + self.colon + "%d" % len(self.report.bkref_dict[Place]), inline=True) sec7 += Html("br", self._("Number of sources") + self.colon + "%d" % len(self.report.bkref_dict[Source]), inline=True) sec7 += Html("br", self._("Number of citations") + self.colon + "%d" % len(self.report.bkref_dict[Citation]), inline=True) sec7 += Html("br", self._("Number of repositories") + self.colon + "%d" % len(self.report.bkref_dict[Repository]), inline=True) body += sec7 # add fullclear for proper styling # and footer section to page footer = self.write_footer(None) body += (FULLCLEAR, footer) # send page out for processing # and close the file self.xhtml_writer(addressbookpage, output_file, sio, 0)
def eventpage(self, report, title, event_handle): """ Creates the individual event page @param: report -- The instance of the main report class for this report @param: title -- Is the title of the web page @param: event_handle -- The event handle for the database """ event = report.database.get_event_from_handle(event_handle) BasePage.__init__(self, report, title, event.get_gramps_id()) if not event: return None ldatec = event.get_change_time() event_media_list = event.get_media_list() self.uplink = True subdirs = True evt_type = self._(event.get_type().xml_str()) self.page_title = "%(eventtype)s" % {'eventtype': evt_type} self.bibli = Bibliography() output_file, sio = self.report.create_file(event_handle, "evt") eventpage, head, body = self.write_header(self._("Events")) # start event detail division with Html("div", class_="content", id="EventDetail") as eventdetail: body += eventdetail thumbnail = self.disp_first_img_as_thumbnail( event_media_list, event) if thumbnail is not None: eventdetail += thumbnail # display page title eventdetail += Html("h3", self.page_title, inline=True) # begin eventdetail table with Html("table", class_="infolist eventlist") as table: eventdetail += table tbody = Html("tbody") table += tbody evt_gid = event.get_gramps_id() if not self.noid and evt_gid: trow = Html("tr") + (Html("td", self._("Gramps ID"), class_="ColumnAttribute", inline=True), Html("td", evt_gid, class_="ColumnGRAMPSID", inline=True)) tbody += trow # get event data # # for more information: see get_event_data() # event_data = self.get_event_data(event, event_handle, subdirs, evt_gid) for (label, colclass, data) in event_data: if data: trow = Html("tr") + (Html( "td", label, class_="ColumnAttribute", inline=True ), Html('td', data, class_="Column" + colclass)) tbody += trow # Narrative subsection notelist = event.get_note_list() notelist = self.display_note_list(notelist) if notelist is not None: eventdetail += notelist # get attribute list attrlist = event.get_attribute_list() if attrlist: attrsection, attrtable = self.display_attribute_header() self.display_attr_list(attrlist, attrtable) eventdetail += attrsection # event source references srcrefs = self.display_ind_sources(event) if srcrefs is not None: eventdetail += srcrefs # display additional images as gallery if self.create_media: addgallery = self.disp_add_img_as_gallery( event_media_list, event) if addgallery: eventdetail += addgallery # References list ref_list = self.display_bkref_list(Event, event_handle) if ref_list is not None: eventdetail += ref_list # add clearline for proper styling # add footer section footer = self.write_footer(ldatec) body += (FULLCLEAR, footer) # send page out for processing # and close the page self.xhtml_writer(eventpage, output_file, sio, ldatec)
def placepage(self, report, title, place_handle): """ Create a place page @param: report -- The instance of the main report class for this report @param: title -- Is the title of the web page @param: place_handle -- The handle for the place to add """ place = report.database.get_place_from_handle(place_handle) if not place: return BasePage.__init__(self, report, title, place.get_gramps_id()) self.bibli = Bibliography() place_name = self.report.obj_dict[Place][place_handle][1] ldatec = place.get_change_time() output_file, sio = self.report.create_file(place_handle, "plc") self.uplink = True self.page_title = place_name (placepage, head, dummy_body, outerwrapper) = self.write_header(_("Places")) self.placemappages = self.report.options['placemappages'] self.mapservice = self.report.options['mapservice'] self.googlemapkey = self.report.options['googlemapkey'] self.stamenopts = self.report.options['stamenopts'] # begin PlaceDetail Division with Html("div", class_="content", id="PlaceDetail") as placedetail: outerwrapper += placedetail if self.create_media: media_list = place.get_media_list() thumbnail = self.disp_first_img_as_thumbnail(media_list, place) if thumbnail is not None: placedetail += thumbnail # add section title placedetail += Html("h3", html_escape(place_name), inline=True) # begin summaryarea division and places table with Html("div", id='summaryarea') as summaryarea: placedetail += summaryarea with Html("table", class_="infolist place") as table: summaryarea += table # list the place fields self.dump_place(place, table) # place gallery if self.create_media: placegallery = self.disp_add_img_as_gallery(media_list, place) if placegallery is not None: placedetail += placegallery # place notes notelist = self.display_note_list(place.get_note_list(), Place) if notelist is not None: placedetail += notelist # place urls urllinks = self.display_url_list(place.get_url_list()) if urllinks is not None: placedetail += urllinks # add place map here # Link to Gramps marker fname = "/".join(['images', 'marker.png']) marker_path = self.report.build_url_image("marker.png", "images", self.uplink) if self.placemappages: if place and (place.lat and place.long): placetitle = place_name # add narrative-maps CSS... 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 src_js = GOOGLE_MAPS + "api/js?sensor=false" if self.mapservice == "Google": if self.googlemapkey: src_js += "&key=" + self.googlemapkey head += Html("script", type="text/javascript", src=src_js, inline=True) else: # OpenStreetMap, Stamen... url = self.secure_mode url += ("maxcdn.bootstrapcdn.com/bootstrap/3.3.7/" "css/bootstrap.min.css") head += Html("link", href=url, type="text/javascript", rel="stylesheet") 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) src_js = "https://openlayers.org/en/latest/build/ol.js" head += Html("script", type="text/javascript", src=src_js, inline=True) url = "https://openlayers.org/en/latest/css/ol.css" head += Html("link", href=url, type="text/javascript", rel="stylesheet") src_js = self.secure_mode src_js += ("maxcdn.bootstrapcdn.com/bootstrap/3.3.7/" "js/bootstrap.min.js") head += Html("script", type="text/javascript", src=src_js, inline=True) # section title placedetail += Html("h4", self._("Place Map"), inline=True) # begin map_canvas division with Html("div", id="map_canvas", inline=True) as canvas: placedetail += canvas # add div for popups. if self.mapservice == "Google": with Html("div", id="popup", inline=True) as popup: placedetail += popup else: with Html("div", id="popup", class_="ol-popup", inline=True) as popup: placedetail += popup popup += Html("a", href="#", id="popup-closer", class_="ol-popup-closer") popup += Html("div", id="popup-title", class_="ol-popup-title") popup += Html("div", id="popup-content") with Html("div", id="tooltip", class_="ol-popup", inline=True) as tooltip: placedetail += tooltip tooltip += Html("div", id="tooltip-content") # source references srcrefs = self.display_ind_sources(place) if srcrefs is not None: placedetail += srcrefs # References list ref_list = self.display_bkref_list(Place, place_handle) if ref_list is not None: placedetail += ref_list # Begin inline javascript code because jsc is a # docstring, it does NOT have to be properly indented if self.placemappages: if place and (place.lat and place.long): latitude, longitude = conv_lat_lon(place.get_latitude(), place.get_longitude(), "D.D8") scripts = Html() if self.mapservice == "Google": with Html("script", type="text/javascript", indent=False) as jsc: scripts += jsc # Google adds Latitude/ Longitude to its maps... plce = placetitle.replace("'", "\\'") jsc += MARKER_PATH % marker_path jsc += MARKERS % ([[ plce, latitude, longitude, 1, "" ]], latitude, longitude, 10) elif self.mapservice == "OpenStreetMap": with Html("script", type="text/javascript") as jsc: scripts += jsc jsc += MARKER_PATH % marker_path jsc += OSM_MARKERS % ([[ float(longitude), float(latitude), placetitle, "" ]], longitude, latitude, 10) jsc += OPENLAYER else: # STAMEN with Html("script", type="text/javascript") as jsc: scripts += jsc jsc += MARKER_PATH % marker_path jsc += STAMEN_MARKERS % ([[ float(longitude), float(latitude), placetitle, "" ]], self.stamenopts, longitude, latitude, 10) jsc += OPENLAYER placedetail += scripts # add clearline for proper styling # add footer section footer = self.write_footer(ldatec) outerwrapper += (FULLCLEAR, footer) # send page out for processing # and close the file self.xhtml_writer(placepage, output_file, sio, ldatec)
def familypage(self, report, the_lang, the_title, family_handle): """ Create a family 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: family_handle -- The handle for the family to add """ family = report.database.get_family_from_handle(family_handle) if not family: return BasePage.__init__(self, report, the_lang, the_title, family.get_gramps_id()) ldatec = family.get_change_time() self.bibli = Bibliography() self.uplink = True family_name = self.report.get_family_name(family) self.page_title = family_name self.familymappages = report.options["familymappages"] output_file, sio = self.report.create_file(family.get_handle(), "fam") result = self.write_header(family_name) familydetailpage, dummy_head, dummy_body, outerwrapper = result # begin FamilyDetaill division with Html("div", class_="content", id="RelationshipDetail") as relationshipdetail: outerwrapper += relationshipdetail # family media list for initial thumbnail if self.create_media: media_list = family.get_media_list() # If Event pages are not being created, then we need to display # the family event media here if not self.inc_events: 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() relationshipdetail += Html( "h2", self.page_title, inline=True) + ( Html('sup') + (Html('small') + self.get_citation_links( family.get_citation_list()))) # Tags tags = self.show_tags(family) if tags and self.report.inc_tags: trow = Html("table", class_='tags') + (Html("tr") + ( Html("td", self._("Tags") + self._(":"), class_="ColumnAttribute", inline=True), Html("td", tags, class_="ColumnValue", inline=True), )) relationshipdetail += trow # display relationships families = self.display_family_relationships(family, None) if families is not None: relationshipdetail += families # display additional images as gallery if self.create_media and media_list: addgallery = self.disp_add_img_as_gallery(media_list, family) if addgallery: relationshipdetail += addgallery # Narrative subsection notelist = family.get_note_list() if notelist: relationshipdetail += self.display_note_list(notelist, Family) # display family LDS ordinance... family_lds_ordinance_list = family.get_lds_ord_list() if family_lds_ordinance_list: relationshipdetail += self.display_lds_ordinance(family) # get attribute list attrlist = family.get_attribute_list() if attrlist: attrsection, attrtable = self.display_attribute_header() self.display_attr_list(attrlist, attrtable) relationshipdetail += attrsection # for use in family map pages... if self.report.options["familymappages"]: name_format = self.report.options['name_format'] father = mother = None with self.create_toggle("map") as h4_head: relationshipdetail += h4_head h4_head += self._("Family Map") disp = "none" if self.report.options['toggle'] else "block" with Html("div", style="display:%s" % disp, id="toggle_map") as toggle: relationshipdetail += toggle mapdetail = Html("br") fhdle = family.get_father_handle() for handle, dummy_url in self.report.fam_link.items(): if fhdle == handle: father = self.r_db.get_person_from_handle(fhdle) break if father: primary_name = father.get_primary_name() name = Name(primary_name) name.set_display_as(name_format) fname = html_escape(_nd.display_name(name)) mapdetail += self.family_map_link_for_parent(fhdle, fname) mapdetail += Html("br") mhdle = family.get_mother_handle() for handle, dummy_url in self.report.fam_link.items(): if mhdle == handle: mother = self.r_db.get_person_from_handle(mhdle) break if mother: primary_name = mother.get_primary_name() name = Name(primary_name) name.set_display_as(name_format) mname = html_escape(_nd.display_name(name)) mapdetail += self.family_map_link_for_parent(mhdle, mname) toggle += mapdetail # source references srcrefs = self.display_ind_sources(family) if srcrefs: relationshipdetail += srcrefs # add clearline for proper styling # add footer section footer = self.write_footer(ldatec) outerwrapper += (FULLCLEAR, footer) # send page out for processing # and close the file self.xhtml_writer(familydetailpage, output_file, sio, ldatec)
def familypage(self, report, title, family_handle): """ Create a family page @param: report -- The instance of the main report class for this report @param: title -- Is the title of the web page @param: family_handle -- The handle for the family to add """ family = report.database.get_family_from_handle(family_handle) if not family: return BasePage.__init__(self, report, title, family.get_gramps_id()) ldatec = family.get_change_time() self.bibli = Bibliography() self.uplink = True family_name = self.report.get_family_name(family) self.page_title = family_name self.familymappages = report.options["familymappages"] output_file, sio = self.report.create_file(family.get_handle(), "fam") result = self.write_header(family_name) familydetailpage, dummy_head, dummy_body, outerwrapper = result # begin FamilyDetaill division with Html("div", class_="content", id="RelationshipDetail") as relationshipdetail: outerwrapper += relationshipdetail # family media list for initial thumbnail if self.create_media: media_list = family.get_media_list() # If Event pages are not being created, then we need to display # the family event media here if not self.inc_events: 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() relationshipdetail += Html("h2", self.page_title, inline=True) + ( Html('sup') + (Html('small') + self.get_citation_links(family.get_citation_list()))) # display relationships families = self.display_family_relationships(family, None) if families is not None: relationshipdetail += families # display additional images as gallery if self.create_media and media_list: addgallery = self.disp_add_img_as_gallery(media_list, family) if addgallery: relationshipdetail += addgallery # Narrative subsection notelist = family.get_note_list() if notelist: relationshipdetail += self.display_note_list(notelist) # display family LDS ordinance... family_lds_ordinance_list = family.get_lds_ord_list() if family_lds_ordinance_list: relationshipdetail += self.display_lds_ordinance(family) # get attribute list attrlist = family.get_attribute_list() if attrlist: attrsection, attrtable = self.display_attribute_header() self.display_attr_list(attrlist, attrtable) relationshipdetail += attrsection # source references srcrefs = self.display_ind_sources(family) if srcrefs: relationshipdetail += srcrefs # add clearline for proper styling # add footer section footer = self.write_footer(ldatec) outerwrapper += (FULLCLEAR, footer) # send page out for processing # and close the file self.xhtml_writer(familydetailpage, output_file, sio, ldatec)
def mediapage(self, report, title, media_handle, info): """ Generate and output an individual Media page. @param: report -- The instance of the main report class for this report @param: title -- Is the title of the web page @param: media_handle -- The media handle to use @param: info -- A tuple containing the media handle for the next and previous media, the current page number, and the total number of media pages """ media = report.database.get_media_from_handle(media_handle) BasePage.__init__(self, report, title, media.gramps_id) (prev, next_, page_number, total_pages) = info ldatec = media.get_change_time() # get media rectangles _region_items = self.media_ref_rect_regions(media_handle) output_file, sio = self.report.create_file(media_handle, "img") self.uplink = True self.bibli = Bibliography() # get media type to be used primarily with "img" tags mime_type = media.get_mime_type() if mime_type: newpath = self.copy_source_file(media_handle, media) target_exists = newpath is not None else: target_exists = False self.copy_thumbnail(media_handle, media) self.page_title = media.get_description() esc_page_title = html_escape(self.page_title) result = self.write_header("%s - %s" % (self._("Media"), self.page_title)) mediapage, head, dummy_body, outerwrapper = result # if there are media rectangle regions, attach behaviour style sheet if _region_items: fname = "/".join(["css", "behaviour.css"]) url = self.report.build_url_fname(fname, None, self.uplink) head += Html("link", href=url, type="text/css", media="screen", rel="stylesheet") # begin MediaDetail division with Html("div", class_="content", id="GalleryDetail") as mediadetail: outerwrapper += mediadetail # media navigation with Html("div", id="GalleryNav", role="navigation") as medianav: mediadetail += medianav if prev: medianav += self.media_nav_link(prev, self._("Previous"), True) data = self._( '%(strong1_strt)s%(page_number)d%(strong_end)s ' 'of %(strong2_strt)s%(total_pages)d%(strong_end)s') % { 'strong1_strt': '<strong id="GalleryCurrent">', 'strong2_strt': '<strong id="GalleryTotal">', 'strong_end': '</strong>', 'page_number': page_number, 'total_pages': total_pages } medianav += Html("span", data, id="GalleryPages") if next_: medianav += self.media_nav_link(next_, self._("Next"), True) # missing media error message errormsg = self._("The file has been moved or deleted.") # begin summaryarea division with Html("div", id="summaryarea") as summaryarea: mediadetail += summaryarea if mime_type: if mime_type.startswith("image"): if not target_exists: with Html("div", id="MediaDisplay") as mediadisplay: summaryarea += mediadisplay mediadisplay += Html("span", errormsg, class_="MissingImage") else: # Check how big the image is relative to the # requested 'initial' image size. # If it's significantly bigger, scale it down to # improve the site's responsiveness. We don't want # the user to have to await a large download # unnecessarily. Either way, set the display image # size as requested. orig_image_path = media_path_full( self.r_db, media.get_path()) (width, height) = image_size(orig_image_path) max_width = self.report.options[ 'maxinitialimagewidth'] # TODO. Convert disk path to URL. url = self.report.build_url_fname( orig_image_path, None, self.uplink) with Html("div", id="GalleryDisplay", style='max-width: %dpx; height: auto' % (max_width)) as mediadisplay: summaryarea += mediadisplay # Feature #2634; display the mouse-selectable # regions. See the large block at the top of # this function where the various regions are # stored in _region_items if _region_items: ordered = Html("ol", class_="RegionBox") mediadisplay += ordered while _region_items: (name, coord_x, coord_y, width, height, linkurl) = _region_items.pop() ordered += Html( "li", style="left:%d%%; " "top:%d%%; " "width:%d%%; " "height:%d%%;" % (coord_x, coord_y, width, height) ) + (Html("a", name, href=linkurl)) # display the image if orig_image_path != newpath: url = self.report.build_url_fname( newpath, None, self.uplink) s_width = 'width: %dpx;' % max_width mediadisplay += Html("a", href=url) + (Html( "img", src=url, style=s_width, alt=esc_page_title)) else: dirname = tempfile.mkdtemp() thmb_path = os.path.join(dirname, "document.png") if run_thumbnailer( mime_type, media_path_full(self.r_db, media.get_path()), thmb_path, 320): try: path = self.report.build_path( "preview", media.get_handle()) npath = os.path.join(path, media.get_handle()) npath += ".png" self.report.copy_file(thmb_path, npath) path = npath os.unlink(thmb_path) except EnvironmentError: path = os.path.join("images", "document.png") else: path = os.path.join("images", "document.png") os.rmdir(dirname) with Html("div", id="GalleryDisplay") as mediadisplay: summaryarea += mediadisplay img_url = self.report.build_url_fname( path, None, self.uplink) if target_exists: # TODO. Convert disk path to URL url = self.report.build_url_fname( newpath, None, self.uplink) s_width = 'width: 48px;' hyper = Html( "a", href=url, title=esc_page_title) + ( Html("img", src=img_url, style=s_width, alt=esc_page_title)) mediadisplay += hyper else: mediadisplay += Html("span", errormsg, class_="MissingImage") else: with Html("div", id="GalleryDisplay") as mediadisplay: summaryarea += mediadisplay url = self.report.build_url_image( "document.png", "images", self.uplink) s_width = 'width: 48px;' mediadisplay += Html("img", src=url, style=s_width, alt=esc_page_title, title=esc_page_title) # media title title = Html("h3", html_escape(self.page_title.strip()), inline=True) summaryarea += title # begin media table with Html("table", class_="infolist gallery") as table: summaryarea += table # Gramps ID media_gid = media.gramps_id if not self.noid and media_gid: trow = Html("tr") + (Html("td", self._("Gramps ID"), class_="ColumnAttribute", inline=True), Html("td", media_gid, class_="ColumnValue", inline=True)) table += trow # mime type if mime_type: trow = Html("tr") + (Html("td", self._("File Type"), class_="ColumnAttribute", inline=True), Html("td", mime_type, class_="ColumnValue", inline=True)) table += trow # media date date = media.get_date_object() if date and date is not Date.EMPTY: trow = Html("tr") + (Html("td", self._("Date"), class_="ColumnAttribute", inline=True), Html("td", self.rlocale.get_date(date), class_="ColumnValue", inline=True)) table += trow # get media notes notelist = self.display_note_list(media.get_note_list(), Media) if notelist is not None: mediadetail += notelist # get attribute list attrlist = media.get_attribute_list() if attrlist: attrsection, attrtable = self.display_attribute_header() self.display_attr_list(attrlist, attrtable) mediadetail += attrsection # get media sources srclist = self.display_media_sources(media) if srclist is not None: mediadetail += srclist # get media references reflist = self.display_bkref_list(Media, media_handle) if reflist is not None: mediadetail += reflist # add clearline for proper styling # add footer section footer = self.write_footer(ldatec) outerwrapper += (FULLCLEAR, footer) # send page out for processing # and close the file self.xhtml_writer(mediapage, output_file, sio, ldatec)
def placepage(self, report, the_lang, the_title, place_handle, place_name): """ Create a place 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: place_handle -- The handle for the place to add @param: place_name -- The alternate place name """ place = report.database.get_place_from_handle(place_handle) if not place: return BasePage.__init__(self, report, the_lang, the_title, place.get_gramps_id()) self.bibli = Bibliography() ldatec = place.get_change_time() apname = _pd.display(self.r_db, place) if place_name == apname: # store only the primary named page output_file, sio = self.report.create_file(place_handle, "plc") self.uplink = True self.page_title = place_name (placepage, head, dummy_body, outerwrapper) = self.write_header(_("Places")) self.placemappages = self.report.options['placemappages'] self.mapservice = self.report.options['mapservice'] self.googlemapkey = self.report.options['googlemapkey'] self.stamenopts = self.report.options['stamenopts'] # begin PlaceDetail Division with Html("div", class_="content", id="PlaceDetail") as placedetail: outerwrapper += placedetail media_list = place.get_media_list() if self.create_media: thumbnail = self.disp_first_img_as_thumbnail(media_list, place) if thumbnail is not None: if media_list[0].ref in self.report.obj_dict[Media]: placedetail += thumbnail # add section title placedetail += Html("h3", html_escape(place_name), inline=True) # begin summaryarea division and places table with Html("div", id='summaryarea') as summaryarea: placedetail += summaryarea with Html("table", class_="infolist place") as table: summaryarea += table # list the place fields self.dump_place(place, table) # place gallery if self.create_media and not self.report.options['inc_uplaces']: # Don't diplay media for unused places. It generates # "page not found" if they are not collected in pass 1. placegallery = self.disp_add_img_as_gallery(media_list, place) if placegallery is not None: placedetail += placegallery # place notes notelist = self.display_note_list(place.get_note_list(), Place) if notelist is not None: placedetail += notelist # place urls urllinks = self.display_url_list(place.get_url_list()) if urllinks is not None: placedetail += urllinks # add place map here # Link to Gramps marker fname = "/".join(['images', 'marker.png']) marker_path = self.report.build_url_image("marker.png", "images", self.uplink) if self.placemappages: if place and (place.lat and place.long): placetitle = place_name # add narrative-maps CSS... if 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 src_js = GOOGLE_MAPS + "api/js" if self.mapservice == "Google": 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) src_js = "https://openlayers.org/en/latest/build/ol.js" head += Html("script", type="text/javascript", src=src_js, inline=True) url = "https://openlayers.org/en/latest/css/ol.css" head += Html("link", href=url, type="text/css", rel="stylesheet") # section title placedetail += Html("h4", self._("Place Map"), inline=True) # begin map_canvas division with Html("div", id="map_canvas", inline=True) as canvas: placedetail += canvas # add div for popups. if self.mapservice == "Google": with Html("div", id="popup", inline=True) as popup: placedetail += popup else: with Html("div", id="popup", class_="ol-popup", inline=True) as popup: placedetail += popup popup += Html("a", href="#", id="popup-closer", class_="ol-popup-closer") popup += Html("div", id="popup-title", class_="ol-popup-title") popup += Html("div", id="popup-content") with Html("div", id="tooltip", class_="ol-popup", inline=True) as tooltip: placedetail += tooltip tooltip += Html("div", id="tooltip-content") # source references if not self.report.options['inc_uplaces']: # We can't display source reference when we display # unused places. These info are not in the collected objects. # This is to avoid "page not found" errors. srcrefs = self.display_ind_sources(place) if srcrefs is not None: placedetail += srcrefs # References list ref_list = self.display_bkref_list(Place, place_handle) if ref_list is not None: placedetail += ref_list # Begin inline javascript code because jsc is a # docstring, it does NOT have to be properly indented if self.placemappages: if place and (place.lat and place.long): latitude, longitude = conv_lat_lon(place.get_latitude(), place.get_longitude(), "D.D8") tracelife = " " if self.create_media and media_list: for fmedia in media_list: photo_hdle = fmedia.get_reference_handle() photo = self.r_db.get_media_from_handle(photo_hdle) mime_type = photo.get_mime_type() descr = photo.get_description() if mime_type and is_image_type(mime_type): uplnk = self.uplink (pth, dummy_) = self.report.prepare_copy_media(photo) srbuf = self.report.build_url_fname newpath = srbuf(pth, image=True, uplink=uplnk) imglnk = self.media_link(photo_hdle, newpath, descr, uplink=uplnk, usedescr=False) if photo_hdle in self.report.obj_dict[Media]: tracelife += str(imglnk) break # We show only the first image scripts = Html() if self.mapservice == "Google": with Html("script", type="text/javascript", indent=False) as jsc: scripts += jsc # Google adds Latitude/ Longitude to its maps... plce = placetitle.replace("'", "\\'") jsc += MARKER_PATH % marker_path jsc += MARKERS % ([[plce, latitude, longitude, 1, tracelife]], latitude, longitude, 10) elif self.mapservice == "OpenStreetMap": with Html("script", type="text/javascript") as jsc: scripts += jsc jsc += MARKER_PATH % marker_path jsc += OSM_MARKERS % ([[float(longitude), float(latitude), placetitle, tracelife]], longitude, latitude, 10) jsc += OPENLAYER else: # STAMEN with Html("script", type="text/javascript") as jsc: scripts += jsc jsc += MARKER_PATH % marker_path jsc += STAMEN_MARKERS % ([[float(longitude), float(latitude), placetitle, tracelife]], self.stamenopts, longitude, latitude, 10) jsc += OPENLAYER placedetail += scripts # add clearline for proper styling # add footer section footer = self.write_footer(ldatec) outerwrapper += (FULLCLEAR, footer) # send page out for processing # and close the file if place_name == apname: # store only the primary named page self.xhtml_writer(placepage, output_file, sio, ldatec)