* src/Simple/_SimpleTable.py:
added callback for click/doubleclick manual override for rows added numeric sorting * src/QuickReports.py: added run_quick_report_by_name_direct that allows one quick report to run another * src/plugins/DefaultGramplets.py: made stats gramplet show details when drilling down with double-click * src/plugins/SameSurnames.py: allow running by string rather than person object * src/DataViews/GrampletView.py: added Filter type of link; fixed bug in drag and drop from earlier option infrastructure * src/plugins/FilterByName.py: quick report that runs a filter by name 2008-03-04 Douglas S. Blank <dblank@cs.brynmawr.edu> svn: r10188
This commit is contained in:
		
							
								
								
									
										15
									
								
								ChangeLog
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								ChangeLog
									
									
									
									
									
								
							@@ -1,3 +1,18 @@
 | 
			
		||||
2008-03-04  Douglas S. Blank  <dblank@cs.brynmawr.edu>
 | 
			
		||||
	* src/Simple/_SimpleTable.py: 
 | 
			
		||||
	added callback for click/doubleclick manual override for rows
 | 
			
		||||
	added numeric sorting
 | 
			
		||||
	* src/QuickReports.py: added run_quick_report_by_name_direct
 | 
			
		||||
	that allows one quick report to run another
 | 
			
		||||
	* src/plugins/DefaultGramplets.py: made stats gramplet show 
 | 
			
		||||
	details when drilling down with double-click
 | 
			
		||||
	* src/plugins/SameSurnames.py: allow running by string rather than 
 | 
			
		||||
	person object
 | 
			
		||||
	* src/DataViews/GrampletView.py: added Filter type of link; fixed
 | 
			
		||||
	bug in drag and drop from earlier option infrastructure
 | 
			
		||||
	* src/plugins/FilterByName.py: quick report that runs a filter by
 | 
			
		||||
	name
 | 
			
		||||
 | 
			
		||||
2008-03-04  Douglas S. Blank  <dblank@cs.brynmawr.edu>
 | 
			
		||||
	* src/docgen/HtmlDoc.py (HtmlDoc.page_break): 
 | 
			
		||||
	Fixed indentation issue
 | 
			
		||||
 
 | 
			
		||||
@@ -428,6 +428,14 @@ class Gramplet(object):
 | 
			
		||||
                                                     'samesurnames', 
 | 
			
		||||
                                                     handle)
 | 
			
		||||
                    return True
 | 
			
		||||
                elif link_type == 'Filter':
 | 
			
		||||
                    if event.button == 1: # left mouse
 | 
			
		||||
                        if event.type == gtk.gdk._2BUTTON_PRESS: # double
 | 
			
		||||
                            run_quick_report_by_name(self.gui.dbstate, 
 | 
			
		||||
                                                     self.gui.uistate, 
 | 
			
		||||
                                                     'filterbyname', 
 | 
			
		||||
                                                     handle)
 | 
			
		||||
                    return True
 | 
			
		||||
        return False # did not handle event
 | 
			
		||||
 | 
			
		||||
    def set_options(self, option_dict):
 | 
			
		||||
