1# -*- coding: utf-8 -*- 2#!/usr/bin/env python 3# 4# Gramps - a GTK+/GNOME based genealogy program 5# 6# Copyright (C) 2000-2007 Donald N. Allingham 7# Copyright (C) 2007 Johan Gonqvist <johan.gronqvist@gmail.com> 8# Copyright (C) 2007-2009 Gary Burton <gary.burton@zen.co.uk> 9# Copyright (C) 2007-2009 Stephane Charette <stephanecharette@gmail.com> 10# Copyright (C) 2008-2009 Brian G. Matherly 11# Copyright (C) 2008 Jason M. Simanek <jason@bohemianalps.com> 12# Copyright (C) 2008-2011 Rob G. Healey <robhealey1@gmail.com> 13# Copyright (C) 2010 Doug Blank <doug.blank@gmail.com> 14# Copyright (C) 2010 Jakim Friant 15# Copyright (C) 2010- Serge Noiraud 16# Copyright (C) 2011 Tim G L Lyons 17# Copyright (C) 2013 Benny Malengier 18# Copyright (C) 2016 Allen Crider 19# 20# This program is free software; you can redistribute it and/or modify 21# it under the terms of the GNU General Public License as published by 22# the Free Software Foundation; either version 2 of the License, or 23# (at your option) any later version. 24# 25# This program is distributed in the hope that it will be useful, 26# but WITHOUT ANY WARRANTY; without even the implied warranty of 27# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28# GNU General Public License for more details. 29# 30# You should have received a copy of the GNU General Public License 31# along with this program; if not, write to the Free Software 32# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 33# 34 35""" 36Narrative Web Page generator. 37 38Classe: 39 AddressBookListPage 40""" 41#------------------------------------------------ 42# python modules 43#------------------------------------------------ 44from decimal import getcontext 45import logging 46 47#------------------------------------------------ 48# Gramps module 49#------------------------------------------------ 50from gramps.gen.const import GRAMPS_LOCALE as glocale 51from gramps.plugins.lib.libhtml import Html 52 53#------------------------------------------------ 54# specific narrative web import 55#------------------------------------------------ 56from gramps.plugins.webreport.basepage import BasePage 57from gramps.plugins.webreport.common import FULLCLEAR 58 59LOG = logging.getLogger(".NarrativeWeb") 60_ = glocale.translation.sgettext 61getcontext().prec = 8 62 63class AddressBookListPage(BasePage): 64 """ 65 Create the index for addresses. 66 """ 67 def __init__(self, report, title, has_url_addr_res): 68 """ 69 @param: report -- The instance of the main report class 70 for this report 71 @param: title -- Is the title of the web page 72 @param: has_url_addr_res -- The url, address and residence to use 73 for the report 74 """ 75 BasePage.__init__(self, report, title) 76 77 # Name the file, and create it 78 output_file, sio = self.report.create_file("addressbook") 79 80 # Add xml, doctype, meta and stylesheets 81 result = self.write_header(_("Address Book")) 82 addressbooklistpage, dummy_head, dummy_body, outerwrapper = result 83 84 # begin AddressBookList division 85 with Html("div", class_="content", 86 id="AddressBookList") as addressbooklist: 87 outerwrapper += addressbooklist 88 89 # Address Book Page message 90 msg = _("This page contains an index of all the individuals in " 91 "the database, sorted by their surname, with one of the " 92 "following: Address, Residence, or Web Links. " 93 "Selecting the person’s name will take you " 94 "to their individual Address Book page.") 95 addressbooklist += Html("p", msg, id="description") 96 97 # begin Address Book table 98 with Html("table", 99 class_="infolist primobjlist addressbook") as table: 100 addressbooklist += table 101 102 thead = Html("thead") 103 table += thead 104 105 trow = Html("tr") 106 thead += trow 107 108 trow.extend( 109 Html("th", label, class_=colclass, inline=True) 110 for (label, colclass) in [ 111 [" ", "ColumnRowLabel"], 112 [_("Full Name"), "ColumnName"], 113 [_("Address"), "ColumnAddress"], 114 [_("Residence"), "ColumnResidence"], 115 [_("Web Links"), "ColumnWebLinks"] 116 ] 117 ) 118 119 tbody = Html("tbody") 120 table += tbody 121 122 index = 1 123 for (dummy_sort_name, person_handle, 124 has_add, has_res, 125 has_url) in has_url_addr_res: 126 127 address = None 128 residence = None 129 weblinks = None 130 131 # has address but no residence event 132 if has_add and not has_res: 133 address = "X" 134 135 # has residence, but no addresses 136 elif has_res and not has_add: 137 residence = "X" 138 139 # has residence and addresses too 140 elif has_add and has_res: 141 address = "X" 142 residence = "X" 143 144 # has Web Links 145 if has_url: 146 weblinks = "X" 147 148 trow = Html("tr") 149 tbody += trow 150 151 trow.extend( 152 Html("td", data or " ", class_=colclass, 153 inline=True) 154 for (colclass, data) in [ 155 ["ColumnRowLabel", index], 156 ["ColumnName", 157 self.addressbook_link(person_handle)], 158 ["ColumnAddress", address], 159 ["ColumnResidence", residence], 160 ["ColumnWebLinks", weblinks] 161 ] 162 ) 163 index += 1 164 165 # Add footer and clearline 166 footer = self.write_footer(None) 167 outerwrapper += (FULLCLEAR, footer) 168 169 # send the page out for processing 170 # and close the file 171 self.xhtml_writer(addressbooklistpage, output_file, sio, 0) 172