def surname_link(self, fname, name, opt_val=None, uplink=False): """ Create a link to the surname page. @param: fname -- Path to the file name @param: name -- Name to see in the link @param: opt_val -- Option value to use @param: uplink -- If True, then "../../../" is inserted in front of the result. """ url = self.report.build_url_fname_html(fname, "srn", uplink) try: # some characters don't have a unicode name char = uniname(name[0]) except (ValueError, TypeError) as dummy_err: char = " " hyper = Html("a", html_escape(name), href=url, title="%s starting with %s" % (name, char), inline=True) if opt_val is not None: hyper += opt_val # return hyperlink to its caller return hyper
def media_nav_link(self, handle, name, uplink=False): """ Creates the Media Page Navigation hyperlinks for Next and Prev """ url = self.report.build_url_fname_html(handle, "img", uplink) name = html_escape(name) return Html("a", name, name=name, id=name, href=url, title=name, inline=True)
def thumbnail_link(self, name, index): """ creates a hyperlink for Thumbnail Preview Reference... @param: name -- The image description @param: index -- The image index """ return Html("a", index, title=html_escape(name), href="#%d" % index)
def media_nav_link(self, handle, name, uplink=False): """ Creates the Media Page Navigation hyperlinks for Next and Prev @param: handle -- The media handle @param: name -- The name to use for the link @param: uplink -- If True, then "../../../" is inserted in front of the result. """ url = self.report.build_url_fname_html(handle, "img", uplink) name = html_escape(name) return Html("a", name, name=name, id=name, href=url, title=name, inline=True)
def surname_link(self, fname, name, opt_val=None, uplink=False): """ Create a link to the surname page. @param: fname -- Path to the file name @param: name -- Name to see in the link @param: opt_val -- Option value to use @param: uplink -- If True, then "../../../" is inserted in front of the result. """ url = self.report.build_url_fname_html(fname, "srn", uplink) hyper = Html("a", html_escape(name), href=url, title=name, inline=True) if opt_val is not None: hyper += opt_val # return hyperlink to its caller return hyper
def thumb_hyper_image(self, thumbnail_url, subdir, fname, name): """ eplaces media_link() because it doesn't work for this instance """ name = html_escape(name) url = "/".join(self.report.build_subdirs(subdir, fname) + [fname]) + self.ext with Html("div", class_="thumbnail") as thumbnail: #snapshot += thumbnail if not self.create_thumbs_only: thumbnail_link = Html("a", href=url, title=name) + (Html( "img", src=thumbnail_url, alt=name)) else: thumbnail_link = Html("img", src=thumbnail_url, alt=name) thumbnail += thumbnail_link return thumbnail
def media_ref_link(self, handle, name, uplink=False): """ Create a reference link to a media @param: handle -- The media handle @param: name -- The name to use for the link @param: uplink -- If True, then "../../../" is inserted in front of the result. """ # get media url url = self.report.build_url_fname_html(handle, "img", uplink) # get name name = html_escape(name) # begin hyper link hyper = Html("a", name, href=url, title=name) # return hyperlink to its callers return hyper
def thumb_hyper_image(self, thumbnail_url, subdir, fname, name): """ eplaces media_link() because it doesn't work for this instance """ name = html_escape(name) url = "/".join(self.report.build_subdirs(subdir, fname) + [fname]) + self.ext with Html("div", class_="content", id="ThumbnailPreview") as section: with Html("div", class_="snapshot") as snapshot: section += snapshot with Html("div", class_="thumbnail") as thumbnail: snapshot += thumbnail if not self.create_thumbs_only: thumbnail_link = Html("a", href=url, title=name) + ( Html("img", src=thumbnail_url, alt=name) ) else: thumbnail_link = Html("img", src=thumbnail_url, alt=name) thumbnail += thumbnail_link return section
def thumb_hyper_image(self, thumbnail_url, subdir, fname, name): """ replaces media_link() because it doesn't work for this instance @param: thumnail_url -- The url for this thumbnail @param: subdir -- The subdir prefix to add @param: fname -- The file name for this image @param: name -- The image description """ name = html_escape(name) url = "/".join(self.report.build_subdirs(subdir, fname) + [fname]) + self.ext with Html("div", class_="thumbnail") as thumbnail: #snapshot += thumbnail if not self.create_thumbs_only: thumbnail_link = Html("a", href=url, title=name) + ( Html("img", src=thumbnail_url, alt=name) ) else: thumbnail_link = Html("img", src=thumbnail_url, alt=name) thumbnail += thumbnail_link return thumbnail
def __init__(self, report, title, surname, ppl_handle_list): """ @param: report -- The instance of the main report class for this report @param: title -- Is the title of the web page @param: surname -- The surname to use @param: ppl_handle_list -- The list of people for whom we need to create a page. """ BasePage.__init__(self, report, title) # module variables showbirth = report.options['showbirth'] showdeath = report.options['showdeath'] showpartner = report.options['showpartner'] showparents = report.options['showparents'] if surname == '': surname = self._("<absent>") output_file, sio = self.report.create_file(name_to_md5(surname), "srn") self.uplink = True (surnamepage, head, body) = self.write_header("%s - %s" % (self._("Surname"), surname)) ldatec = 0 # begin SurnameDetail division with Html("div", class_="content", id="SurnameDetail") as surnamedetail: body += surnamedetail # section title surnamedetail += Html("h3", html_escape(surname), inline=True) # feature request 2356: avoid genitive form msg = self._("This page contains an index of all the individuals " "in the database with the surname of %s. " "Selecting the person’s name " "will take you to that person’s " "individual page.") % html_escape(surname) surnamedetail += Html("p", msg, id="description") # begin surname table and thead with Html("table", class_="infolist primobjlist surname") as table: surnamedetail += table thead = Html("thead") table += thead trow = Html("tr") thead += trow # Name Column trow += Html("th", self._("Given 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) # begin table body tbody = Html("tbody") table += tbody for person_handle in sorted(ppl_handle_list, key=self.sort_on_name_and_grampsid): person = self.r_db.get_person_from_handle(person_handle) if person.get_change_time() > ldatec: ldatec = person.get_change_time() trow = Html("tr") tbody += trow # firstname column link = self.new_person_link(person_handle, uplink=True, person=person, name_style=_NAME_STYLE_FIRST) 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: tcell = Html("td", class_="ColumnPartner") trow += tcell family_list = person.get_family_handle_list() if family_list: fam_count = 0 for family_handle in family_list: fam_count += 1 family = self.r_db.get_family_from_handle( family_handle) partner_handle = utils.find_spouse( person, family) if partner_handle: link = self.new_person_link(partner_handle, uplink=True) if fam_count < len(family_list): if isinstance(link, Html): link.inside += "," else: link += ',' tcell += link else: tcell += " " # parents column if showparents: parent_hdl_list = person.get_parent_family_handle_list() if parent_hdl_list: parent_hdl = parent_hdl_list[0] fam = self.r_db.get_family_from_handle(parent_hdl) f_id = fam.get_father_handle() m_id = fam.get_mother_handle() mother = father = None if f_id: father = self.r_db.get_person_from_handle(f_id) if father: father_name = self.get_name(father) if m_id: mother = self.r_db.get_person_from_handle(m_id) if mother: mother_name = self.get_name(mother) if mother and father: tcell = Html("span", father_name, class_="father fatherNmother") tcell += Html("span", mother_name, class_="mother") elif mother: tcell = Html("span", mother_name, class_="mother", inline=True) elif father: tcell = Html("span", father_name, class_="father", inline=True) samerow = False else: tcell = " " # pylint: disable=R0204 samerow = True trow += Html("td", tcell, class_="ColumnParents", inline=samerow) # add clearline for proper styling # add footer section footer = self.write_footer(ldatec) body += (FULLCLEAR, footer) # send page out for processing # and close the file self.xhtml_writer(surnamepage, output_file, sio, ldatec)
def __init__(self, report, title): """ @param: report -- The instance of the main report class for this report @param: title -- Is the title of the web page """ BasePage.__init__(self, report, title) # do NOT include a Download Page if not self.report.inc_download: return # menu options for class # download and description #n ( 1 <= n < 5 ) dlfname = self.report.dl_fname dldescr = self.report.dl_descr # if no filenames at all, return??? if dlfname: output_file, sio = self.report.create_file("download") result = self.write_header(self._('Download')) downloadpage, dummy_head, dummy_body, outerwrapper = result # begin download page and table with Html("div", class_="content", id="Download") as download: outerwrapper += download msg = self._("This page is for the user/ creator " "of this Family Tree/ Narrative website " "to share a couple of files with you " "regarding their family. If there are " "any files listed " "below, clicking on them will allow you " "to download them. The " "download page and files have the same " "copyright as the remainder " "of these web pages.") download += Html("p", msg, id="description") # begin download table and table head with Html("table", class_="infolist download") as table: download += table thead = Html("thead") table += thead trow = Html("tr") thead += trow trow.extend( Html("th", label, class_="Column" + colclass, inline=True) for (label, colclass) in [( self._("File Name"), "Filename"), ( self._("Description"), "Description" ), (self._("Last Modified"), "Modified"), (self._("MD5"), "Md5")]) # table body tbody = Html("tbody") table += tbody dwnld = 0 for fnamex in dlfname: # if fnamex is not None, do we have a file to download? if fnamex: fname = os.path.basename(dlfname[fnamex]) # if fname is not None, show it if fname: dwnld += 1 trow = Html("tr", id='Row01') tbody += trow dldescrx = dldescr[fnamex] tcell = Html("td", class_="ColumnFilename") + ( Html("a", fname, href=fname, title=html_escape(dldescrx))) trow += tcell dldescr1 = dldescrx or " " trow += Html("td", dldescr1, inline=True, class_="ColumnDescription") tcell = Html("td", class_="ColumnModified", inline=True) trow += tcell if os.path.exists(dlfname[fnamex]): md5 = create_checksum(dlfname[fnamex]) trow += Html("td", md5, class_="ColumnMd5", inline=True) modified = os.stat( dlfname[fnamex]).st_mtime last_mod = datetime.datetime.fromtimestamp( modified) tcell += last_mod # copy the file self.report.copy_file( dlfname[fnamex], fname) else: tcell += self._("Cannot open file") if not dwnld: # We have several files to download # but all file names are empty dldescrx = _("No file to download") trow = Html("tr", id='Row01') tbody += trow tcell = Html("td", class_="ColumnFilename", colspan=3) + Html("h2", dldescrx) trow += tcell # clear line for proper styling # create footer section footer = self.write_footer(None) outerwrapper += (FULLCLEAR, footer) # send page out for processing # and close the file self.xhtml_writer(downloadpage, output_file, sio, 0)
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)
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, 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 None 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, body = self.write_header(_("Places")) self.placemappages = self.report.options['placemappages'] self.mapservice = self.report.options['mapservice'] self.googlemapkey = self.report.options['googlemapkey'] # begin PlaceDetail Division with Html("div", class_="content", id="PlaceDetail") as placedetail: body += 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()) 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): latitude, longitude = conv_lat_lon(place.get_latitude(), place.get_longitude(), "D.D8") 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: 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 = self.secure_mode src_js += "openlayers.org/en/v3.17.1/build/ol.js" head += Html("script", type="text/javascript", src=src_js, inline=True) url = self.secure_mode url += "openlayers.org/en/v3.17.1/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 # Begin inline javascript code because jsc is a # docstring, it does NOT have to be properly indented if self.mapservice == "Google": with Html("script", type="text/javascript", indent=False) as jsc: head += 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) else: # OpenStreetMap (OSM) adds Longitude/ Latitude # to its maps, and needs a country code in # lowercase letters... with Html("script", type="text/javascript") as jsc: canvas += jsc #param1 = xml_lang()[3:5].lower() jsc += MARKER_PATH % marker_path jsc += OSM_MARKERS % ([[float(longitude), float(latitude), placetitle]], longitude, latitude, 10) # add javascript function call to body element body.attr += ' onload = "initialize();" ' # add div for popups. with Html("div", id="popup", inline=True) as popup: placedetail += popup # 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 # add clearline for proper styling # add footer section footer = self.write_footer(ldatec) body += (FULLCLEAR, footer) # send page out for processing # and close the file self.xhtml_writer(placepage, output_file, sio, ldatec)
def sourcepage(self, report, title, source_handle): """ Generate and output an individual Source page. @param: report -- The instance of the main report class for this report @param: title -- Is the title of the web page @param: source_handle -- The handle of the source to be output """ source = report.database.get_source_from_handle(source_handle) BasePage.__init__(self, report, title, source.get_gramps_id()) if not source: return self.page_title = source.get_title() inc_repositories = self.report.options["inc_repository"] self.navigation = self.report.options['navigation'] self.citationreferents = self.report.options['citationreferents'] output_file, sio = self.report.create_file(source_handle, "src") self.uplink = True sourcepage, head, body = self.write_header( "%s - %s" % (self._('Sources'), self.page_title)) ldatec = 0 # begin source detail division with Html("div", class_="content", id="SourceDetail") as sourcedetail: body += sourcedetail media_list = source.get_media_list() if self.create_media and media_list: thumbnail = self.disp_first_img_as_thumbnail(media_list, source) if thumbnail is not None: sourcedetail += thumbnail # add section title sourcedetail += Html("h3", html_escape(source.get_title()), inline=True) # begin sources table with Html("table", class_="infolist source") as table: sourcedetail += table tbody = Html("tbody") table += tbody source_gid = False if not self.noid and self.gid: source_gid = source.get_gramps_id() # last modification of this source ldatec = source.get_change_time() for (label, value) in [(self._("Gramps ID"), source_gid), (self._("Author"), source.get_author()), (self._("Abbreviation"), source.get_abbreviation()), (self._("Publication information"), source.get_publication_info())]: if value: trow = Html("tr") + ( Html("td", label, class_="ColumnAttribute", inline=True), Html("td", value, class_="ColumnValue", inline=True) ) tbody += trow # Source notes notelist = self.display_note_list(source.get_note_list()) if notelist is not None: sourcedetail += notelist # additional media from Source (if any?) if self.create_media and media_list: sourcemedia = self.disp_add_img_as_gallery(media_list, source) if sourcemedia is not None: sourcedetail += sourcemedia # Source Data Map... src_data_map = self.write_srcattr(source.get_attribute_list()) if src_data_map is not None: sourcedetail += src_data_map # Source Repository list if inc_repositories: repo_list = self.dump_repository_ref_list( source.get_reporef_list()) if repo_list is not None: sourcedetail += repo_list # Source references list ref_list = self.display_bkref_list(Source, source_handle) if ref_list is not None: sourcedetail += 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 file self.xhtml_writer(sourcepage, output_file, sio, ldatec)
def thumbnail_link(self, name, index): """ creates a hyperlink for Thumbnail Preview Reference... """ return Html("a", index, title=html_escape(name), href="#%d" % index)
def sourcepage(self, report, the_lang, the_title, source_handle): """ Generate and output an individual Source 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: source_handle -- The handle of the source to be output """ source = report.database.get_source_from_handle(source_handle) BasePage.__init__(self, report, the_lang, the_title, source.get_gramps_id()) if not source: return self.page_title = source.get_title() inc_repositories = self.report.options["inc_repository"] self.navigation = self.report.options['navigation'] self.citationreferents = self.report.options['citationreferents'] output_file, sio = self.report.create_file(source_handle, "src") self.uplink = True result = self.write_header("%s - %s" % (self._('Sources'), self.page_title)) sourcepage, dummy_head, dummy_body, outerwrapper = result ldatec = 0 # begin source detail division with Html("div", class_="content", id="SourceDetail") as sourcedetail: outerwrapper += sourcedetail media_list = source.get_media_list() if self.create_media and media_list: thumbnail = self.disp_first_img_as_thumbnail(media_list, source) if thumbnail is not None: sourcedetail += thumbnail # add section title sourcedetail += Html("h3", html_escape(source.get_title()), inline=True) # begin sources table with Html("table", class_="infolist source") as table: sourcedetail += table tbody = Html("tbody") table += tbody source_gid = False if not self.noid and self.gid: source_gid = source.get_gramps_id() # last modification of this source ldatec = source.get_change_time() for (label, value) in [(self._("Gramps ID"), source_gid), (self._("Author"), source.get_author()), (self._("Abbreviation"), source.get_abbreviation()), (self._("Publication information"), source.get_publication_info())]: if value: trow = Html("tr") + ( Html("td", label, class_="ColumnAttribute", inline=True), Html("td", value, class_="ColumnValue", inline=True) ) tbody += trow # Tags tags = self.show_tags(source) if tags and self.report.inc_tags: trow = Html("tr") + ( Html("td", self._("Tags"), class_="ColumnAttribute", inline=True), Html("td", tags, class_="ColumnValue", inline=True) ) tbody += trow # Source notes notelist = self.display_note_list(source.get_note_list(), Source) if notelist is not None: sourcedetail += notelist # additional media from Source (if any?) if self.create_media and media_list: sourcemedia = self.disp_add_img_as_gallery(media_list, source) if sourcemedia is not None: sourcedetail += sourcemedia # Source Data Map... src_data_map = self.write_srcattr(source.get_attribute_list()) if src_data_map is not None: sourcedetail += src_data_map # Source Repository list if inc_repositories: repo_list = self.dump_repository_ref_list( source.get_reporef_list()) if repo_list is not None: sourcedetail += repo_list # Source references list ref_list = self.display_bkref_list(Source, source_handle) if ref_list is not None: sourcedetail += ref_list # 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(sourcepage, 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, 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'] fhandle = mhandle = father = mother = None relationshipdetail += Html("h4", _("Family map"), inline=True) mapdetail = Html("br") fhandle = family.get_father_handle() for handle, dummy_url in self.report.fam_link.items(): if fhandle == handle: father = self.r_db.get_person_from_handle(fhandle) 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(fhandle, fname) mapdetail += Html("br") mhandle = family.get_mother_handle() for handle, dummy_url in self.report.fam_link.items(): if mhandle == handle: mother = self.r_db.get_person_from_handle(mhandle) 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(mhandle, mname) relationshipdetail += 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 list_notes(self): """ List all notes with last change date """ nb_items = 0 section = "" def sort_on_change(handle): """ sort records based on the last change time """ fct = self.report.database.get_note_from_handle obj = fct(handle) timestamp = obj.get_change_time() return timestamp note_list = self.report.database.get_note_handles() obj_list = sorted(note_list, key=sort_on_change, reverse=True) with Html("table", class_="list", id="list") as section: for handle in obj_list: show = False date = obj = None obj = self.report.database.get_note_from_handle(handle) if obj: text = html_escape(obj.get()[:50]) timestamp = obj.get_change_time() if timestamp - self.maxdays > 0: handle_list = set( self.report.database.find_backlink_handles( handle, include_classes=['Person', 'Family', 'Event', 'Place', 'Media', 'Source', 'Citation', 'Repository', ])) tims = localtime(timestamp) odat = Date(tims.tm_year, tims.tm_mon, tims.tm_mday) date = self.rlocale.date_displayer.display(odat) date += strftime(' %X', tims) if handle_list: srbd = self.report.database srbkref = self.report.bkref_dict for obj_t, r_handle in handle_list: if obj_t == 'Person': if r_handle in srbkref[Person]: name = self.new_person_link(r_handle) show = True elif obj_t == 'Family': if r_handle in srbkref[Family]: fam = srbd.get_family_from_handle( r_handle) fam = self._("Family") name = self.family_link(r_handle, fam) if self.inc_families: show = True elif obj_t == 'Place': if r_handle in srbkref[Place]: plc = srbd.get_place_from_handle( r_handle) plcn = _pd.display(self.report.database, plc) name = self.place_link(r_handle, plcn) if self.inc_places: show = True elif obj_t == 'Event': if r_handle in srbkref[Event]: evt = srbd.get_event_from_handle( r_handle) evtn = self._(evt.get_type().xml_str()) name = self.event_link(r_handle, evtn) if self.inc_events: show = True elif obj_t == 'Media': if r_handle in srbkref[Media]: media = srbd.get_media_from_handle( r_handle) evtn = media.get_description() name = self.media_link(r_handle, evtn, evtn, usedescr=False) if self.inc_gallery: show = True elif obj_t == 'Citation': if r_handle in srbkref[Citation]: cit = srbd.get_event_from_handle( r_handle) citsrc = cit.source_handle evtn = self._("Citation") name = self.source_link(citsrc, evtn) if self.inc_sources: show = True elif obj_t == 'Source': if r_handle in srbkref[Source]: src = srbd.get_source_from_handle( r_handle) evtn = src.get_title() name = self.source_link(r_handle, evtn) if self.inc_sources: show = True elif obj_t == 'Repository': if r_handle in srbkref[Repository]: rep = srbd.get_repository_from_handle( r_handle) evtn = rep.get_name() name = self.repository_link(r_handle, evtn) if self.inc_repository: show = True if show: row = Html("tr") section += row row += Html("td", date, class_="date") row += Html("td", text) row += Html("td", name) nb_items += 1 if nb_items > self.nbr: break return section
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() #mtype = get_description(mime_type) if mime_type: #note_only = False newpath = self.copy_source_file(media_handle, media) target_exists = newpath is not None else: #note_only = True target_exists = False self.copy_thumbnail(media_handle, media) self.page_title = media.get_description() esc_page_title = html_escape(self.page_title) (mediapage, head, body) = self.write_header("%s - %s" % (self._("Media"), self.page_title)) # 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: body += 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()) #mtime = os.stat(orig_image_path).st_mtime (width, height) = image_size(orig_image_path) max_width = self.report.options[ 'maxinitialimagewidth'] max_height = self.report.options[ 'maxinitialimageheight'] if width != 0 and height != 0: scale_w = (float(max_width)/width) or 1 # the 'or 1' is so that a max of # zero is ignored scale_h = (float(max_height)/height) or 1 else: scale_w = 1.0 scale_h = 1.0 scale = min(scale_w, scale_h, 1.0) new_width = int(width*scale) new_height = int(height*scale) # TODO. Convert disk path to URL. url = self.report.build_url_fname(orig_image_path, None, self.uplink) with Html("div", id="GalleryDisplay", style='width: %dpx; height: %dpx' % ( new_width, new_height)) 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 len(_region_items) > 0: (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) mediadisplay += Html("a", href=url) + ( Html("img", width=new_width, height=new_height, src=url, 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) hyper = Html("a", href=url, title=esc_page_title) + ( Html("img", src=img_url, 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) mediadisplay += Html("img", src=url, 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()) 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) body += (FULLCLEAR, footer) # send page out for processing # and close the file self.xhtml_writer(mediapage, output_file, sio, ldatec)
def __init__(self, report, title): """ @param: report -- The instance of the main report class for this report @param: title -- Is the title of the web page """ BasePage.__init__(self, report, title) # do NOT include a Download Page if not self.report.inc_download: return # menu options for class # download and description #1 dlfname1 = self.report.dl_fname1 dldescr1 = self.report.dl_descr1 # download and description #2 dlfname2 = self.report.dl_fname2 dldescr2 = self.report.dl_descr2 # if no filenames at all, return??? if dlfname1 or dlfname2: output_file, sio = self.report.create_file("download") downloadpage, head, body = self.write_header(self._('Download')) # begin download page and table with Html("div", class_="content", id="Download") as download: body += download msg = self._("This page is for the user/ creator " "of this Family Tree/ Narrative website " "to share a couple of files with you " "regarding their family. If there are " "any files listed " "below, clicking on them will allow you " "to download them. The " "download page and files have the same " "copyright as the remainder " "of these web pages.") download += Html("p", msg, id="description") # begin download table and table head with Html("table", class_="infolist download") as table: download += table thead = Html("thead") table += thead trow = Html("tr") thead += trow trow.extend( Html("th", label, class_="Column" + colclass, inline=True) for (label, colclass) in [ (self._("File Name"), "Filename"), (self._("Description"), "Description"), (self._("Last Modified"), "Modified")]) # table body tbody = Html("tbody") table += tbody # if dlfname1 is not None, show it??? if dlfname1: trow = Html("tr", id='Row01') tbody += trow fname = os.path.basename(dlfname1) # TODO dlfname1 is filename, convert disk path to URL tcell = Html("td", class_="ColumnFilename") + ( Html("a", fname, href=dlfname1, title=html_escape(dldescr1)) ) trow += tcell dldescr1 = dldescr1 or " " trow += Html("td", dldescr1, class_="ColumnDescription", inline=True) tcell = Html("td", class_="ColumnModified", inline=True) trow += tcell if os.path.exists(dlfname1): modified = os.stat(dlfname1).st_mtime last_mod = datetime.datetime.fromtimestamp(modified) tcell += last_mod else: tcell += " " # if download filename #2, show it??? if dlfname2: # begin row #2 trow = Html("tr", id='Row02') tbody += trow fname = os.path.basename(dlfname2) tcell = Html("td", class_="ColumnFilename") + ( Html("a", fname, href=dlfname2, title=html_escape(dldescr2)) ) trow += tcell dldescr2 = dldescr2 or " " trow += Html("td", dldescr2, class_="ColumnDescription", inline=True) tcell = Html("td", id='Col04', class_="ColumnModified", inline=True) trow += tcell if os.path.exists(dlfname2): modified = os.stat(dlfname2).st_mtime last_mod = datetime.datetime.fromtimestamp(modified) tcell += last_mod else: tcell += " " # clear line for proper styling # create footer section footer = self.write_footer(None) body += (FULLCLEAR, footer) # send page out for processing # and close the file self.xhtml_writer(downloadpage, output_file, sio, 0)
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, body, outerwrapper = self.write_header(_("Places")) self.placemappages = self.report.options['placemappages'] self.mapservice = self.report.options['mapservice'] self.googlemapkey = self.report.options['googlemapkey'] # 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()) 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): latitude, longitude = conv_lat_lon(place.get_latitude(), place.get_longitude(), "D.D8") 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: 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 = self.secure_mode src_js += "openlayers.org/en/latest/build/ol.js" head += Html("script", type="text/javascript", src=src_js, inline=True) url = self.secure_mode url += "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 # Begin inline javascript code because jsc is a # docstring, it does NOT have to be properly indented if self.mapservice == "Google": with Html("script", type="text/javascript", indent=False) as jsc: head += 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) else: # OpenStreetMap (OSM) adds Longitude/ Latitude # to its maps, and needs a country code in # lowercase letters... with Html("script", type="text/javascript") as jsc: canvas += jsc #param1 = xml_lang()[3:5].lower() jsc += MARKER_PATH % marker_path jsc += OSM_MARKERS % ([[ float(longitude), float(latitude), placetitle ]], longitude, latitude, 10) # add javascript function call to body element body.attr += ' onload = "initialize();" ' # add div for popups. with Html("div", id="popup", inline=True) as popup: placedetail += popup # 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 # 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 repositorypage(self, report, title, repo, handle): """ Create one page for one repository. @param: report -- The instance of the main report class for this report @param: title -- Is the title of the web page @param: repo -- the repository to use @param: handle -- the handle to use """ gid = repo.get_gramps_id() BasePage.__init__(self, report, title, gid) ldatec = repo.get_change_time() output_file, sio = self.report.create_file(handle, 'repo') self.uplink = True repositorypage, head, body = self.write_header(_('Repositories')) # begin RepositoryDetail division and page title with Html("div", class_="content", id="RepositoryDetail") as repositorydetail: body += repositorydetail # repository name repositorydetail += Html("h3", html_escape(repo.name), inline=True) # begin repository table with Html("table", class_="infolist repolist") as table: repositorydetail += table tbody = Html("tbody") table += tbody if not self.noid and gid: trow = Html("tr") + ( Html("td", self._("Gramps ID"), class_="ColumnAttribute", inline=True), Html("td", gid, class_="ColumnValue", inline=True) ) tbody += trow trow = Html("tr") + ( Html("td", self._("Type"), class_="ColumnAttribute", inline=True), Html("td", self._(repo.get_type().xml_str()), class_="ColumnValue", inline=True) ) tbody += trow # repository: address(es)... # repository addresses do NOT have Sources repo_address = self.display_addr_list(repo.get_address_list(), False) if repo_address is not None: repositorydetail += repo_address # repository: urllist urllist = self.display_url_list(repo.get_url_list()) if urllist is not None: repositorydetail += urllist # reposity: notelist notelist = self.display_note_list(repo.get_note_list()) if notelist is not None: repositorydetail += notelist # display Repository Referenced Sources... ref_list = self.display_bkref_list(Repository, repo.get_handle()) if ref_list is not None: repositorydetail += 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 file self.xhtml_writer(repositorypage, output_file, sio, ldatec)
def __init__(self, report, title): """ @param: report -- The instance of the main report class for this report @param: title -- Is the title of the web page """ BasePage.__init__(self, report, title) # do NOT include a Download Page if not self.report.inc_download: return # menu options for class # download and description #1 dlfname1 = self.report.dl_fname1 dldescr1 = self.report.dl_descr1 # download and description #2 dlfname2 = self.report.dl_fname2 dldescr2 = self.report.dl_descr2 # if no filenames at all, return??? if dlfname1 or dlfname2: output_file, sio = self.report.create_file("download") downloadpage, head, body = self.write_header(self._('Download')) # begin download page and table with Html("div", class_="content", id="Download") as download: body += download msg = self._("This page is for the user/ creator " "of this Family Tree/ Narrative website " "to share a couple of files with you " "regarding their family. If there are " "any files listed " "below, clicking on them will allow you " "to download them. The " "download page and files have the same " "copyright as the remainder " "of these web pages.") download += Html("p", msg, id="description") # begin download table and table head with Html("table", class_="infolist download") as table: download += table thead = Html("thead") table += thead trow = Html("tr") thead += trow trow.extend( Html("th", label, class_="Column" + colclass, inline=True) for (label, colclass) in [( self._("File Name"), "Filename"), (self._("Description"), "Description"), (self._("Last Modified"), "Modified")]) # table body tbody = Html("tbody") table += tbody # if dlfname1 is not None, show it??? if dlfname1: trow = Html("tr", id='Row01') tbody += trow fname = os.path.basename(dlfname1) # TODO dlfname1 is filename, convert disk path to URL tcell = Html("td", class_="ColumnFilename") + (Html( "a", fname, href=dlfname1, title=html_escape(dldescr1))) trow += tcell dldescr1 = dldescr1 or " " trow += Html("td", dldescr1, class_="ColumnDescription", inline=True) tcell = Html("td", class_="ColumnModified", inline=True) trow += tcell if os.path.exists(dlfname1): modified = os.stat(dlfname1).st_mtime last_mod = datetime.datetime.fromtimestamp( modified) tcell += last_mod else: tcell += " " # if download filename #2, show it??? if dlfname2: # begin row #2 trow = Html("tr", id='Row02') tbody += trow fname = os.path.basename(dlfname2) tcell = Html("td", class_="ColumnFilename") + (Html( "a", fname, href=dlfname2, title=html_escape(dldescr2))) trow += tcell dldescr2 = dldescr2 or " " trow += Html("td", dldescr2, class_="ColumnDescription", inline=True) tcell = Html("td", id='Col04', class_="ColumnModified", inline=True) trow += tcell if os.path.exists(dlfname2): modified = os.stat(dlfname2).st_mtime last_mod = datetime.datetime.fromtimestamp( modified) tcell += last_mod else: tcell += " " # clear line for proper styling # create footer section footer = self.write_footer(None) body += (FULLCLEAR, footer) # send page out for processing # and close the file self.xhtml_writer(downloadpage, output_file, sio, 0)
def __init__(self, report, title, surname, ppl_handle_list): """ @param: report -- The instance of the main report class for this report @param: title -- Is the title of the web page @param: surname -- The surname to use @param: ppl_handle_list -- The list of people for whom we need to create a page. """ BasePage.__init__(self, report, title) # module variables showbirth = report.options['showbirth'] showdeath = report.options['showdeath'] showpartner = report.options['showpartner'] showparents = report.options['showparents'] if surname == '': surname = self._("<absent>") output_file, sio = self.report.create_file(name_to_md5(surname), "srn") self.uplink = True (surnamepage, head, body) = self.write_header("%s - %s" % (self._("Surname"), surname)) ldatec = 0 # begin SurnameDetail division with Html("div", class_="content", id="SurnameDetail") as surnamedetail: body += surnamedetail # section title # 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 surnamedetail += Html("h3", html_escape(surnamed), inline=True) # feature request 2356: avoid genitive form msg = self._("This page contains an index of all the individuals " "in the database with the surname of %s. " "Selecting the person’s name " "will take you to that person’s " "individual page.") % html_escape(surname) surnamedetail += Html("p", msg, id="description") # begin surname table and thead with Html("table", class_="infolist primobjlist surname") as table: surnamedetail += table thead = Html("thead") table += thead trow = Html("tr") thead += trow # Name Column trow += Html("th", self._("Given 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) # begin table body tbody = Html("tbody") table += tbody for person_handle in sorted(ppl_handle_list, key=self.sort_on_given_and_birth): person = self.r_db.get_person_from_handle(person_handle) if person.get_change_time() > ldatec: ldatec = person.get_change_time() trow = Html("tr") tbody += trow # firstname column link = self.new_person_link(person_handle, uplink=True, person=person, name_style=_NAME_STYLE_FIRST) 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: tcell = Html("td", class_="ColumnPartner") trow += tcell family_list = person.get_family_handle_list() if family_list: fam_count = 0 for family_handle in family_list: fam_count += 1 family = self.r_db.get_family_from_handle( family_handle) partner_handle = utils.find_spouse( person, family) if partner_handle: link = self.new_person_link(partner_handle, uplink=True) if fam_count < len(family_list): if isinstance(link, Html): link.inside += "," else: link += ',' tcell += link else: tcell += " " # parents column if showparents: parent_hdl_list = person.get_parent_family_handle_list() if parent_hdl_list: parent_hdl = parent_hdl_list[0] fam = self.r_db.get_family_from_handle(parent_hdl) f_id = fam.get_father_handle() m_id = fam.get_mother_handle() mother = father = None if f_id: father = self.r_db.get_person_from_handle(f_id) if father: father_name = self.get_name(father) if m_id: mother = self.r_db.get_person_from_handle(m_id) if mother: mother_name = self.get_name(mother) if mother and father: tcell = Html("span", father_name, class_="father fatherNmother") tcell += Html("span", mother_name, class_="mother") elif mother: tcell = Html("span", mother_name, class_="mother", inline=True) elif father: tcell = Html("span", father_name, class_="father", inline=True) samerow = False else: tcell = " " # pylint: disable=R0204 samerow = True trow += Html("td", tcell, class_="ColumnParents", inline=samerow) # add clearline for proper styling # add footer section footer = self.write_footer(ldatec) body += (FULLCLEAR, footer) # send page out for processing # and close the file self.xhtml_writer(surnamepage, output_file, sio, ldatec)