@@ -902,7 +910,8 @@ class GrampletView(PageView.PageView):
 | 
			
		||||
        """
 | 
			
		||||
        button = context.get_source_widget()
 | 
			
		||||
        hbox = button.get_parent()
 | 
			
		||||
        mainframe = hbox.get_parent()
 | 
			
		||||
        mframe = hbox.get_parent()
 | 
			
		||||
        mainframe = mframe.get_parent() # actually a vbox
 | 
			
		||||
        rect = source.get_allocation()
 | 
			
		||||
        sx, sy = rect.width, rect.height
 | 
			
		||||
        # first, find column:
 | 
			
		||||
 
 | 
			
		||||
@@ -55,7 +55,7 @@ import gtk
 | 
			
		||||
 | 
			
		||||
#from PluginUtils import Plugins
 | 
			
		||||
from ReportBase  import (CATEGORY_QR_PERSON, CATEGORY_QR_FAMILY,
 | 
			
		||||
                        CATEGORY_QR_EVENT, CATEGORY_QR_SOURCE,
 | 
			
		||||
                        CATEGORY_QR_EVENT, CATEGORY_QR_SOURCE, CATEGORY_QR_MISC,
 | 
			
		||||
                        CATEGORY_QR_PLACE, CATEGORY_QR_REPOSITORY)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -122,6 +122,31 @@ def run_quick_report_by_name(dbstate, uistate, report_name, handle):
 | 
			
		||||
            break
 | 
			
		||||
    if report:
 | 
			
		||||
        run_report(dbstate, uistate, report[2], handle, report[0])
 | 
			
		||||
    else:
 | 
			
		||||
        raise AttributeError, ("No such quick report '%s'" % report_name)
 | 
			
		||||
 | 
			
		||||
def run_quick_report_by_name_direct(report_name, database, document, handle):
 | 
			
		||||
    """
 | 
			
		||||
    Useful for running one quick report from another
 | 
			
		||||
    """
 | 
			
		||||
    from PluginUtils import quick_report_list
 | 
			
		||||
    from docgen import TextBufDoc
 | 
			
		||||
    from Simple import make_basic_stylesheet
 | 
			
		||||
    report = None
 | 
			
		||||
    for item in quick_report_list:
 | 
			
		||||
        if item[3] == report_name:
 | 
			
		||||
            report = item
 | 
			
		||||
            break
 | 
			
		||||
    if report:
 | 
			
		||||
        # FIXME: allow auto lookup of obj like below?
 | 
			
		||||
        d = TextBufDoc(make_basic_stylesheet(), None, None)
 | 
			
		||||
        d.dbstate = document.dbstate
 | 
			
		||||
        d.uistate = document.uistate
 | 
			
		||||
        d.open("")
 | 
			
		||||
        report[0](database, d, handle)
 | 
			
		||||
        d.close()
 | 
			
		||||
    else:
 | 
			
		||||
        raise AttributeError, ("No such quick report '%s'" % report_name)
 | 
			
		||||
                            
 | 
			
		||||
def run_report(dbstate, uistate, category, handle,func):
 | 
			
		||||
        from docgen import TextBufDoc
 | 
			
		||||
@@ -144,6 +169,8 @@ def run_report(dbstate, uistate, category, handle,func):
 | 
			
		||||
                    obj = dbstate.db.get_place_from_handle(handle)
 | 
			
		||||
                elif category == CATEGORY_QR_REPOSITORY :
 | 
			
		||||
                    obj = dbstate.db.get_repository_from_handle(handle)
 | 
			
		||||
                elif category == CATEGORY_QR_MISC:
 | 
			
		||||
                    obj = handle
 | 
			
		||||
                else: 
 | 
			
		||||
                    obj = None
 | 
			
		||||
            else: # allow caller to send object directly
 | 
			
		||||
 
 | 
			
		||||
@@ -47,6 +47,8 @@ class SimpleTable:
 | 
			
		||||
        self.__sort_col = None
 | 
			
		||||
        self.__sort_reverse = False
 | 
			
		||||
        self.__link_col = None
 | 
			
		||||
        self.__callback_leftclick = None
 | 
			
		||||
        self.__callback_leftdouble = None
 | 
			
		||||
 | 
			
		||||
    def get_row_count(self):
 | 
			
		||||
        return len(self.__rows)
 | 
			
		||||
@@ -58,6 +60,15 @@ class SimpleTable:
 | 
			
		||||
        self.__columns = list(copy.copy(columns))
 | 
			
		||||
        self.__sort_vals = [[] for i in range(len(self.__columns))]
 | 
			
		||||
 | 
			
		||||
    def set_callback(self, which, callback):
 | 
			
		||||
        """
 | 
			
		||||
        Override (or add) a function for click/double-click
 | 
			
		||||
        """
 | 
			
		||||
        if which == "leftclick":
 | 
			
		||||
            self.__callback_leftclick = callback
 | 
			
		||||
        elif which == "leftdouble":
 | 
			
		||||
            self.__callback_leftdouble = callback
 | 
			
		||||
 | 
			
		||||
    def on_table_doubleclick(self, obj, path, view_column):
 | 
			
		||||
        """
 | 
			
		||||
        Handle events on tables. obj is a treeview
 | 
			
		||||
@@ -69,7 +80,9 @@ class SimpleTable:
 | 
			
		||||
        if not node:
 | 
			
		||||
            return
 | 
			
		||||
        index = store.get_value(node, 0) # index
 | 
			
		||||
        if self.__link[index]:
 | 
			
		||||
        if self.__callback_leftdouble:
 | 
			
		||||
            self.__callback_leftdouble(store.get_value(node, 1))
 | 
			
		||||
        elif self.__link[index]:
 | 
			
		||||
            objclass, handle = self.__link[index]
 | 
			
		||||
            if objclass == 'Person':
 | 
			
		||||
                person = self.access.dbase.get_person_from_handle(handle)
 | 
			
		||||
@@ -161,6 +174,9 @@ class SimpleTable:
 | 
			
		||||
            # FIXME: add better text representations of these objects
 | 
			
		||||
            if type(item) in [str, unicode]:
 | 
			
		||||
                retval.append(item)
 | 
			
		||||
            elif type(item) in [int, float]:
 | 
			
		||||
                retval.append(item)
 | 
			
		||||
                self.row_sort_val(col, item)
 | 
			
		||||
            elif isinstance(item, gen.lib.Person):
 | 
			
		||||
                name = self.access.name(item)
 | 
			
		||||
                retval.append(name)
 | 
			
		||||
 
 | 
			
		||||
@@ -595,9 +595,12 @@ class StatsGramplet(Gramplet):
 | 
			
		||||
                total_photos = total_photos + length
 | 
			
		||||
 | 
			
		||||
            person = database.get_person_from_handle(person_handle)
 | 
			
		||||
            name = person.get_primary_name()
 | 
			
		||||
            if name.get_first_name() == "" or name.get_surname() == "":
 | 
			
		||||
                incomp_names = incomp_names + 1
 | 
			
		||||
            names = [person.get_primary_name()] + person.get_alternate_names()
 | 
			
		||||
            for name in names:
 | 
			
		||||
                if name.get_first_name() == "" or name.get_surname() == "":
 | 
			
		||||
                    incomp_names = incomp_names + 1
 | 
			
		||||
                if name.get_surname() not in namelist:
 | 
			
		||||
                    namelist.append(name.get_surname())
 | 
			
		||||
            if ((not person.get_main_parents_family_handle()) and 
 | 
			
		||||
                (not len(person.get_family_handle_list()))):
 | 
			
		||||
                disconnected = disconnected + 1
 | 
			
		||||
@@ -614,39 +617,70 @@ class StatsGramplet(Gramplet):
 | 
			
		||||
                males = males + 1
 | 
			
		||||
            else:
 | 
			
		||||
                unknowns += 1
 | 
			
		||||
            if name.get_surname() not in namelist:
 | 
			
		||||
                namelist.append(name.get_surname())
 | 
			
		||||
            if cnt % 200 == 0:
 | 
			
		||||
                yield True
 | 
			
		||||
            cnt += 1
 | 
			
		||||
 | 
			
		||||
        text = _("Individuals") + "\n"
 | 
			
		||||
        text = text + "----------------------------\n"
 | 
			
		||||
        text = text + "%s: %d\n" % (_("Number of individuals"),len(personList))
 | 
			
		||||
        text = text + "%s: %d\n" % (_("Males"),males)
 | 
			
		||||
        text = text + "%s: %d\n" % (_("Females"),females)
 | 
			
		||||
        text = text + "%s: %d\n" % (_("Individuals with unknown gender"),unknowns)
 | 
			
		||||
        text = text + "%s: %d\n" % (_("Individuals with incomplete names"),incomp_names)
 | 
			
		||||
        text = text + "%s: %d\n" % (_("Individuals missing birth dates"),missing_bday)
 | 
			
		||||
        text = text + "%s: %d\n" % (_("Disconnected individuals"),disconnected)
 | 
			
		||||
        text = text + "\n%s\n" % _("Family Information")
 | 
			
		||||
        text = text + "----------------------------\n"
 | 
			
		||||
        text = text + "%s: %d\n" % (_("Number of families"),len(familyList))
 | 
			
		||||
        text = text + "%s: %d\n" % (_("Unique surnames"),len(namelist))
 | 
			
		||||
        text = text + "\n%s\n" % _("Media Objects")
 | 
			
		||||
        text = text + "----------------------------\n"
 | 
			
		||||
        text = text + "%s: %d\n" % (_("Individuals with media objects"),with_photos)
 | 
			
		||||
        text = text + "%s: %d\n" % (_("Total number of media object references"),total_photos)
 | 
			
		||||
        text = text + "%s: %d\n" % (_("Number of unique media objects"),pobjects)
 | 
			
		||||
        text = text + "%s: %d %s\n" % (_("Total size of media objects"),bytes,\
 | 
			
		||||
                                        _("bytes"))
 | 
			
		||||
 | 
			
		||||
        if len(notfound) > 0:
 | 
			
		||||
            text = text + "\n%s\n" % _("Missing Media Objects")
 | 
			
		||||
            text = text + "----------------------------\n"
 | 
			
		||||
            for p in notfound:
 | 
			
		||||
                text = text + "%s\n" % p
 | 
			
		||||
        self.set_text(text)
 | 
			
		||||
        self.clear_text()
 | 
			
		||||
        self.append_text(_("Individuals") + "\n")
 | 
			
		||||
        self.append_text("----------------------------\n")
 | 
			
		||||
        self.link(_("Number of individuals") + ":",
 | 
			
		||||
                  'Filter', 'all people')
 | 
			
		||||
        self.append_text(" %s" % len(personList))
 | 
			
		||||
        self.append_text("\n")
 | 
			
		||||
        self.link("%s:" % _("Males"), 'Filter', 'males')
 | 
			
		||||
        self.append_text(" %s" % males)
 | 
			
		||||
        self.append_text("\n")
 | 
			
		||||
        self.link("%s:" % _("Females"), 'Filter', 'females')
 | 
			
		||||
        self.append_text(" %s" % females)
 | 
			
		||||
        self.append_text("\n")
 | 
			
		||||
        self.link("%s:" % _("Individuals with unknown gender"),
 | 
			
		||||
                  'Filter', 'people with unknown gender')
 | 
			
		||||
        self.append_text(" %s" % unknowns)
 | 
			
		||||
        self.append_text("\n")
 | 
			
		||||
        self.link("%s:" % _("Individuals with incomplete names"),
 | 
			
		||||
                  'Filter', 'people with incomplete names')
 | 
			
		||||
        self.append_text(" %s" % incomp_names)
 | 
			
		||||
        self.append_text("\n")
 | 
			
		||||
        self.link("%s:" % _("Individuals missing birth dates"),
 | 
			
		||||
                  'Filter', 'people with missing birth dates')
 | 
			
		||||
        self.append_text(" %s" % missing_bday)
 | 
			
		||||
        self.append_text("\n")
 | 
			
		||||
        self.link("%s:" % _("Disconnected individuals"),
 | 
			
		||||
                  'Filter', 'disconnected people')
 | 
			
		||||
        self.append_text(" %s" % disconnected)
 | 
			
		||||
        self.append_text("\n")
 | 
			
		||||
        self.append_text("\n%s\n" % _("Family Information"))
 | 
			
		||||
        self.append_text("----------------------------\n")
 | 
			
		||||
        self.link("%s:" % _("Number of families"),
 | 
			
		||||
                  'Filter', 'all families')
 | 
			
		||||
        self.append_text(" %s" % len(familyList))
 | 
			
		||||
        self.append_text("\n")
 | 
			
		||||
        self.link("%s:" % _("Unique surnames"), 
 | 
			
		||||
                  'Filter', 'unique surnames')
 | 
			
		||||
        self.append_text(" %s" % len(namelist))
 | 
			
		||||
        self.append_text("\n")
 | 
			
		||||
        self.append_text("\n%s\n" % _("Media Objects"))
 | 
			
		||||
        self.append_text("----------------------------\n")
 | 
			
		||||
        self.link("%s:" % _("Individuals with media objects"),
 | 
			
		||||
                  'Filter', 'people with media')
 | 
			
		||||
        self.append_text(" %s" % with_photos)
 | 
			
		||||
        self.append_text("\n")
 | 
			
		||||
        self.link("%s:" % _("Total number of media object references"),
 | 
			
		||||
                  'Filter', 'media references')
 | 
			
		||||
        self.append_text(" %s" % total_photos)
 | 
			
		||||
        self.append_text("\n")
 | 
			
		||||
        self.link("%s:" % _("Number of unique media objects"),
 | 
			
		||||
                  'Filter', 'unique media')
 | 
			
		||||
        self.append_text(" %s" % pobjects)
 | 
			
		||||
        self.append_text("\n")
 | 
			
		||||
        self.append_text("%s: %d %s\n" % (_("Total size of media objects"),
 | 
			
		||||
                                          bytes,
 | 
			
		||||
                                          _("bytes")))
 | 
			
		||||
        self.link("%s:" % _("Missing Media Objects"),
 | 
			
		||||
                  'Filter', 'missing media')
 | 
			
		||||
        self.append_text(" %s\n" % total_photos)
 | 
			
		||||
        self.append_text("", scroll_to="begin")
 | 
			
		||||
 | 
			
		||||
class PythonGramplet(Gramplet):
 | 
			
		||||
    def init(self):
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										210
									
								
								src/plugins/FilterByName.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										210
									
								
								src/plugins/FilterByName.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,210 @@
 | 
			
		||||
#
 | 
			
		||||
# Gramps - a GTK+/GNOME based genealogy program
 | 
			
		||||
#
 | 
			
		||||
# Copyright (C) 2000-2007  Donald N. Allingham
 | 
			
		||||
# Copyright (C) 2007       Brian G. Matherly
 | 
			
		||||
#
 | 
			
		||||
# This program is free software; you can redistribute it and/or modify
 | 
			
		||||
# it under the terms of the GNU General Public License as published by
 | 
			
		||||
# the Free Software Foundation; either version 2 of the License, or
 | 
			
		||||
# (at your option) any later version.
 | 
			
		||||
#
 | 
			
		||||
# This program is distributed in the hope that it will be useful,
 | 
			
		||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
# GNU General Public License for more details.
 | 
			
		||||
#
 | 
			
		||||
# You should have received a copy of the GNU General Public License
 | 
			
		||||
# along with this program; if not, write to the Free Software
 | 
			
		||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
Display filtered data
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
from Simple import SimpleAccess, SimpleDoc, SimpleTable
 | 
			
		||||
from gettext import gettext as _
 | 
			
		||||
from PluginUtils import register_quick_report
 | 
			
		||||
from Utils import media_path_full
 | 
			
		||||
from QuickReports import run_quick_report_by_name_direct
 | 
			
		||||
from gen.lib import Person
 | 
			
		||||
import DateHandler
 | 
			
		||||
 | 
			
		||||
def run(database, document, filter_name):
 | 
			
		||||
    """
 | 
			
		||||
    Loops through the families that the person is a child in, and display
 | 
			
		||||
    the information about the other children.
 | 
			
		||||
    """
 | 
			
		||||
    # setup the simple access functions
 | 
			
		||||
    sdb = SimpleAccess(database)
 | 
			
		||||
    sdoc = SimpleDoc(document)
 | 
			
		||||
    stab = SimpleTable(sdb, sdoc)
 | 
			
		||||
    # display the title
 | 
			
		||||
    sdoc.title(_("Filtering on %s") % filter_name)
 | 
			
		||||
    sdoc.paragraph("")
 | 
			
		||||
    matches = 0
 | 
			
		||||
    if (filter_name == 'all people'):
 | 
			
		||||
        stab.columns(_("Person"), _("Birth Date"), _("Name type"))
 | 
			
		||||
        people = database.get_person_handles(sort_handles=False)
 | 
			
		||||
        for person_handle in people:
 | 
			
		||||
            person = database.get_person_from_handle(person_handle)
 | 
			
		||||
            stab.row(person, sdb.birth_date_obj(person),
 | 
			
		||||
                     str(person.get_primary_name().get_type()))
 | 
			
		||||
            matches += 1
 | 
			
		||||
    elif (filter_name == 'males'):
 | 
			
		||||
        stab.columns(_("Person"), _("Birth Date"), _("Name type"))
 | 
			
		||||
        people = database.get_person_handles(sort_handles=False)
 | 
			
		||||
        for person_handle in people:
 | 
			
		||||
            person = database.get_person_from_handle(person_handle)
 | 
			
		||||
            if person.gender == Person.MALE:
 | 
			
		||||
                stab.row(person, sdb.birth_date_obj(person),
 | 
			
		||||
                         str(person.get_primary_name().get_type()))
 | 
			
		||||
                matches += 1
 | 
			
		||||
    elif (filter_name == 'females'):
 | 
			
		||||
        stab.columns(_("Person"), _("Birth Date"), _("Name type"))
 | 
			
		||||
        people = database.get_person_handles(sort_handles=False)
 | 
			
		||||
        for person_handle in people:
 | 
			
		||||
            person = database.get_person_from_handle(person_handle)
 | 
			
		||||
            if person.gender == Person.FEMALE:
 | 
			
		||||
                stab.row(person, sdb.birth_date_obj(person),
 | 
			
		||||
                         str(person.get_primary_name().get_type()))
 | 
			
		||||
                matches += 1
 | 
			
		||||
    elif (filter_name == 'people with unknown gender'):
 | 
			
		||||
        stab.columns(_("Person"), _("Birth Date"), _("Name type"))
 | 
			
		||||
        people = database.get_person_handles(sort_handles=False)
 | 
			
		||||
        for person_handle in people:
 | 
			
		||||
            person = database.get_person_from_handle(person_handle)
 | 
			
		||||
            if person.gender not in [Person.FEMALE, Person.MALE]:
 | 
			
		||||
                stab.row(person, sdb.birth_date_obj(person),
 | 
			
		||||
                         str(person.get_primary_name().get_type()))
 | 
			
		||||
                matches += 1
 | 
			
		||||
    elif (filter_name == 'people with incomplete names'):
 | 
			
		||||
        stab.columns(_("Person"), _("Birth Date"), _("Name type"))
 | 
			
		||||
        people = database.get_person_handles(sort_handles=False)
 | 
			
		||||
        for person_handle in people:
 | 
			
		||||
            person = database.get_person_from_handle(person_handle)
 | 
			
		||||
            for name in [person.get_primary_name()] + person.get_alternate_names():
 | 
			
		||||
                if name.get_surname() == "" or name.get_first_name() == "":
 | 
			
		||||
                    stab.row(person, sdb.birth_date_obj(person),
 | 
			
		||||
                             str(person.get_primary_name().get_type()))
 | 
			
		||||
                    matches += 1
 | 
			
		||||
    elif (filter_name == 'people with missing birth dates'):
 | 
			
		||||
        stab.columns(_("Person"), _("Type"))
 | 
			
		||||
        people = database.get_person_handles(sort_handles=False)
 | 
			
		||||
        for person_handle in people:
 | 
			
		||||
            person = database.get_person_from_handle(person_handle)
 | 
			
		||||
            if person:
 | 
			
		||||
                birth_ref = person.get_birth_ref()
 | 
			
		||||
                if birth_ref:
 | 
			
		||||
                    birth = database.get_event_from_handle(birth_ref.ref)
 | 
			
		||||
                    if not DateHandler.get_date(birth):
 | 
			
		||||
                        stab.row(person, "birth event but no date")
 | 
			
		||||
                        matches += 1
 | 
			
		||||
                else:
 | 
			
		||||
                    stab.row(person, "missing birth event")
 | 
			
		||||
                    matches += 1
 | 
			
		||||
    elif (filter_name == 'disconnected people'):
 | 
			
		||||
        stab.columns(_("Person"), _("Birth Date"), _("Name type"))
 | 
			
		||||
        people = database.get_person_handles(sort_handles=False)
 | 
			
		||||
        for person_handle in people:
 | 
			
		||||
            person = database.get_person_from_handle(person_handle)
 | 
			
		||||
            if person:
 | 
			
		||||
                if ((not person.get_main_parents_family_handle()) and 
 | 
			
		||||
                    (not len(person.get_family_handle_list()))):
 | 
			
		||||
                    stab.row(person, sdb.birth_date_obj(person),
 | 
			
		||||
                             str(person.get_primary_name().get_type()))
 | 
			
		||||
                    matches += 1
 | 
			
		||||
    elif (filter_name == 'all families'):
 | 
			
		||||
        familyList = database.get_family_handles()
 | 
			
		||||
        stab.columns(_("Family"))
 | 
			
		||||
        for family_handle in familyList:
 | 
			
		||||
            family = database.get_family_from_handle(family_handle)
 | 
			
		||||
            if family:
 | 
			
		||||
                stab.row(family)
 | 
			
		||||
                matches += 1
 | 
			
		||||
    elif (filter_name == 'unique surnames'):
 | 
			
		||||
        namelist = {}
 | 
			
		||||
        people = database.get_person_handles(sort_handles=False)
 | 
			
		||||
        for person_handle in people:
 | 
			
		||||
            person = database.get_person_from_handle(person_handle)
 | 
			
		||||
            if person:
 | 
			
		||||
                name = person.get_primary_name()
 | 
			
		||||
                if name:
 | 
			
		||||
                    surname = name.get_surname()
 | 
			
		||||
                    if surname:
 | 
			
		||||
                        namelist[surname] = namelist.get(surname, 0) + 1
 | 
			
		||||
        surnames = namelist.keys()
 | 
			
		||||
        surnames.sort()
 | 
			
		||||
        stab.columns(_("Surname"), _("Count"))
 | 
			
		||||
        for name in surnames:
 | 
			
		||||
            stab.row(name, namelist[name])
 | 
			
		||||
            matches += 1
 | 
			
		||||
        stab.set_callback("leftdouble", 
 | 
			
		||||
            lambda name: run_quick_report_by_name_direct("samesurnames",
 | 
			
		||||
                                                         database,
 | 
			
		||||
                                                         document,
 | 
			
		||||
                                                         name))
 | 
			
		||||
    elif (filter_name == 'people with media'):
 | 
			
		||||
        stab.columns(_("Person"), _("Media count"))
 | 
			
		||||
        people = database.get_person_handles(sort_handles=False)
 | 
			
		||||
        for person_handle in people:
 | 
			
		||||
            person = database.get_person_from_handle(person_handle)
 | 
			
		||||
            if not person:
 | 
			
		||||
                continue
 | 
			
		||||
            length = len(person.get_media_list())
 | 
			
		||||
            if length > 0:
 | 
			
		||||
                stab.row(person, length)
 | 
			
		||||
                matches += 1
 | 
			
		||||
    elif (filter_name == 'media references'):
 | 
			
		||||
        stab.columns(_("Person"), _("Reference"))
 | 
			
		||||
        people = database.get_person_handles(sort_handles=False)
 | 
			
		||||
        for person_handle in people:
 | 
			
		||||
            person = database.get_person_from_handle(person_handle)
 | 
			
		||||
            if not person:
 | 
			
		||||
                continue
 | 
			
		||||
            medialist = person.get_media_list()
 | 
			
		||||
            for item in medialist:
 | 
			
		||||
                stab.row(person, "media")
 | 
			
		||||
                matches += 1
 | 
			
		||||
    elif (filter_name == 'unique media'):
 | 
			
		||||
        stab.columns(_("Unique Media"))
 | 
			
		||||
        pobjects = database.get_media_object_handles()
 | 
			
		||||
        for photo_id in database.get_media_object_handles():
 | 
			
		||||
            photo = database.get_object_from_handle(photo_id)
 | 
			
		||||
            fullname = media_path_full(database, photo.get_path())
 | 
			
		||||
            stab.row(fullname)
 | 
			
		||||
            matches += 1
 | 
			
		||||
    elif (filter_name == 'missing media'):
 | 
			
		||||
        stab.columns(_("Missing Media"))
 | 
			
		||||
        pobjects = database.get_media_object_handles()
 | 
			
		||||
        for photo_id in database.get_media_object_handles():
 | 
			
		||||
            photo = database.get_object_from_handle(photo_id)
 | 
			
		||||
            fullname = media_path_full(database, photo.get_path())
 | 
			
		||||
            try:
 | 
			
		||||
                bytes = bytes + posixpath.getsize(fullname)
 | 
			
		||||
            except:
 | 
			
		||||
                stab.row(fullname)
 | 
			
		||||
                matches += 1
 | 
			
		||||
    else:
 | 
			
		||||
        raise AttributeError, ("invalid filter name: '%s'" % filter_name)
 | 
			
		||||
    sdoc.paragraph(_("Filter matched %d records.") % matches)
 | 
			
		||||
    sdoc.paragraph("")
 | 
			
		||||
    if matches > 0:
 | 
			
		||||
        stab.write()
 | 
			
		||||
                    
 | 
			
		||||
#------------------------------------------------------------------------
 | 
			
		||||
#
 | 
			
		||||
# 
 | 
			
		||||
#
 | 
			
		||||
#------------------------------------------------------------------------
 | 
			
		||||
register_quick_report(
 | 
			
		||||
    name = 'filterbyname',
 | 
			
		||||
    category = -1, # stand-alone
 | 
			
		||||
    run_func = run,
 | 
			
		||||
    translated_name = _("Filter"),
 | 
			
		||||
    status = _("Stable"),
 | 
			
		||||
    description= _("Display filtered data"),
 | 
			
		||||
    author_name="Douglas S. Blank",
 | 
			
		||||
    author_email="dblank@cs.brynmawr.edu"
 | 
			
		||||
    )
 | 
			
		||||
@@ -63,15 +63,19 @@ def run(database, document, person):
 | 
			
		||||
    sdb = SimpleAccess(database)
 | 
			
		||||
    sdoc = SimpleDoc(document)
 | 
			
		||||
    stab = SimpleTable(sdb, sdoc)
 | 
			
		||||
    if type(person) == str:
 | 
			
		||||
        surname = person
 | 
			
		||||
        rsurname = person
 | 
			
		||||
    else:
 | 
			
		||||
        surname = sdb.surname(person)
 | 
			
		||||
        rsurname = person.get_primary_name().get_surname()
 | 
			
		||||
    # display the title
 | 
			
		||||
    sdoc.title(_("People with the surname '%s'") % sdb.surname(person))
 | 
			
		||||
    sdoc.title(_("People with the surname '%s'") % surname)
 | 
			
		||||
    sdoc.paragraph("")
 | 
			
		||||
    stab.columns(_("Person"), _("Birth Date"), _("Name type"))
 | 
			
		||||
    # grab our current id (self):
 | 
			
		||||
    gid = sdb.gid(person)
 | 
			
		||||
    filter = GenericFilterFactory('Person')()
 | 
			
		||||
    if person.get_primary_name().get_surname() != '':
 | 
			
		||||
        rule = SameSurname([person.get_primary_name().get_surname()])
 | 
			
		||||
    if rsurname != '':
 | 
			
		||||
        rule = SameSurname([rsurname])
 | 
			
		||||
    else:
 | 
			
		||||
        rule = IncompleteSurname([])
 | 
			
		||||
    filter.add_rule(rule)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user