Ejemplo n.º 1
0
class PlaceFamilyReport(Report):
    """
    Place Report class
    """
    def __init__(self, database, options, user):
        """
        Create the PlaceFamilyReport object produces the PlaceFamily report.
        
        The arguments are:

        database        - the GRAMPS database instance
        options         - instance of the Options class for this report
        user            - instance of a gen.user.User class

        This report needs the following parameters (class variables)
        that come in the options class.
        
        places          - List of places to report on.
        place_fmt       - Place Fromat used
        incpriv         - Whether to include private data
        showgodparents  - Whether to include and show godparents

        """

        Report.__init__(self, database, options, user)

        self._user = user
        menu = options.menu
        places = menu.get_option_by_name('places').get_value()
        self.place_fmt = menu.get_option_by_name("place_format").get_value()
        print("self.place_fmt                     ", self.place_fmt)
        self.incpriv = menu.get_option_by_name('incpriv').get_value()
        self.showgodparents = menu.get_option_by_name(
            'showgodparents').get_value()

        self.set_locale(menu.get_option_by_name('trans').get_value())

        name_format = menu.get_option_by_name("name_format").get_value()
        if name_format != 0:
            self._name_display.set_default_format(name_format)
        self._nd = self._name_display

        if self.incpriv:
            self.db = database
        else:
            self.db = PrivateProxyDb(database)

        filter_option = menu.get_option_by_name('filter')
        self.filter = filter_option.get_filter()
        self.sort = Sort(self.db)

        if self.filter.get_name() != '':
            # Use the selected filter to provide a list of place handles
            plist = self.db.iter_place_handles()
            self.place_handles = self.filter.apply(self.db, plist)
        else:
            # Use the place handles selected without a filter
            self.place_handles = self.__get_place_handles(places)

        self.place_handles.sort(key=self.sort.by_place_title_key)

    def write_report(self):
        """
        The routine that actually creates the report.
        At this point, the document is opened and ready for writing.
        """

        # Write the title line. Set in INDEX marker so that this section will be
        # identified as a major category if this is included in a Book report.

        title = self._("PlaceFamily Report")
        mark = IndexMark(title, INDEX_TYPE_TOC, 1)
        self.doc.start_paragraph("PLC-ReportTitle")
        self.doc.write_text(title, mark)
        self.doc.end_paragraph()

        self.__write_all_places()
        self.__write_referenced_families()

    def __write_all_places(self):
        """
        This procedure writes out each of the selected places.
        """
        place_nbr = 1
        subtitle = self._("Places")
        mark = IndexMark(subtitle, INDEX_TYPE_TOC, 2)
        self.doc.start_paragraph("PLC-ReportSubtitle")
        self.doc.write_text(subtitle, mark)
        self.doc.end_paragraph()

        self.doc.start_paragraph("PLC-Section")
        self.doc.write_text(
            "Enthält alle Familien mit Hochzeitsereignis in diesen Orten")
        self.doc.end_paragraph()

        pl_list = []
        pl_list = [
            _pd.display(self.db, self.db.get_place_from_handle(handle))
            for handle in self.place_handles
        ]
        for p in pl_list:
            self.doc.start_paragraph("PLC-Section")
            self.doc.write_text("     %s  " % place_nbr)
            self.doc.write_text(p)
            self.doc.end_paragraph()
            place_nbr += 1

        subtitle = self._("Families")
        mark = IndexMark(subtitle, INDEX_TYPE_TOC, 2)
        self.doc.start_paragraph("PLC-ReportSubtitle")
        self.doc.write_text(subtitle, mark)
        self.doc.end_paragraph()

    def __format_date_place(self, eventref):
        estr = " "
        event = self.db.get_event_from_handle(eventref.ref)
        if event:
            #e_date = event.get_date_object()
            e_date = self._get_date(event.get_date_object())
            place_handle = event.get_place_handle()
            if place_handle:
                # feature requests 2356, 1657: avoid genitive form
                place_title = _pd.display_event(self.db,
                                                event,
                                                fmt=self.place_fmt)
                estr = (_(" %s in %s") % (e_date, place_title))
                #print(estr)
                #print(_(" %s in ") % e_date, place_title)
            else:
                estr = (_(" %s") % e_date)
        else:
            estr = "leer"
        return estr

    def __add_grampsID_to_index(self, list, person):
        """
        This procedure adds the (gramps_id, _nd(Person)) tuple to person_tuple = tuple()
        """
        list.append((self._nd.display_name(person.get_primary_name()),
                     person.get_gramps_id()))

    def __write_referenced_families(self):
        """
        This procedure writes out each of the families related to the place
        """
        i = 0
        iw = 0
        ifam = 0
        marrevt_handle_list = []
        marr = []
        fam_list = []
        fam_index = {}
        person_index = []
        Patenlist = []
        with self._user.progress(_("PlaceFamily Report"),
                                 _("preparing Dictionaries"),
                                 len(self.place_handles)) as step:

            if self.showgodparents:
                pedic = {}
                pedic = defaultdict(list)
                for pe in self.db.get_person_handles():
                    for eventref in self.db.get_person_from_handle(
                            pe).event_ref_list:
                        if not eventref.get_role().is_primary():
                            pedic[eventref.ref].append(
                                (eventref.get_role(), pe))

            for handle in self.place_handles:
                # first all events
                event_handles = [
                    event_handle
                    for (object_type, event_handle
                         ) in self.db.find_backlink_handles(handle, ['Event'])
                ]
                event_handles.sort(key=self.sort.by_date_key)
                # increment progress bar
                step()

                # only marriage
                for evt_handle in event_handles:
                    if self.db.get_event_from_handle(
                            evt_handle).get_type().is_marriage():
                        marrevt_handle_list.append(evt_handle)
    #            print(len(marrevt_handle_list))
    # no dups
            marr = list(OrderedDict.fromkeys(marrevt_handle_list))
            #        print(len(marr))
            mi = 0

            for evt_handle in marr:
                event = self.db.get_event_from_handle(evt_handle)
                date = self._get_date(event.get_date_object())
                date_sort = event.get_date_object().get_sort_value()
                descr = event.get_description()
                ref_handles = [
                    x for x in self.db.find_backlink_handles(evt_handle)
                ]
                #            print(mi, evt_handle)
                mi += 1
                for (ref_type, ref_handle) in ref_handles:
                    if ref_type == 'Person':
                        continue
                    else:
                        family = self.db.get_family_from_handle(ref_handle)
                        ifam += 1
                        father_handle = family.get_father_handle()
                        # now from the families only fathers
                        if father_handle:
                            fp = self.db.get_person_from_handle(father_handle)
                            father_name = \
                                self._nd.display_name(fp.get_primary_name()).lower()
                        else:
                            father_name = _("unknown")
                        place_d = _pd.display_event(self.db, event)
                        event_details = [
                            father_handle, father_name, date, ref_handle,
                            descr, place_d, family, date_sort
                        ]
                        fam_list.append(event_details)

            fam_index_keys = fam_index.keys()
            printsurname = "NOW"
            index = 0
            for fn in sorted(fam_list,
                             key=lambda t: (locale.strxfrm(t[1]), t[7])):
                index += 1
                fam_index[fn[6].get_gramps_id()] = index
            for fn in sorted(fam_list,
                             key=lambda t: (locale.strxfrm(t[1]), t[7])):
                if fn[0] is None:
                    surname = _("unknown")
                else:
                    surname = self.db.get_person_from_handle(
                        fn[0]).get_primary_name().get_surname()
                if printsurname == surname:
                    pass
                else:
                    #Family Surname
                    printsurname = surname
                    self.doc.start_paragraph("PLC-PlaceTitle")
                    mark = IndexMark(surname, INDEX_TYPE_ALP)

                    self.doc.write_text(surname, mark)
                    self.doc.end_paragraph()
                i += 1
                # weddingdetails
                family = fn[6]
                iw += 1
                self.doc.start_paragraph("PLC-Details")
                self.doc.start_bold()
                #            self.doc.write_text("<%s> " % iw)
                self.doc.write_text(" <%s>" % fam_index[fn[6].gramps_id])
                #            self.doc.write_text("Heirat %s " % fn[1])
                self.doc.write_text("%s " % u'\u26AD')
                self.doc.write_text("%s " % fn[2])
                self.doc.end_bold()
                # wedding place
                self.doc.write_text("in %s." % fn[5])
                # FamID
                self.doc.write_text(" [%s]" % fn[6].gramps_id)
                self.doc.end_paragraph()

                ##################################################
                # fatherdetails
                if fn[6].father_handle:
                    father = self.db.get_person_from_handle(
                        fn[6].father_handle)
                    self.doc.start_paragraph("PLC-PlaceDetails")
                    #given Name
                    self.doc.start_bold()
                    mark = ReportUtils.get_person_mark(self.db, father)
                    text = father.get_primary_name().get_first_name()
                    self.doc.write_text(text, mark)
                    self.doc.write_text(
                        " %s" % father.get_primary_name().get_surname())

                    self.doc.end_bold()
                    self.doc.write_text(" [%s] " % father.get_gramps_id())
                    #ggf familyID
                    for fam in father.get_family_handle_list():
                        if self.db.get_family_from_handle(
                                fam).gramps_id == fn[6].gramps_id:
                            pass
                        else:
                            self.doc.write_text(
                                " [%s]" %
                                self.db.get_family_from_handle(fam).gramps_id)
                            if self.db.get_family_from_handle(
                                    fam).gramps_id in fam_index_keys:
                                self.doc.start_bold()
                                self.doc.write_text(
                                    " <%s>" %
                                    fam_index[self.db.get_family_from_handle(
                                        fam).gramps_id])
                                self.doc.end_bold()
                    self.__add_grampsID_to_index(person_index, father)
                    #birth date
                    birth_ref = father.get_birth_ref()
                    if birth_ref:
                        self.doc.write_text(" *")
                        self.doc.write_text(
                            self.__format_date_place(birth_ref))
        #bapt date
                    for eventref in father.event_ref_list:
                        if eventref.role == EventRoleType.PRIMARY:
                            if self.db.get_event_from_handle(
                                    eventref.ref).get_type(
                                    ) == EventType.BAPTISM:
                                self.doc.write_text(" %s " % u'\u2053')
                                self.doc.write_text(
                                    self.__format_date_place(eventref))
        #death date
                    death_ref = father.get_death_ref()
                    if death_ref:
                        self.doc.write_text(" † ")
                        self.doc.write_text(
                            self.__format_date_place(death_ref))
        #burr date
                    for eventref in father.event_ref_list:
                        if eventref.role == EventRoleType.PRIMARY:
                            if self.db.get_event_from_handle(
                                    eventref.ref).get_type(
                                    ) == EventType.BURIAL:
                                self.doc.write_text("%s " % u'\u26B0')
                                self.doc.write_text(
                                    self.__format_date_place(eventref))
                    self.doc.end_paragraph()
    # motherdetails
#                print(fn[6].gramps_id,fn[6])
                print('            handle', fn[6].mother_handle)

                if fn[6].mother_handle:
                    mother = self.db.get_person_from_handle(
                        fn[6].mother_handle)
                    self.doc.start_paragraph("PLC-PlaceDetails")
                    #given Name
                    self.doc.write_text("und ")
                    self.doc.start_bold()

                    mark = ReportUtils.get_person_mark(self.db, mother)
                    text = mother.get_primary_name().get_surname()
                    self.doc.write_text(text, mark)

                    self.doc.end_bold()
                    self.doc.write_text(
                        " %s " % mother.get_primary_name().get_first_name())
                    self.doc.write_text("[%s] " % mother.get_gramps_id())
                    #ggf familyID
                    for fam in mother.get_family_handle_list():
                        if self.db.get_family_from_handle(
                                fam).gramps_id == fn[6].gramps_id:
                            pass
                        else:
                            self.doc.write_text(
                                " [%s]" %
                                self.db.get_family_from_handle(fam).gramps_id)
                            if self.db.get_family_from_handle(
                                    fam).gramps_id in fam_index_keys:
                                self.doc.start_bold()
                                self.doc.write_text(
                                    " <%s>" %
                                    fam_index[self.db.get_family_from_handle(
                                        fam).gramps_id])
                                self.doc.end_bold()
                    self.__add_grampsID_to_index(person_index, mother)

                    #birth date
                    birth_ref = mother.get_birth_ref()
                    if birth_ref:
                        self.doc.write_text(" *")
                        self.doc.write_text(
                            self.__format_date_place(birth_ref))
        #bapt date
                    for eventref in mother.event_ref_list:
                        if eventref.role == EventRoleType.PRIMARY:
                            if self.db.get_event_from_handle(
                                    eventref.ref).get_type(
                                    ) == EventType.BAPTISM:
                                self.doc.write_text(" %s " % u'\u2053')
                                self.doc.write_text(
                                    self.__format_date_place(eventref))
        #death date
                    death_ref = mother.get_death_ref()
                    if death_ref:
                        self.doc.write_text(" † ")
                        self.doc.write_text(
                            self.__format_date_place(death_ref))
        #burr date
                    for eventref in mother.event_ref_list:
                        if eventref.role == EventRoleType.PRIMARY:
                            if self.db.get_event_from_handle(
                                    eventref.ref).get_type(
                                    ) == EventType.BURIAL:
                                self.doc.write_text("%s " % u'\u26B0')
                                self.doc.write_text(
                                    self.__format_date_place(eventref))
                    self.doc.end_paragraph()

    # Children
                fc = 0
                for ch in fn[6].get_child_ref_list():
                    self.doc.start_paragraph("PLC-PlaceDetailsChildren")
                    fc += 1
                    child = self.db.get_person_from_handle(ch.ref)
                    if child:
                        #lnr
                        self.doc.write_text("     %s " % fc)
                        #given Name
                        mark = ReportUtils.get_person_mark(self.db, child)
                        text = child.get_primary_name().get_first_name()
                        self.doc.write_text(text, mark)
                        self.doc.write_text(" [%s] " % child.get_gramps_id())
                        #ggf familyID
                        for fam in child.get_family_handle_list():
                            if self.db.get_family_from_handle(
                                    fam).gramps_id == fn[6].gramps_id:
                                pass
                            else:
                                self.doc.write_text(
                                    " [%s]" % self.db.get_family_from_handle(
                                        fam).gramps_id)
                                if self.db.get_family_from_handle(
                                        fam).gramps_id in fam_index_keys:
                                    self.doc.start_bold()
                                    self.doc.write_text(" <%s>" % fam_index[
                                        self.db.get_family_from_handle(
                                            fam).gramps_id])
                                    self.doc.end_bold()
                        self.__add_grampsID_to_index(person_index, child)
                        #birth date
                        birth_ref = child.get_birth_ref()
                        if birth_ref:
                            self.doc.write_text(" * ")
                            self.doc.write_text(
                                self.__format_date_place(birth_ref))
        #bapt date
                        for eventref in child.event_ref_list:
                            if eventref.role == EventRoleType.PRIMARY:
                                if self.db.get_event_from_handle(
                                        eventref.ref).get_type(
                                        ) == EventType.BAPTISM:
                                    self.doc.write_text(" %s " % u'\u2053')
                                    self.doc.write_text(
                                        self.__format_date_place(eventref))

                                    if self.showgodparents:
                                        Patenlist = []
                                        Patenlist = pedic[eventref.ref]

        #death date
                        death_ref = child.get_death_ref()
                        if death_ref:
                            self.doc.write_text(" † ")
                            self.doc.write_text(
                                self.__format_date_place(death_ref))
        #burr date
                        for eventref in child.event_ref_list:
                            if eventref.role == EventRoleType.PRIMARY:
                                if self.db.get_event_from_handle(
                                        eventref.ref).get_type(
                                        ) == EventType.BURIAL:
                                    self.doc.write_text("%s " % u'\u26B0')
                                    self.doc.write_text(
                                        self.__format_date_place(eventref))
                        self.doc.end_paragraph()

                        if self.showgodparents:
                            if len(Patenlist) > 0:
                                self.doc.start_paragraph("PLC-Godparents")
                                self.doc.write_text(" Paten: ")
                                for i, (pa_a, pa_b) in enumerate(Patenlist):
                                    self.doc.write_text(" (%s) " % str(i + 1))
                                    pate = self.db.get_person_from_handle(pa_b)
                                    mark = ReportUtils.get_person_mark(
                                        self.db, pate)
                                    self.doc.write_text(
                                        pate.get_primary_name().get_first_name(
                                        ) + " " +
                                        pate.get_primary_name().get_surname(),
                                        mark)
                                self.doc.end_paragraph()
                            Patenlist = []

        person_index = list(set(person_index))
        for (indname, pi) in sorted(person_index):
            print(indname, pi)
            self.doc.start_paragraph("PLC-Details")
            self.doc.write_text("%s  [%s]" % (indname, pi))
            self.doc.end_paragraph()
        self.doc.start_paragraph("PLC-Details")
        self.doc.write_text("Anzahl: %s" % len(person_index))
        self.doc.end_paragraph()
##########

    def __get_place_handles(self, places):
        """
        This procedure converts a string of place GIDs to a list of handles
        """
        place_handles = []
        for place_gid in places.split():
            place = self.db.get_place_from_gramps_id(place_gid)
            if place is not None:
                place_handles.append(place.get_handle())

        return place_handles
class PlaceFamilyReport(Report):
    """
    Place Report class
    """
    def __init__(self, database, options, user):
        """
        Create the PlaceFamilyReport object produces the PlaceFamily report.
       
        The arguments are:

        database        - the GRAMPS database instance
        options         - instance of the Options class for this report
        user            - instance of a gen.user.User class

        This report needs the following parameters (class variables)
        that come in the options class.

        places          - List of places to report on.
#       placeformat     - Format of Place to display
        incpriv         - Whether to include private data
        showgodparents  - Whether to include and show godparents

        """

        Report.__init__(self, database, options, user)

        self._user = user
        menu = options.menu
        places = menu.get_option_by_name('places').get_value()
        self.pl_format = menu.get_option_by_name('placeformat').get_value()
        #U        self.placeformat  = get_value('placeformat')

        self.incpriv = menu.get_option_by_name('incpriv').get_value()

        self.showgodparents = menu.get_option_by_name(
            'showgodparents').get_value()

        self.set_locale(menu.get_option_by_name('trans').get_value())

        name_format = menu.get_option_by_name("name_format").get_value()
        if name_format != 0:
            self._name_display.set_default_format(name_format)
        self._nd = self._name_display

        if self.incpriv:
            self.database = database
        else:
            self.database = PrivateProxyDb(database)

        filter_option = menu.get_option_by_name('filter')
        self.filter = filter_option.get_filter()
        self.sort = Sort(self.database)

        if self.filter.get_name() != '':
            # Use the selected filter to provide a list of place handles
            plist = self.database.iter_place_handles()
            self.place_handles = self.filter.apply(self.database, plist)
        else:
            # Use the place handles selected without a filter
            self.place_handles = self.__get_place_handles(places)

        self.place_handles.sort(key=self.sort.by_place_title_key)

    def write_report(self):
        """
        The routine that actually creates the report.
        At this point, the document is opened and ready for writing.
        """

        # Write the title line. Set in INDEX marker so that this section will be
        # identified as a major category if this is included in a Book report.

        pl_format = self.pl_format
        title = self._("PlaceFamily Report")
        mark = IndexMark(title, INDEX_TYPE_TOC, 1)
        self.doc.start_paragraph("PLC-ReportTitle")
        self.doc.write_text(title, mark)
        self.doc.end_paragraph()

        self.__write_all_places(pl_format)
        self.__write_referenced_families(pl_format)

    def __write_all_places(self, pl_format):
        """
        This procedure writes out each of the selected places.
        """
        place_nbr = 1

        with self._user.progress(_("PlaceFamily Report"),
                                 _("Generating report"),
                                 len(self.place_handles)) as step:

            subtitle = self._("Places")
            mark = IndexMark(subtitle, INDEX_TYPE_TOC, 2)
            self.doc.start_paragraph("PLC-ReportSubtitle")
            self.doc.write_text(subtitle, mark)
            self.doc.end_paragraph()

            self.doc.start_paragraph("PLC-Section")
            self.doc.write_text(
                "Enthält alle Familien mit Hochzeitsereignis in diesem Ort")
            self.doc.end_paragraph()

            for handle in self.place_handles:
                if handle:
                    self.doc.start_paragraph("PLC-Section")
                    printplace = self.database.get_place_from_handle(
                        handle).get_title()

                    indexplace = printplace + " L_INDEX"
                    #                    indexplace = printplace+" ' \f 'O'"
                    mark = IndexMark(indexplace, INDEX_TYPE_ALP)
                    #mark = IndexMark(indexplace, INDEX_TYPE_ALP, iname="HUHUHU")
                    print(mark.key, mark.type, mark.level)
                    self.doc.write_text(printplace, mark)
                    #                    self.doc.write_text(self.database.get_place_from_handle(handle).get_title(),mark)
                    self.doc.end_paragraph()
                place_nbr += 1
                # increment progress bar
                step()

            subtitle = self._("Families")
            mark = IndexMark(subtitle, INDEX_TYPE_TOC, 2)
            self.doc.start_paragraph("PLC-ReportSubtitle")
            self.doc.write_text(subtitle, mark)
            self.doc.end_paragraph()

    def __format_date(self, date_object):
        if not date_object: return
        d = date_object.get_day()
        m = date_object.get_month()
        y = date_object.get_year()
        if (d == 0) and (m == 0):
            date_f = (" %s" % y)
        elif (d == 0) and not (m == 0):
            date_f = (" %s.%s" % (m, y))
        else:
            date_f = (" %s.%s.%s" % (d, m, y))
        return date_f

#    def __format_place(self, place_string, pl_format):
#        if (len(place_string) <=0): return place_string
#        if (pl_format == "default"):
#          # Default
#            place_string = (" in %s " % place_string)
#        elif (pl_format == "one"):
#          # one
#            place_list = place_string.split(',')
#            place_string = (" in %s " % place_list[0].strip())
#        elif (pl_format == "place-country"):
#          # place-country
#            place_list = place_string.split(',')
#            place_string = (" in %s " % place_list[0].strip()+", "+place_list[-1].strip())
#        elif (pl_format == "long"):
#          # long
#            place_string = (" in %s " % place_string)
#        return place_string

    def __write_referenced_families(self, pl_format):
        """
        This procedure writes out each of the families related to the place
        """
        i = 0
        iw = 0
        ifam = 0
        marrevt_handle_list = []
        marr = []
        fam_list = []
        fam_index = {}
        #        Paten_list = []

        if self.showgodparents:
            pedic = {}
            pedic = defaultdict(list)
            for pe in self.database.get_person_handles():
                for eventref in self.database.get_person_from_handle(
                        pe).event_ref_list:
                    if not eventref.get_role().is_primary():
                        pedic[eventref.ref].append((eventref.get_role(), pe))

        with self._user.progress(_("PlaceFamily Report"),
                                 ("Generating report"),
                                 len(self.place_handles)) as step:

            for handle in self.place_handles:
                # first all events
                event_handles = [
                    event_handle for (object_type, event_handle) in
                    self.database.find_backlink_handles(handle, ['Event'])
                ]
                event_handles.sort(key=self.sort.by_date_key)
                # only marriage
                for evt_handle in event_handles:
                    if self.database.get_event_from_handle(
                            evt_handle).get_type().is_marriage():
                        marrevt_handle_list.append(evt_handle)
    # no dups
            marr = list(OrderedDict.fromkeys(marrevt_handle_list))
            #        print(len(marr))
            mi = 0
            for evt_handle in marr:
                event = self.database.get_event_from_handle(evt_handle)
                date = self._get_date(event.get_date_object())
                date_sort = event.get_date_object().get_sort_value()
                descr = event.get_description()
                #                event_type = self._(self._get_type(event.get_type()))
                #                event_place = event.place
                ref_handles = [
                    x for x in self.database.find_backlink_handles(evt_handle)
                ]
                #            print(mi, evt_handle)
                mi += 1
                for (ref_type, ref_handle) in ref_handles:
                    if ref_type == 'Person':
                        continue
                    else:
                        family = self.database.get_family_from_handle(
                            ref_handle)
                        ifam += 1
                        father_handle = family.get_father_handle()
                        # now from the families only fathers
                        if father_handle:
                            fp = self.database.get_person_from_handle(
                                father_handle)
                            father_name = \
                                self._name_display.display_name(fp.get_primary_name()).lower()
                        else:
                            father_name = _("unknown")
                        place_d = place_displayer.display_event(
                            self.database, event, pl_format)
                        #                        print(place_d)
                        event_details = [
                            father_handle, father_name, date, ref_handle,
                            descr, place_d, family, date_sort
                        ]
                        fam_list.append(event_details)

    #        print(sorted(fam_list, key=itemgetter(1,7)))
    #        print(len(fam_list))
            printsurname = "NOW"
            index = 0
            ##########################
            #for fn in sorted(fam_list, key=itemgetter(1,7)):

            #fam_list_name
            # TEST FOR SORTING
            #            lastnames = ["Bange", "Änger", "Amman", "Änger", "Zelch", "Ösbach"]
            #            print(sorted(lastnames, key=locale.strxfrm))
            #            print()
            #
            #            lastnames_firstnames_groups =[
            #                ["Bange", "Michael", 2],
            #                ["Änger", "Ämma", 2],
            #                ["Amman", "Anton", 1],
            #                ["Änger", "Chris", 2],
            #                ["Zelch", "Sven", 1],
            #                ["Ösbach", "Carl", 1]
            #            ]
            #            print(sorted(lastnames_firstnames_groups, key=operator.itemgetter(2,0,1)))
            #            print(
            #                sorted(
            #                    lastnames_firstnames_groups,
            #                    key=lambda t: (t[2], locale.strxfrm(t[0]), locale.strxfrm(t[1]))
            #                )
            #            )
            #**************************
            for fn in sorted(fam_list,
                             key=lambda t: (locale.strxfrm(t[1]), t[7])):
                index += 1
                fam_index[fn[6].get_gramps_id()] = index
    #            print(index)
    #        for ifn in fam_index.keys():
    #            print(ifn, fam_index[ifn])
            fam_index_keys = fam_index.keys()

            for fn in sorted(fam_list,
                             key=lambda t: (locale.strxfrm(t[1]), t[7])):
                if fn[0] is None:
                    surname = _("unknown")
                else:
                    surname = self.database.get_person_from_handle(
                        fn[0]).get_primary_name().get_surname()
    #            print(fn[0], surname)
                if printsurname == surname:
                    pass
                else:
                    #Family Surname
                    printsurname = surname
                    #                  S_Name = ("%s " % surname)
                    #                    mark = IndexMark(S_Name, INDEX_TYPE_TOC, 1)
                    self.doc.start_paragraph("PLC-PlaceTitle")
                    # self.doc.write_text("%s " % surname)

                    #   mark = ReportUtils.get_person_mark(self.database,surname)

                    #                    mark = IndexMark( surname, INDEX_TYPE_ALP )
                    #                    indexname = surname+" P_INDEX"
                    indexname = surname + " P_INDEX"
                    mark = IndexMark(indexname, INDEX_TYPE_ALP, 2)

                    self.doc.write_text(surname, mark)
                    self.doc.end_paragraph()
                i += 1
                # weddingdetails
                family = fn[6]
                iw += 1
                self.doc.start_paragraph("PLC-Details")
                self.doc.start_bold()
                #            self.doc.write_text("<%s> " % iw)
                self.doc.write_text(" <%s>" % fam_index[fn[6].gramps_id])
                #            self.doc.write_text("Heirat %s " % fn[1])
                self.doc.write_text("%s " % u'\u26AD')
                self.doc.write_text("%s " % fn[2])
                self.doc.end_bold()

                # increment progress bar
                step()

                #given Name
                # wedding place
                #UINDEX                self.doc.write_text(" %s." % fn[5]+" P_INDEX"+" LLL")
                self.doc.write_text(" %s." % fn[5])
                # FamID
                self.doc.write_text(" [%s]" % fn[6].gramps_id)
                self.doc.end_paragraph()

                ##################################################
                # fatherdetails
                father = self.database.get_person_from_handle(
                    fn[6].father_handle)
                if father:
                    self.doc.start_paragraph("PLC-PlaceDetails")
                    #given Name
                    self.doc.start_bold()
                    #    self.doc.write_text("%s " % father.get_primary_name().get_first_name())
                    mark = ReportUtils.get_person_mark(self.database, father)
                    text = father.get_primary_name().get_first_name()
                    self.doc.write_text(text, mark)
                    self.doc.write_text(
                        " %s" % father.get_primary_name().get_surname())

                    self.doc.end_bold()
                    self.doc.write_text("[%s] " % father.get_gramps_id())
                    #ggf familyID
                    for fam in father.get_family_handle_list():
                        if self.database.get_family_from_handle(
                                fam).gramps_id == fn[6].gramps_id:
                            pass
                        else:
                            self.doc.write_text(
                                " [%s]" % self.database.get_family_from_handle(
                                    fam).gramps_id)
                            if self.database.get_family_from_handle(
                                    fam).gramps_id in fam_index_keys:
                                self.doc.start_bold()
                                self.doc.write_text(" <%s>" % fam_index[
                                    self.database.get_family_from_handle(
                                        fam).gramps_id])
                                self.doc.end_bold()

    #birth date
                    birth_ref = father.get_birth_ref()
                    if birth_ref:
                        # erst event
                        birth_event = self.database.get_event_from_handle(
                            birth_ref.ref)
                        self.doc.write_text(" * ")
                        self.doc.write_text(
                            self.__format_date(birth_event.get_date_object()))
                        #birth place
                        # dann display place
                        #P                       print("HIER")
                        #p                       print(place_displayer.display_event(self.database, birth_event, pl_format))
                        self.doc.write_text(
                            " " + place_displayer.display_event(
                                self.database, birth_event, pl_format))
        #bapt date
                    for eventref in father.event_ref_list:
                        if eventref.role == EventRoleType.PRIMARY:
                            if self.database.get_event_from_handle(
                                    eventref.ref).get_type(
                                    ) == EventType.BAPTISM:
                                # erst event
                                bapt_event = self.database.get_event_from_handle(
                                    eventref.ref)
                                self.doc.write_text(" %s " % u'\u2053')
                                self.doc.write_text(
                                    self.__format_date(
                                        bapt_event.get_date_object()))
                                #bapt place
                                #        # erst event
                                bapt_event = self.database.get_event_from_handle(
                                    eventref.ref)
                                # dann display place
                                self.doc.write_text(
                                    " " + place_displayer.display_event(
                                        self.database, bapt_event, pl_format))

        #death date
                    death_ref = father.get_death_ref()
                    if death_ref:
                        # erst event
                        death_event = self.database.get_event_from_handle(
                            death_ref.ref)
                        self.doc.write_text(" † ")
                        self.doc.write_text(
                            self.__format_date(death_event.get_date_object()))
                        #death place
                        self.doc.write_text(
                            " " + place_displayer.display_event(
                                self.database, death_event, pl_format))

        #burr date
                    for eventref in father.event_ref_list:
                        if eventref.role == EventRoleType.PRIMARY:
                            if self.database.get_event_from_handle(
                                    eventref.ref).get_type(
                                    ) == EventType.BURIAL:
                                # erst event
                                burr_event = self.database.get_event_from_handle(
                                    eventref.ref)
                                self.doc.write_text("%s " % u'\u26B0')
                                self.doc.write_text(
                                    self.__format_date(
                                        burr_event.get_date_object()))
                                #burr place
                                # dann display place
                                self.doc.write_text(
                                    " " + place_displayer.display_event(
                                        self.database, burr_event, pl_format))
                    self.doc.end_paragraph()

    ############################################################
    # motherdetails
                mother = self.database.get_person_from_handle(
                    fn[6].mother_handle)
                if mother:
                    self.doc.start_paragraph("PLC-PlaceDetails")
                    #given Name
                    self.doc.write_text("und ")
                    self.doc.start_bold()

                    mark = ReportUtils.get_person_mark(self.database, mother)
                    text = mother.get_primary_name().get_surname()
                    self.doc.write_text(text, mark)

                    #         self.doc.write_text("%s, " % mother.get_primary_name().get_surname())
                    self.doc.end_bold()
                    self.doc.write_text(
                        " %s " % mother.get_primary_name().get_first_name())
                    self.doc.write_text("[%s] " % mother.get_gramps_id())
                    #ggf familyID
                    for fam in mother.get_family_handle_list():
                        if self.database.get_family_from_handle(
                                fam).gramps_id == fn[6].gramps_id:
                            pass
                        else:
                            self.doc.write_text(
                                " [%s]" % self.database.get_family_from_handle(
                                    fam).gramps_id)
                            if self.database.get_family_from_handle(
                                    fam).gramps_id in fam_index_keys:
                                self.doc.start_bold()
                                self.doc.write_text(" <%s>" % fam_index[
                                    self.database.get_family_from_handle(
                                        fam).gramps_id])
                                self.doc.end_bold()

    #birth date
                    birth_ref = mother.get_birth_ref()
                    if birth_ref:
                        # erst event
                        birth_event = self.database.get_event_from_handle(
                            birth_ref.ref)
                        self.doc.write_text(" * ")
                        self.doc.write_text(
                            self.__format_date(birth_event.get_date_object()))
                        #birth place
                        # dann display place
                        place_string = place_displayer.display_event(
                            self.database, birth_event, pl_format)
                        self.doc.write_text(" " + place_string)

        #bapt date
                    for eventref in mother.event_ref_list:
                        if eventref.role == EventRoleType.PRIMARY:
                            if self.database.get_event_from_handle(
                                    eventref.ref).get_type(
                                    ) == EventType.BAPTISM:
                                # erst event
                                bapt_event = self.database.get_event_from_handle(
                                    eventref.ref)

                                self.doc.write_text(" %s " % u'\u2053')
                                self.doc.write_text(
                                    self.__format_date(
                                        bapt_event.get_date_object()))
                                #bapt place
                                # dann display place
                                place_string = place_displayer.display_event(
                                    self.database, bapt_event, pl_format)
                                self.doc.write_text(" " + place_string)

        #death date
                    death_ref = mother.get_death_ref()
                    if death_ref:
                        # erst event
                        death_event = self.database.get_event_from_handle(
                            death_ref.ref)
                        self.doc.write_text(" † ")
                        self.doc.write_text(
                            self.__format_date(death_event.get_date_object()))
                        #death place
                        place_string = place_displayer.display_event(
                            self.database, death_event, pl_format)
                        self.doc.write_text(" " + place_string)

        #burr date
                    for eventref in mother.event_ref_list:
                        if eventref.role == EventRoleType.PRIMARY:
                            if self.database.get_event_from_handle(
                                    eventref.ref).get_type(
                                    ) == EventType.BURIAL:
                                # erst event
                                burr_event = self.database.get_event_from_handle(
                                    eventref.ref)
                                self.doc.write_text("%s " % u'\u26B0')
                                self.doc.write_text(
                                    self.__format_date(
                                        burr_event.get_date_object()))
                                #burr place
                                # dann display place
                                place_string = place_displayer.display_event(
                                    self.database, burr_event, pl_format)
                                self.doc.write_text(" " + place_string)
                    self.doc.end_paragraph()

    ############################################################
    # Children

                fc = 0
                for ch in fn[6].get_child_ref_list():
                    self.doc.start_paragraph("PLC-PlaceDetailsChildren")
                    fc += 1
                    child = self.database.get_person_from_handle(ch.ref)
                    if child:
                        #lnr
                        self.doc.write_text("     %s " % fc)
                        #given Name
                        mark = ReportUtils.get_person_mark(
                            self.database, child)
                        text = child.get_primary_name().get_first_name()
                        self.doc.write_text(text, mark)
                        #             self.doc.write_text("%s " % child.get_primary_name().get_first_name())
                        self.doc.write_text("[%s] " % child.get_gramps_id())
                        #ggf familyID
                        for fam in child.get_family_handle_list():
                            if self.database.get_family_from_handle(
                                    fam).gramps_id == fn[6].gramps_id:
                                pass
                            else:
                                self.doc.write_text(
                                    " [%s]" %
                                    self.database.get_family_from_handle(
                                        fam).gramps_id)
                                if self.database.get_family_from_handle(
                                        fam).gramps_id in fam_index_keys:
                                    self.doc.start_bold()
                                    self.doc.write_text(" <%s>" % fam_index[
                                        self.database.get_family_from_handle(
                                            fam).gramps_id])
                                    self.doc.end_bold()

            #birth date

                        birth_ref = child.get_birth_ref()
                        if birth_ref:
                            # erst event
                            birth_event = self.database.get_event_from_handle(
                                birth_ref.ref)
                            self.doc.write_text(" * ")
                            self.doc.write_text(
                                self.__format_date(
                                    birth_event.get_date_object()))
                            #birth place
                            place_string = place_displayer.display_event(
                                self.database, birth_event, pl_format)
                            self.doc.write_text(" " + place_string)

            #bapt date
                        for eventref in child.event_ref_list:
                            if eventref.role == EventRoleType.PRIMARY:
                                if self.database.get_event_from_handle(
                                        eventref.ref).get_type(
                                        ) == EventType.BAPTISM:
                                    # erst event
                                    bapt_event = self.database.get_event_from_handle(
                                        eventref.ref)

                                    self.doc.write_text(" %s " % u'\u2053')
                                    self.doc.write_text(
                                        self.__format_date(
                                            bapt_event.get_date_object()))
                                    #bapt place
                                    # dann display place
                                    place_string = place_displayer.display_event(
                                        self.database, bapt_event, pl_format)
                                    self.doc.write_text(" " + place_string)

                                    if self.showgodparents:
                                        Patenlist = []
                                        Patenlist = pedic[eventref.ref]
            #death date
                        death_ref = child.get_death_ref()
                        if death_ref:
                            # erst event
                            death_event = self.database.get_event_from_handle(
                                death_ref.ref)
                            self.doc.write_text(" † ")
                            self.doc.write_text(
                                self.__format_date(
                                    death_event.get_date_object()))
                            #death place
                            # dann display place
                            place_string = place_displayer.display_event(
                                self.database, death_event, pl_format)
                            self.doc.write_text(" " + place_string)

            #burr date
                        for eventref in child.event_ref_list:
                            if eventref.role == EventRoleType.PRIMARY:
                                if self.database.get_event_from_handle(
                                        eventref.ref).get_type(
                                        ) == EventType.BURIAL:
                                    # erst event
                                    burr_event = self.database.get_event_from_handle(
                                        eventref.ref)
                                    self.doc.write_text("%s " % u'\u26B0')
                                    self.doc.write_text(
                                        self.__format_date(
                                            burr_event.get_date_object()))
                                    #burr place
                                    # dann display place
                                    place_string = place_displayer.display_event(
                                        self.database, burr_event, pl_format)
                                    # dann drucken
                                    self.doc.write_text(" " + place_string)
                        self.doc.end_paragraph()

                        #                       print(len(Patenlist))
                        if self.showgodparents:
                            if len(Patenlist) > 0:
                                self.doc.start_paragraph("PLC-Godparents")
                                self.doc.write_text(" Paten: ")
                                for i, (pa_a, pa_b) in enumerate(Patenlist):
                                    self.doc.write_text(" (%s) " % str(i + 1))
                                    pate_name = self.database.get_person_from_handle(
                                        pa_b
                                    ).get_primary_name().get_first_name(
                                    ) + " " + self.database.get_person_from_handle(
                                        pa_b).get_primary_name().get_surname()
                                    pate = self.database.get_person_from_handle(
                                        pa_b)
                                    #                                    print(pate, pate_name)
                                    mark = ReportUtils.get_person_mark(
                                        self.database, pate)
                                    self.doc.write_text(
                                        pate.get_primary_name().get_first_name(
                                        ) + " " +
                                        pate.get_primary_name().get_surname(),
                                        mark)
                                self.doc.end_paragraph()
                                Patenlist = []

        #        print(ifam, "family")

    def __get_place_handles(self, places):
        """
        This procedure converts a string of place GIDs to a list of handles
        """
        place_handles = []
        for place_gid in places.split():
            place = self.database.get_place_from_gramps_id(place_gid)
            if place is not None:
                place_handles.append(place.get_handle())

        return place_handles
class PlaceFamilyReport(Report):
    """
    Place Report class
    """
    def __init__(self, database, options, user):
        """
        Create the PlaceFamilyReport object produces the PlaceFamily report.
        
        The arguments are:

        database        - the GRAMPS database instance
        options         - instance of the Options class for this report
        user            - instance of a gen.user.User class

        This report needs the following parameters (class variables)
        that come in the options class.
        
        places          - List of places to report on.
#        center         - Center of report, person or event
        incpriv         - Whether to include private data
        showgodparents  - Whether to include and show godparents

        """

        Report.__init__(self, database, options, user)

        self._user = user
        menu = options.menu
        places = menu.get_option_by_name('places').get_value()
#        self.center  = menu.get_option_by_name('center').get_value()
        self.incpriv = menu.get_option_by_name('incpriv').get_value()
        self.showgodparents = menu.get_option_by_name('showgodparents').get_value()

        self.set_locale(menu.get_option_by_name('trans').get_value())

        name_format = menu.get_option_by_name("name_format").get_value()
        if name_format != 0:
            self._name_display.set_default_format(name_format)
        self._nd = self._name_display

        if self.incpriv:
            self.database = database
        else:
            self.database = PrivateProxyDb(database)

        filter_option = menu.get_option_by_name('filter')
        self.filter = filter_option.get_filter()
        self.sort = Sort(self.database)

        if self.filter.get_name() != '':
            # Use the selected filter to provide a list of place handles
            plist = self.database.iter_place_handles()
            self.place_handles = self.filter.apply(self.database, plist)
        else:
            # Use the place handles selected without a filter
            self.place_handles = self.__get_place_handles(places)

        self.place_handles.sort(key=self.sort.by_place_title_key)

    def write_report(self):
        """
        The routine that actually creates the report.
        At this point, the document is opened and ready for writing.
        """

        # Write the title line. Set in INDEX marker so that this section will be
        # identified as a major category if this is included in a Book report.

        title = self._("PlaceFamily Report")
        mark = IndexMark(title, INDEX_TYPE_TOC, 1)        
        self.doc.start_paragraph("PLC-ReportTitle")
        self.doc.write_text(title, mark)
        self.doc.end_paragraph()
        
        self.__write_all_places()
        self.__write_referenced_families()

    def __write_all_places(self):
        """
        This procedure writes out each of the selected places.
        """
        place_nbr = 1

        with self._user.progress(_("PlaceFamily Report"), 
                                  _("Generating report"), 
                                  len(self.place_handles)) as step:

            subtitle = self._("Places")
            mark = IndexMark(subtitle, INDEX_TYPE_TOC, 2)        
            self.doc.start_paragraph("PLC-ReportSubtitle")
            self.doc.write_text(subtitle, mark)
            self.doc.end_paragraph()
    
            self.doc.start_paragraph("PLC-Section")
            self.doc.write_text("Enthält alle Familien mit Hochzeitsereignis in diesem Ort")
            self.doc.end_paragraph()
    
            for handle in self.place_handles:
                if handle:
                    self.doc.start_paragraph("PLC-Section")
                    self.doc.write_text(self.database.get_place_from_handle(handle).get_title())
                    self.doc.end_paragraph()
                place_nbr += 1
                # increment progress bar
                step()

            subtitle = self._("Families")
            mark = IndexMark(subtitle, INDEX_TYPE_TOC, 2)        
            self.doc.start_paragraph("PLC-ReportSubtitle")
            self.doc.write_text(subtitle, mark)
            self.doc.end_paragraph()

           
    def __format_date(self, date_object):
        if not date_object: return
        d=date_object.get_day()    
        m=date_object.get_month()
        y=date_object.get_year()
        if (d == 0) and (m == 0):
            date_f = (" %s" % y)
        elif (d == 0) and not (m == 0):
            date_f = (" %s.%s" % (m, y))  
        else:       
            date_f = (" %s.%s.%s" % (d, m, y)) 
        return date_f           
        

    def __write_referenced_families(self):
        """
        This procedure writes out each of the families related to the place
        """
        i = 0
        iw = 0
        ifam = 0
        marrevt_handle_list =[]
        marr =[]
        fam_list=[]
        fam_index={}
        Paten_list =[]

        if self.showgodparents:
            pedic ={}
            pedic = defaultdict(list)
            for pe in self.database.get_person_handles():
                for eventref in self.database.get_person_from_handle(pe).event_ref_list:
                    if not eventref.get_role().is_primary():
                        pedic[eventref.ref].append((eventref.get_role(),pe))

        with self._user.progress(_("PlaceFamily Report"), 
                                  _("Generating report"), 
                                  len(self.place_handles)) as step:
                                  


    
    
    
            for handle in self.place_handles:        
    # first all events
                  
                event_handles = [event_handle for (object_type, event_handle) in
                                 self.database.find_backlink_handles(handle, ['Event'])]
                event_handles.sort(key=self.sort.by_date_key)
        
#                if event_handles:
#                    self.doc.start_paragraph("PLC-Section")
#                    self.doc.write_text(self.database.get_place_from_handle(handle).get_title())
#                    self.doc.end_paragraph()
#    #            print(len(event_handles))
    
    # only marriage            
                for evt_handle in event_handles:
                    if self.database.get_event_from_handle(evt_handle).get_type().is_marriage():
                        marrevt_handle_list.append(evt_handle)
    #            print(len(marrevt_handle_list))
    # no dups            
            marr = list(OrderedDict.fromkeys(marrevt_handle_list))
    #        print(len(marr))
            mi = 0    
            for evt_handle in marr:
                event = self.database.get_event_from_handle(evt_handle)
                date = self._get_date(event.get_date_object())
                date_sort = event.get_date_object().get_sort_value()
                descr = event.get_description()
                event_type = self._(self._get_type(event.get_type()))
                event_place = event.place 
                ref_handles = [x for x in
                               self.database.find_backlink_handles(evt_handle)]
    #            print(mi, evt_handle)
                mi += 1
                for (ref_type, ref_handle) in ref_handles:
                    if ref_type == 'Person':
                        continue
                    else:
                        family = self.database.get_family_from_handle(ref_handle)
                        ifam +=1
                        father_handle = family.get_father_handle()
        # now from the families only fathers
                        if father_handle:
                            fp = self.database.get_person_from_handle(father_handle)
                            father_name = \
                                self._name_display.display_name(fp.get_primary_name()).lower()
                        else:
                            father_name = _("unknown")
                        place_d = place_displayer.display_event(self.database, event)                                        
                        event_details = [ father_handle, father_name, date, ref_handle, descr, place_d, family, date_sort]
                        fam_list.append(event_details)
    
                                                     
    #        print(sorted(fam_list, key=itemgetter(1,7)))
    #        print(len(fam_list))
            printsurname = "NOW"
            index=0
            for fn in sorted(fam_list, key=itemgetter(1,7)):
                index +=1
                fam_index[fn[6].get_gramps_id()]=index
    #            print(index)
    #        for ifn in fam_index.keys():
    #            print(ifn, fam_index[ifn])
            fam_index_keys = fam_index.keys()
    
    
            for fn in sorted(fam_list, key=itemgetter(1,7)):
                if fn[0] is None:
                    surname = _("unknown")
                else:
                    surname = self.database.get_person_from_handle(fn[0]).get_primary_name().get_surname()
    #            print(fn[0], surname)
                if printsurname == surname:
                    pass
                else:
        #Family Surname
                    printsurname = surname
  #                  S_Name = ("%s " % surname)
#                    mark = IndexMark(S_Name, INDEX_TYPE_TOC, 1) 
                    self.doc.start_paragraph("PLC-PlaceTitle")
                   # self.doc.write_text("%s " % surname)
                    
                 #   mark = ReportUtils.get_person_mark(self.database,surname)
                    
                    mark = IndexMark( surname, INDEX_TYPE_ALP )
                    
                    self.doc.write_text(surname,mark)
                    self.doc.end_paragraph()                              
                i +=1
    # weddingdetails
                family = fn[6]
                iw += 1
                self.doc.start_paragraph("PLC-Details")
                self.doc.start_bold()
    #            self.doc.write_text("<%s> " % iw)
                self.doc.write_text(" <%s>" % fam_index[fn[6].gramps_id])
    #            self.doc.write_text("Heirat %s " % fn[1])
                self.doc.write_text("%s " % u'\u26AD')
                self.doc.write_text("%s " % fn[2])
                self.doc.end_bold()

                # increment progress bar
                step()
    
    #given Name
    # wedding place
                self.doc.write_text("in %s." % fn[5])
    # FamID            
                self.doc.write_text(" [%s]" % fn[6].gramps_id)        
                self.doc.end_paragraph()
    
    ##################################################
    # fatherdetails
                father = self.database.get_person_from_handle(fn[6].father_handle)
                if father:
                    self.doc.start_paragraph("PLC-PlaceDetails")
    #given Name
                    self.doc.start_bold()
                #    self.doc.write_text("%s " % father.get_primary_name().get_first_name())
                    mark = ReportUtils.get_person_mark(self.database,father)
                    text = father.get_primary_name().get_first_name()
                    self.doc.write_text(text,mark)
                    self.doc.write_text(" %s" % father.get_primary_name().get_surname())
                    
                    self.doc.end_bold()
                    self.doc.write_text("[%s] " % father.get_gramps_id())
    #ggf familyID
                    for fam in father.get_family_handle_list():
                        if self.database.get_family_from_handle(fam).gramps_id == fn[6].gramps_id:
                            pass
                        else:
                            self.doc.write_text(" [%s]" % self.database.get_family_from_handle(fam).gramps_id)
                            if self.database.get_family_from_handle(fam).gramps_id in fam_index_keys:
                                self.doc.start_bold()
                                self.doc.write_text(" <%s>" % fam_index[self.database.get_family_from_handle(fam).gramps_id])
                                self.doc.end_bold()
    
    #birth date
                    birth_ref = father.get_birth_ref()
                    if birth_ref:
                        self.doc.write_text(" * ")
                        self.doc.write_text(self.__format_date(self.database.get_event_from_handle(birth_ref.ref).get_date_object()))
    
        #birth place
                        place_handle = self.database.get_event_from_handle(birth_ref.ref).get_place_handle()
                        if place_handle:
                            birth_place_string = self.database.get_place_from_handle(
                                           place_handle).get_title()
                            self.doc.write_text(" in %s " % birth_place_string)
        #bapt date
                    for eventref in father.event_ref_list:
                        if eventref.role == EventRoleType.PRIMARY:
                            if self.database.get_event_from_handle(eventref.ref).get_type() == EventType.BAPTISM:
                                self.doc.write_text(" %s " % u'\u2053')
                                self.doc.write_text(self.__format_date(self.database.get_event_from_handle(eventref.ref).get_date_object()))
        #bapt place
                                place_handle = self.database.get_event_from_handle(eventref.ref).get_place_handle()
                                if place_handle:
                                    bapt_place_string = self.database.get_place_from_handle(
                                                                        place_handle).get_title()
                                    self.doc.write_text(" in %s " % bapt_place_string)
        #death date
                    death_ref = father.get_death_ref()
                    if death_ref:
                        self.doc.write_text(" † ")
                        self.doc.write_text(self.__format_date(self.database.get_event_from_handle(death_ref.ref).get_date_object()))
        #death place
                        place_handle = self.database.get_event_from_handle(death_ref.ref).get_place_handle()
                        if place_handle:
                            death_place_string = self.database.get_place_from_handle(
                                           place_handle).get_title()
                            self.doc.write_text(" in %s " % death_place_string)
        #burr date
                    for eventref in father.event_ref_list:
                        if eventref.role == EventRoleType.PRIMARY:
                            if self.database.get_event_from_handle(eventref.ref).get_type() == EventType.BURIAL:
                                self.doc.write_text("%s " % u'\u26B0')
                                self.doc.write_text(self.__format_date(self.database.get_event_from_handle(eventref.ref).get_date_object()))
    
        #burr place
                                place_handle = self.database.get_event_from_handle(eventref.ref).get_place_handle()
                                if place_handle:
                                    bur_place_string = self.database.get_place_from_handle(
                                                                        place_handle).get_title()
                                    self.doc.write_text(" in %s " % bur_place_string)
                    self.doc.end_paragraph()
                
    ############################################################
    # motherdetails
                mother = self.database.get_person_from_handle(fn[6].mother_handle)
                if mother:
                    self.doc.start_paragraph("PLC-PlaceDetails")                 
        #given Name
                    self.doc.write_text("und ")
                    self.doc.start_bold()
              
                    mark = ReportUtils.get_person_mark(self.database,mother)
                    text = mother.get_primary_name().get_surname()
                    self.doc.write_text(text,mark)
              
           #         self.doc.write_text("%s, " % mother.get_primary_name().get_surname())
                    self.doc.end_bold()
                    self.doc.write_text(" %s " % mother.get_primary_name().get_first_name())
                    self.doc.write_text("[%s] " % mother.get_gramps_id())
        #ggf familyID
                    for fam in mother.get_family_handle_list():
                        if self.database.get_family_from_handle(fam).gramps_id == fn[6].gramps_id:
                            pass
                        else:
                            self.doc.write_text(" [%s]" % self.database.get_family_from_handle(fam).gramps_id)
                            if self.database.get_family_from_handle(fam).gramps_id in fam_index_keys:
                                self.doc.start_bold()
                                self.doc.write_text(" <%s>" % fam_index[self.database.get_family_from_handle(fam).gramps_id])
                                self.doc.end_bold()
    
                    birth_ref = mother.get_birth_ref()
                    if birth_ref:
                        self.doc.write_text(" * ")
                        self.doc.write_text(self.__format_date(self.database.get_event_from_handle(birth_ref.ref).get_date_object()))
    
        #birth place
                        place_handle = self.database.get_event_from_handle(birth_ref.ref).get_place_handle()
                        if place_handle:
                            birth_place_string = self.database.get_place_from_handle(
                                           place_handle).get_title()
                            self.doc.write_text(" in %s " % birth_place_string)
        #bapt date
                    for eventref in mother.event_ref_list:
                        if eventref.role == EventRoleType.PRIMARY:
                            if self.database.get_event_from_handle(eventref.ref).get_type() == EventType.BAPTISM:
                                self.doc.write_text(" %s " % u'\u2053')
                                self.doc.write_text(self.__format_date(self.database.get_event_from_handle(eventref.ref).get_date_object()))
    
        #bapt place
                                place_handle = self.database.get_event_from_handle(eventref.ref).get_place_handle()
                                if place_handle:
                                    bapt_place_string = self.database.get_place_from_handle(
                                                                          place_handle).get_title()
                                    self.doc.write_text(" in %s " % bapt_place_string)
        #death date
                    death_ref = mother.get_death_ref()
                    if death_ref:
                        self.doc.write_text(" † ")
                        self.doc.write_text(self.__format_date(self.database.get_event_from_handle(death_ref.ref).get_date_object()))
    
        #death place
                        place_handle = self.database.get_event_from_handle(death_ref.ref).get_place_handle()
                        if place_handle:
                            death_place_string = self.database.get_place_from_handle(
                                           place_handle).get_title()
                            self.doc.write_text(" in %s " % death_place_string)
        #burr date
                    for eventref in mother.event_ref_list:
                        if eventref.role == EventRoleType.PRIMARY:
                            if self.database.get_event_from_handle(eventref.ref).get_type() == EventType.BURIAL:
                                self.doc.write_text("%s " % u'\u26B0')
                                self.doc.write_text(self.__format_date(self.database.get_event_from_handle(eventref.ref).get_date_object())) 
        #burr place
                                place_handle = self.database.get_event_from_handle(eventref.ref).get_place_handle()
                                if place_handle:
                                    bur_place_string = self.database.get_place_from_handle(
                                                                        place_handle).get_title()
                                    self.doc.write_text(" in %s " % bur_place_string)
                    self.doc.end_paragraph()
                
    ############################################################
    # Children
    
                fc = 0
                for ch in fn[6].get_child_ref_list():
                    self.doc.start_paragraph("PLC-PlaceDetailsChildren")
                    fc +=1
                    child = self.database.get_person_from_handle(ch.ref)
                    if child:
        #lnr
                        self.doc.write_text("     %s " % fc)
        #given Name
                        mark = ReportUtils.get_person_mark(self.database, child)
                        text = child.get_primary_name().get_first_name()
                        self.doc.write_text(text, mark)
           #             self.doc.write_text("%s " % child.get_primary_name().get_first_name())
                        self.doc.write_text("[%s] " % child.get_gramps_id())
        #ggf familyID
                        for fam in child.get_family_handle_list():
                            if self.database.get_family_from_handle(fam).gramps_id == fn[6].gramps_id:
                                pass
                            else:
                                self.doc.write_text(" [%s]" % self.database.get_family_from_handle(fam).gramps_id)
                                if self.database.get_family_from_handle(fam).gramps_id in fam_index_keys:
                                    self.doc.start_bold()
                                    self.doc.write_text(" <%s>" % fam_index[self.database.get_family_from_handle(fam).gramps_id])
                                    self.doc.end_bold()
        
        #birth date
                        birth_ref = child.get_birth_ref()
                        if birth_ref:
                            self.doc.write_text(" * ")                                
                            self.doc.write_text(self.__format_date(self.database.get_event_from_handle(birth_ref.ref).get_date_object()))
        #birth place
                            place_handle = self.database.get_event_from_handle(birth_ref.ref).get_place_handle()
                            if place_handle:
                                birth_place_string = self.database.get_place_from_handle(
                                               place_handle).get_title()
                                self.doc.write_text(" in %s " % birth_place_string)
        #bapt date
                        for eventref in child.event_ref_list:
                            if eventref.role == EventRoleType.PRIMARY:
                                if self.database.get_event_from_handle(eventref.ref).get_type() == EventType.BAPTISM:
                                    BaptEvt = self.database.get_event_from_handle(eventref.ref)
                                    self.doc.write_text(" %s " % u'\u2053')
                                    self.doc.write_text(self.__format_date(self.database.get_event_from_handle(eventref.ref).get_date_object()))
        #bapt place
                                    place_handle = self.database.get_event_from_handle(eventref.ref).get_place_handle()
                                    if place_handle:
                                        bapt_place_string = self.database.get_place_from_handle(
                                                                            place_handle).get_title()
                                        self.doc.write_text(" in %s " % bapt_place_string)
     
                                    if self.showgodparents:
                                        Patenlist = []
#                                        if len(pedic[eventref.ref])>0:
#                 #                           self.doc.start_superscript()
#                 #                           self.doc.write_text(" Paten: ")
#                                            for i,(pa_a,pa_b) in  enumerate(pedic[eventref.ref]):
#                 #                               self.doc.write_text(" (%s) " % str(i+1))
#               #                                 pate_name = self.database.get_person_from_handle(pa_b).get_primary_name().get_first_name() +" "+ self.database.get_person_from_handle(pa_b).get_primary_name().get_surname() 
#                                                pate = self.database.get_person_from_handle(pa_b) 
#    
#                 #                               mark = ReportUtils.get_person_mark(self.database, pate)
#                 #                               text = self.database.get_person_from_handle(pa_b).get_primary_name().get_first_name() +" "+ self.database.get_person_from_handle(pa_b).get_primary_name().get_surname() 
#    
#                 #                               self.doc.write_text(text, mark)
#                                  #             self.doc.write_text("%s " % child.get_primary_name().get_first_name())
#                 #                               self.doc.write_text("[%s] " % pate.get_gramps_id())
#        #                                        self.doc.write_text(" %s;" % pate_name)
#                                                Patenlist.append(pate)
#                 #                           self.doc.end_superscript()

                                        Patenlist = pedic[eventref.ref]


        #death date
                        death_ref = child.get_death_ref()
                        if death_ref:
                            self.doc.write_text(" † ")
                            self.doc.write_text(self.__format_date(self.database.get_event_from_handle(death_ref.ref).get_date_object()))
        #death place
                            place_handle = self.database.get_event_from_handle(death_ref.ref).get_place_handle()
                            if place_handle:
                                death_place_string = self.database.get_place_from_handle(
                                               place_handle).get_title()
                                self.doc.write_text(" in %s " % death_place_string)
        #burr date
                        for eventref in child.event_ref_list:
                            if eventref.role == EventRoleType.PRIMARY:
                                if self.database.get_event_from_handle(eventref.ref).get_type() == EventType.BURIAL:
                                    self.doc.write_text("%s " % u'\u26B0')
                                    self.doc.write_text(self.__format_date(self.database.get_event_from_handle(eventref.ref).get_date_object()))
        
        #burr place
                                    place_handle = self.database.get_event_from_handle(eventref.ref).get_place_handle()
                                    if place_handle:
                                        bur_place_string = self.database.get_place_from_handle(
                                                                            place_handle).get_title()
                                        self.doc.write_text(" in %s " % bur_place_string)
                        self.doc.end_paragraph()

                        if self.showgodparents:
                        
                            self.doc.start_paragraph("PLC-Godparents")
                            self.doc.write_text(" Paten: ")
                            for i,(pa_a,pa_b) in enumerate(Patenlist):
                                self.doc.write_text(" (%s) " % str(i+1))
                         
                                pate_name = self.database.get_person_from_handle(pa_b).get_primary_name().get_first_name() +" "+ self.database.get_person_from_handle(pa_b).get_primary_name().get_surname() 
                                pate = self.database.get_person_from_handle(pa_b) 
                         
                                mark = ReportUtils.get_person_mark(self.database, pate)
                                self.doc.write_text(pate.get_primary_name().get_first_name() +" "+ pate.get_primary_name().get_surname() ,mark)
                            self.doc.end_paragraph()
                            Patenlist =[]

        #        print(ifam, "family")    


        
    def __get_place_handles(self, places):
        """
        This procedure converts a string of place GIDs to a list of handles
        """
        place_handles = [] 
        for place_gid in places.split():
            place = self.database.get_place_from_gramps_id(place_gid)
            if place is not None:
                place_handles.append(place.get_handle())

        return place_handles
Ejemplo n.º 4
0
class ledigquote(Report):
    """
    ledigquote Report class
    """
    def __init__(self, database, options, user):
        """
        Create the ledigquote Report object produces the ledigquote report.
        
        The arguments are:

        database        - the GRAMPS database instance
        options         - instance of the Options class for this report
        user            - instance of a gen.user.User class

        This report needs the following parameters (class variables)
        that come in the options class.
        
        places          - List of places to report on.
#        classwidth          - classwidth of report, person or event
        incpriv         - Whether to include private data

        """

        Report.__init__(self, database, options, user)

        self._user = user
        menu = options.menu
        places = menu.get_option_by_name('places').get_value()
        self.classwidth = menu.get_option_by_name('classwidth').get_value()
        self.incpriv = menu.get_option_by_name('incpriv').get_value()

        self.set_locale(menu.get_option_by_name('trans').get_value())

        name_format = menu.get_option_by_name("name_format").get_value()
        if name_format != 0:
            self._name_display.set_default_format(name_format)
        self._nd = self._name_display

        if self.incpriv:
            self.database = database
        else:
            self.database = PrivateProxyDb(database)

        filter_option = menu.get_option_by_name('filter')
        self.filter = filter_option.get_filter()
        self.sort = Sort(self.database)

        if self.filter.get_name() != '':
            # Use the selected filter to provide a list of place handles
            plist = self.database.iter_place_handles()
            self.place_handles = self.filter.apply(self.database, plist)
        else:
            # Use the place handles selected without a filter
            self.place_handles = self.__get_place_handles(places)

        self.place_handles.sort(key=self.sort.by_place_title_key)

    def write_report(self):
        """
        The routine that actually creates the report.
        At this point, the document is opened and ready for writing.
        """

        # Write the title line. Set in INDEX marker so that this section will be
        # identified as a major category if this is included in a Book report.

        title = self._("Ledigenquote und Verheiratetenanteile ")
        mark = IndexMark(title, INDEX_TYPE_TOC, 1)
        self.doc.start_paragraph("PLC-ReportTitle")
        self.doc.write_text(title, mark)
        self.doc.end_paragraph()

        self.doc.start_paragraph("PLC-Section")
        self.doc.write_text(
            "Enthält alle Personen, die in diesem Ort geboren oder getauft wurden"
        )
        self.doc.end_paragraph()
        self.doc.start_table("LEQUODETTable", "SRC-LEQUODETTable")
        column_titles = [
            _("name"),
            _("ID"),
            _("m/w"),
            _("birth"),
            _("death"),
            _("marriage"),
            _("date"),
            _("weitere Heiraten"),
            _("Alter Tod"),
            _("Alter Hochzeit"),
            _("place"),
            _("LNR")
        ]
        i = 0
        self.doc.start_row()
        for title in column_titles:
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(title)
            self.doc.end_paragraph()
            self.doc.end_cell()
        self.doc.end_row()

        self.__write_data()

        self.doc.end_table()

        # Männer Tabelle
        self.doc.start_paragraph("PLC-Section")
        self.doc.write_text(
            "Ledigenquote und Verheiratetenanteile bei Männern")
        self.doc.end_paragraph()
        self.doc.start_table("LEQUODETTable", "SRC-LEQUODETTable")
        column_titles = [
            _("cat"),
            _("ID"),
            _("m/w"),
            _("birth"),
            _("death"),
            _("marriage"),
            _("date"),
            _("weitere Heiraten"),
            _("Alter Tod"),
            _("Alter Hochzeit"),
            _("place"),
            _("LNR")
        ]
        i = 0
        self.doc.start_row()
        for title in column_titles:
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(title)
            self.doc.end_paragraph()
            self.doc.end_cell()
        self.doc.end_row()

        self.__write_statistics(pdet_list)

        self.doc.end_table()

    def __write_data(self):
        """
        This procedure writes out each of the families related to the place
        """
        i = 0
        iw = 0
        ifam = 0
        p_set = set()
        pdet_list = []
        QUAL_ESTIMATED = 1
        gender_dict = {0: "w", 1: "m", 2: "u"}

        for person in self.database.iter_people():
            birth_event = get_birth_or_fallback(self.database, person)
            b_year = 0
            alt_tod = 0
            b_role = "ROLLE"
            if birth_event:
                if birth_event.get_place_handle() in self.place_handles:
                    birth_obj = birth_event.get_date_object()
                    if birth_obj.get_quality() is not QUAL_ESTIMATED:
                        place_d = place_displayer.display_event(
                            self.database, birth_event)
                        person_name = person.get_primary_name().get_surname()
                        person_ID = person.get_gramps_id()
                        gender = gender_dict[person.get_gender()]

                        m_date = self._get_date(birth_obj)
                        #                if birth_obj.get_quality() is not QUAL_ESTIMATED:
                        b_year = birth_obj.get_year()
                        #              b_role = "ROLLE "+ str(birth_event.role)
                        #                    b_place =
                        death_event = get_death_or_fallback(
                            self.database, person)
                        d_year = 0
                        if death_event:
                            death_obj = death_event.get_date_object()
                            #                if death_obj.get_quality() is not QUAL_ESTIMATED:
                            d_year = death_obj.get_year()
                            alt_tod = d_year - b_year
                        m_year = 0

                        alt_marr = 0

                        m_list = []
                        #                    m_date = ""
                        m_wm = "WEIT"
                        for family_handle in person.get_family_handle_list():
                            #                        print(family_handle)
                            family = self.database.get_family_from_handle(
                                family_handle)

                            for fam_event_ref in family.get_event_ref_list():
                                #                            print(fam_event_ref)
                                if fam_event_ref:
                                    fam_event = self.database.get_event_from_handle(
                                        fam_event_ref.ref)
                                    if fam_event.type == EventType.MARRIAGE:
                                        print(fam_event.type)
                                        m_list.append(
                                            fam_event.get_date_object(
                                            ).get_year())
    #                                    print(fam_event.get_date_object().get_year())
    #                                    m_year = fam_event.get_date_object().get_year()
                        if len(m_list) > 0:
                            m_year = min(m_list)
                            alt_marr = m_year - b_year

    #                    else:
    #                        m_year = 0
                        for m in m_list:
                            m_wm = m_wm + " " + str(m)

        #                person_details = [ person, person_name, person_ID, gender, b_year, d_year, m_year, b_role, m_date, diff,place_d]
                        person_details = [
                            person, person_name, person_ID, gender, b_year,
                            d_year, m_year, m_date, m_wm, alt_tod, alt_marr,
                            place_d
                        ]

                        pdet_list.append(person_details)
        i = 1
        for pn in pdet_list:
            self.doc.start_row()

            #            self.doc.start_cell("SRC-TableColumn")
            #            self.doc.start_paragraph("SRC-ColumnTitle")
            #            ST = "PN"+ str(pn[0])
            #            self.doc.write_text(_("%s") % ST)
            #    #        self.doc.write_text(_("Hallo0"))
            #            self.doc.end_paragraph()
            #            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[1])
            #      self.doc.write_text(_("Hallo1"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[2])
            #     self.doc.write_text(_("Hallo2"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[3])
            #    self.doc.write_text(_("Hallo3"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[4])
            #   self.doc.write_text(_("Hallo4"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[5])
            #           self.doc.write_text(_("Hallo5"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[6])
            #          self.doc.write_text(_("Hallo6"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[7])
            #          self.doc.write_text(_("Hallo7"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[8])
            #          self.doc.write_text(_("Hallo8"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[9])
            #          self.doc.write_text(_("Hallo9"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            #            diff= pn[6] - pn[4]
            self.doc.write_text(_("%s") % pn[10])
            #            self.doc.write_text(diff)
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[11])
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % i)
            #           self.doc.write_text(i)
            #          self.doc.write_text(_("LNR"))
            self.doc.end_paragraph()
            self.doc.end_cell()
            i += 1

            self.doc.end_row()

#########################

    def __write_statistics(self, list):
        """
        This procedure writes out each of the families related to the place
        """
        # build classes
        #year_list = list(pdet_list[4])
        print(min(list[4]))
        #cm=min()
#        i=1
#        for pn in pdet_list:
#            self.doc.start_row()
#
##            self.doc.start_cell("SRC-TableColumn")
##            self.doc.start_paragraph("SRC-ColumnTitle")
##            ST = "PN"+ str(pn[0])
##            self.doc.write_text(_("%s") % ST)
##    #        self.doc.write_text(_("Hallo0"))
##            self.doc.end_paragraph()
##            self.doc.end_cell()
#
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[1])
#      #      self.doc.write_text(_("Hallo1"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[2])
#       #     self.doc.write_text(_("Hallo2"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[3])
#        #    self.doc.write_text(_("Hallo3"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[4])
#         #   self.doc.write_text(_("Hallo4"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[5])
# #           self.doc.write_text(_("Hallo5"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[6])
#  #          self.doc.write_text(_("Hallo6"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[7])
#  #          self.doc.write_text(_("Hallo7"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[8])
#  #          self.doc.write_text(_("Hallo8"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[9])
#  #          self.doc.write_text(_("Hallo9"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
##            diff= pn[6] - pn[4]
#            self.doc.write_text(_("%s") % pn[10])
##            self.doc.write_text(diff)
#            self.doc.end_paragraph()
#           self.doc.end_cell()
#
#           self.doc.start_cell("SRC-TableColumn")
#           self.doc.start_paragraph("SRC-ColumnTitle")
#           self.doc.write_text(_("%s") % pn[11])
#           self.doc.end_paragraph()
#           self.doc.end_cell()
#
#           self.doc.start_cell("SRC-TableColumn")
#           self.doc.start_paragraph("SRC-ColumnTitle")
#           self.doc.write_text(_("%s") % i)
##           self.doc.write_text(i)
# #          self.doc.write_text(_("LNR"))
#           self.doc.end_paragraph()
#          self.doc.end_cell()
#          i +=1
#
#
#          self.doc.end_row()
#
#########################

    def __format_date(self, date_object):
        if not date_object: return
        d = date_object.get_day()
        m = date_object.get_month()
        y = date_object.get_year()
        if (d == 0) and (m == 0):
            date_f = (" %s" % y)
        elif (d == 0) and not (m == 0):
            date_f = (" %s.%s" % (m, y))
        else:
            date_f = (" %s.%s.%s" % (d, m, y))
        return date_f

    def __get_place_handles(self, places):
        """
        This procedure converts a string of place GIDs to a list of handles
        """
        place_handles = []
        for place_gid in places.split():
            place = self.database.get_place_from_gramps_id(place_gid)
            if place is not None:
                place_handles.append(place.get_handle())

        return place_handles
Ejemplo n.º 5
0
class ListeEclairReport(Report):
    def __init__(self, database, options_class, user):

        Report.__init__(self, database, options_class, user)

        menu = options_class.menu
        places = menu.get_option_by_name('places').get_value()
        self.reporttype = menu.get_option_by_name('reporttype').get_value()
        self.incpriv = menu.get_option_by_name('incpriv').get_value()
        #self.incliving = menu.get_option_by_name('incliving').get_value()

        if self.incpriv:
            self.database = database
        else:
            self.database = PrivateProxyDb(database)

        #self.database = LivingProxyDb(database, LivingProxyDb.MODE_EXCLUDE_ALL)

        filter_option = menu.get_option_by_name('filter')
        self.filter = filter_option.get_filter()
        self.sort = Sort(self.database)

        if self.filter.get_name() != '':
            # Use the selected filter to provide a list of place handles
            plist = self.database.iter_place_handles()
            self.place_handles = self.filter.apply(self.database, plist)
        else:
            # Use the place handles selected without a filter
            self.place_handles = self.__get_place_handles(places)

        self.place_handles.sort(key=self.sort.by_place_title_key)

    def write_report(self):
        """
        The routine the actually creates the report. At this point, the document
        is opened and ready for writing.
        """

        # Create progress meter bar
        self.progress = ProgressMeter(_("Liste Eclair"), '')

        # Write the title line. Set in INDEX marker so that this section will be
        # identified as a major category if this is included in a Book report.

        title = _("Liste Eclair")
        mark = IndexMark(title, INDEX_TYPE_TOC, 1)
        self.doc.start_paragraph("Eclair-ReportTitle")
        self.doc.write_text(title, mark)
        self.doc.end_paragraph()
        self.__write_all_places()

        # Close the progress meter
        self.progress.close()

    def __write_all_places(self):
        """
        This procedure writes out each of the selected places.
        """
        place_nbr = 1
        self.doc.start_paragraph("Eclair-Report")
        self.progress.set_pass(_("Generating report"), len(self.place_handles))
        self.result = []
        for handle in self.place_handles:
            city = self.__write_place(handle, place_nbr)
            self.__write_referenced_events(handle, city)
            place_nbr += 1
            # increment progress bar
            self.progress.step()
        self.result.sort()
        for msg in self.result:
            # AttributeError: 'GtkDocDocument' object has no attribute 'add_text
            self.doc.write_text("%s\n" % msg)
        self.doc.end_paragraph()

    def __write_place(self, handle, place_nbr):
        """
        This procedure writes out the details of a single place
        """
        place = self.database.get_place_from_handle(handle)
        location = get_main_location(self.database, place)

        city = location.get(PlaceType.CITY)

        place_title = _pd.display(self.database, place)
        if city == '' and place_title:
            city = place_title

        return city

    def __write_referenced_events(self, handle, city):
        """
        This procedure writes out each of the events related to the place
        """
        event_handles = [
            event_handle
            for (object_type,
                 event_handle) in self.database.find_backlink_handles(handle)
        ]
        #event_handles.sort(self.sort.by_date)

        self.debut = defaultdict(lambda: defaultdict(dict))
        self.fin = defaultdict(lambda: defaultdict(dict))
        for evt_handle in event_handles:
            event = self.database.get_event_from_handle(evt_handle)
            if event:
                date = event.get_date_object()
            if date:
                year = int(date.get_year())
            else:
                next()
            person_list = []
            ref_handles = [
                x for x in self.database.find_backlink_handles(evt_handle)
            ]
            for (ref_type, ref_handle) in ref_handles:
                if ref_type == 'Person':
                    person_list.append(ref_handle)
                else:
                    family = self.database.get_family_from_handle(ref_handle)
                    # bug 8584
                    if family:
                        father = family.get_father_handle()
                        if father:
                            person_list.append(father)
                        mother = family.get_mother_handle()
                        if mother:
                            person_list.append(mother)

            people = ""
            person_list = list(set(person_list))
            for p_handle in person_list:
                person = self.database.get_person_from_handle(p_handle)
                if person:
                    people = person.get_primary_name().get_surname()

            if not self.debut[city][people]:
                self.debut[city][people] = year
                self.fin[city][people] = year
            if self.debut[city][people] > year:
                self.debut[city][people] = year
            if self.fin[city][people] < year:
                self.fin[city][people] = year
                event_details = [year, people]
        keylist = self.debut.keys()
        #keylist.sort()
        sorted(list(keylist))  # bug 8437
        for city in keylist:
            for people in sorted(self.debut[city].keys()):
                if self.reporttype == "ListeEclair":
                    if self.debut[city][people] == 0:
                        msg = city + ":" + people
                    else:
                        msg = city + ":" + people + ":" + str(
                            self.debut[city][people]) + ":" + str(
                                self.fin[city][people])
                else:
                    msg = people + ":" + city
                if msg:
                    self.result.append(str(msg))

    def __get_place_handles(self, places):
        """
        This procedure converts a string of place GIDs to a list of handles
        """
        place_handles = []
        for place_gid in places.split():
            place = self.database.get_place_from_gramps_id(place_gid)
            if place is not None:
                #place can be None if option is gid of other fam tree
                place_handles.append(place.get_handle())

        return place_handles
Ejemplo n.º 6
0
class ListeEclairReport(Report):
    def __init__(self, database, options_class, user):

        Report.__init__(self, database, options_class, user)

        menu = options_class.menu
        places = menu.get_option_by_name('places').get_value()
        self.reporttype  = menu.get_option_by_name('reporttype').get_value()
        self.incpriv = menu.get_option_by_name('incpriv').get_value()
        #self.incliving = menu.get_option_by_name('incliving').get_value()

        if self.incpriv:
            self.database = database
        else:
            self.database = PrivateProxyDb(database)

        #self.database = LivingProxyDb(database, LivingProxyDb.MODE_EXCLUDE_ALL)

        filter_option = menu.get_option_by_name('filter')
        self.filter = filter_option.get_filter()
        self.sort = Sort(self.database)

        if self.filter.get_name() != '':
            # Use the selected filter to provide a list of place handles
            plist = self.database.iter_place_handles()
            self.place_handles = self.filter.apply(self.database, plist)
        else:
            # Use the place handles selected without a filter
            self.place_handles = self.__get_place_handles(places)

        self.place_handles.sort(key=self.sort.by_place_title_key)

    def write_report(self):
        """
        The routine the actually creates the report. At this point, the document
        is opened and ready for writing.
        """

        # Create progress meter bar
        self.progress = ProgressMeter(_("Liste Eclair"), '')

        # Write the title line. Set in INDEX marker so that this section will be
        # identified as a major category if this is included in a Book report.

        title = _("Liste Eclair")
        mark = IndexMark(title, INDEX_TYPE_TOC, 1)
        self.doc.start_paragraph("Eclair-ReportTitle")
        self.doc.write_text(title, mark)
        self.doc.end_paragraph()
        self.__write_all_places()

        # Close the progress meter
        self.progress.close()

    def __write_all_places(self):
        """
        This procedure writes out each of the selected places.
        """
        place_nbr = 1
        self.doc.start_paragraph("Eclair-Report")
        self.progress.set_pass(_("Generating report"), len(self.place_handles))
        self.result=[]
        for handle in self.place_handles:
            city = self.__write_place(handle, place_nbr)
            self.__write_referenced_events(handle, city)
            place_nbr += 1
            # increment progress bar
            self.progress.step()
        self.result.sort()
        for msg in self.result:
            # AttributeError: 'GtkDocDocument' object has no attribute 'add_text
            self.doc.write_text("%s\n" % msg)
        self.doc.end_paragraph()

    def __write_place(self, handle, place_nbr):
        """
        This procedure writes out the details of a single place
        """
        place = self.database.get_place_from_handle(handle)
        location = get_main_location(self.database, place)

        city = location.get(PlaceType.CITY)

        place_title = _pd.display(self.database, place)
        if city == '' and place_title:
            city = place_title

        return city

    def __write_referenced_events(self, handle , city):
        """
        This procedure writes out each of the events related to the place
        """
        event_handles = [event_handle for (object_type, event_handle) in
                         self.database.find_backlink_handles(handle)]
        #event_handles.sort(self.sort.by_date)

        self.debut = defaultdict(lambda: defaultdict(dict))
        self.fin = defaultdict(lambda: defaultdict(dict))
        for evt_handle in event_handles:
            event = self.database.get_event_from_handle(evt_handle)
            if event:
                date = event.get_date_object()
            if date:
                year = int(date.get_year())
            else:
                next()
            person_list = []
            ref_handles = [x for x in
                            self.database.find_backlink_handles(evt_handle)]
            for (ref_type, ref_handle) in ref_handles:
                if ref_type == 'Person':
                    person_list.append(ref_handle)
                else:
                    family = self.database.get_family_from_handle(ref_handle)
                    # bug 8584
                    if family:
                        father = family.get_father_handle()
                        if father:
                            person_list.append(father)
                        mother = family.get_mother_handle()
                        if mother:
                            person_list.append(mother)

            people = ""
            person_list = list(set(person_list))
            for p_handle in person_list:
                person = self.database.get_person_from_handle(p_handle)
                if person:
                    people = person.get_primary_name().get_surname()

            if not self.debut[city][people]:
                self.debut[city][people] = year
                self.fin[city][people] = year
            if self.debut[city][people] > year:
                self.debut[city][people] = year
            if self.fin[city][people] < year:
                self.fin[city][people] = year
                event_details = [year, people]
        keylist = self.debut.keys()
        #keylist.sort()
        sorted(list(keylist)) # bug 8437
        for city in keylist:
            for people in sorted(self.debut[city].keys()):
                if self.reporttype == "ListeEclair":
                    if self.debut[city][people] == 0:
                        msg = city + ":" + people
                    else:
                        msg = city + ":" + people + ":" + str(self.debut[city][people]) + ":" + str(self.fin[city][people])
                else:
                    msg = people + ":" + city
                if msg:
                    self.result.append(str(msg))


    def __get_place_handles(self, places):
        """
        This procedure converts a string of place GIDs to a list of handles
        """
        place_handles = []
        for place_gid in places.split():
            place = self.database.get_place_from_gramps_id(place_gid)
            if place is not None:
                #place can be None if option is gid of other fam tree
                place_handles.append(place.get_handle())

        return place_handles
Ejemplo n.º 7
0
class ledigquote(Report):
    """
    ledigquote Report class
    """
    def __init__(self, database, options, user):
        """
        Create the ledigquote Report object produces the ledigquote report.
        
        The arguments are:

        database        - the GRAMPS database instance
        options         - instance of the Options class for this report
        user            - instance of a gen.user.User class

        This report needs the following parameters (class variables)
        that come in the options class.
        
        places          - List of places to report on.
#        classwidth          - classwidth of report, person or event
        incpriv         - Whether to include private data

        """

        Report.__init__(self, database, options, user)

        self._user = user
        menu = options.menu
        places = menu.get_option_by_name('places').get_value()
        self.classwidth  = menu.get_option_by_name('classwidth').get_value()
        self.incpriv = menu.get_option_by_name('incpriv').get_value()

        self.set_locale(menu.get_option_by_name('trans').get_value())

        name_format = menu.get_option_by_name("name_format").get_value()
        if name_format != 0:
            self._name_display.set_default_format(name_format)
        self._nd = self._name_display
        
        if self.incpriv:
            self.database = database
        else:
            self.database = PrivateProxyDb(database)

        filter_option = menu.get_option_by_name('filter')
        self.filter = filter_option.get_filter()
        self.sort = Sort(self.database)

        if self.filter.get_name() != '':
            # Use the selected filter to provide a list of place handles
            plist = self.database.iter_place_handles()
            self.place_handles = self.filter.apply(self.database, plist)
        else:
            # Use the place handles selected without a filter
            self.place_handles = self.__get_place_handles(places)

        self.place_handles.sort(key=self.sort.by_place_title_key)
        
    def write_report(self):
        """
        The routine that actually creates the report.
        At this point, the document is opened and ready for writing.
        """

        # Write the title line. Set in INDEX marker so that this section will be
        # identified as a major category if this is included in a Book report.

        title = self._("Ledigenquote und Verheiratetenanteile ")
        mark = IndexMark(title, INDEX_TYPE_TOC, 1)        
        self.doc.start_paragraph("PLC-ReportTitle")
        self.doc.write_text(title, mark)
        self.doc.end_paragraph()

        self.doc.start_paragraph("PLC-Section")
        self.doc.write_text("Enthält alle Personen, die in diesem Ort geboren oder getauft wurden")
        self.doc.end_paragraph()
        self.doc.start_table("LEQUODETTable", "SRC-LEQUODETTable")
        column_titles = [_("name"), _("ID"), _("m/w"), _("birth"), _("death"), _("marriage"), _("date"), _("weitere Heiraten"), _("Alter Tod"), _("Alter Hochzeit"), _("place"), _("LNR") ] 
        i = 0
        self.doc.start_row()
        for title in column_titles:
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(title)
            self.doc.end_paragraph()
            self.doc.end_cell()
        self.doc.end_row()

        self.__write_data()

        self.doc.end_table()
        
# Männer Tabelle        
        self.doc.start_paragraph("PLC-Section")
        self.doc.write_text("Ledigenquote und Verheiratetenanteile bei Männern")
        self.doc.end_paragraph()
        self.doc.start_table("LEQUODETTable", "SRC-LEQUODETTable")
        column_titles = [_("cat"), _("ID"), _("m/w"), _("birth"), _("death"), _("marriage"), _("date"), _("weitere Heiraten"), _("Alter Tod"), _("Alter Hochzeit"), _("place"), _("LNR") ] 
        i = 0
        self.doc.start_row()
        for title in column_titles:
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(title)
            self.doc.end_paragraph()
            self.doc.end_cell()
        self.doc.end_row()

        self.__write_statistics(pdet_list)

        self.doc.end_table()

    def __write_data(self):
        """
        This procedure writes out each of the families related to the place
        """
        i = 0
        iw = 0
        ifam = 0
        p_set=set()
        pdet_list=[]
        QUAL_ESTIMATED = 1
        gender_dict ={0:"w",1:"m", 2:"u"}


        for person in self.database.iter_people():
            birth_event = get_birth_or_fallback(self.database, person)
            b_year = 0
            alt_tod = 0
            b_role = "ROLLE"
            if birth_event:
                if birth_event.get_place_handle() in self.place_handles:
                    birth_obj = birth_event.get_date_object()
                    if birth_obj.get_quality() is not QUAL_ESTIMATED:
                        place_d = place_displayer.display_event(self.database, birth_event)                             
                        person_name = person.get_primary_name().get_surname()
                        person_ID = person.get_gramps_id()
                        gender = gender_dict[person.get_gender()]

                        m_date = self._get_date(birth_obj)
        #                if birth_obj.get_quality() is not QUAL_ESTIMATED:
                        b_year = birth_obj.get_year()
          #              b_role = "ROLLE "+ str(birth_event.role)
        #                    b_place = 
                        death_event = get_death_or_fallback(self.database, person)
                        d_year = 0
                        if death_event:
                            death_obj = death_event.get_date_object()
            #                if death_obj.get_quality() is not QUAL_ESTIMATED:
                            d_year = death_obj.get_year() 
                            alt_tod = d_year - b_year
                        m_year = 0    
    
                        alt_marr = 0
    
                        m_list=[]
    #                    m_date = ""
                        m_wm = "WEIT"
                        for family_handle in person.get_family_handle_list():
    #                        print(family_handle)
                            family = self.database.get_family_from_handle(family_handle)
            
                            for fam_event_ref in family.get_event_ref_list():
    #                            print(fam_event_ref)
                                if fam_event_ref:
                                    fam_event = self.database.get_event_from_handle(fam_event_ref.ref)
                                    if fam_event.type == EventType.MARRIAGE:
                                        print(fam_event.type)
                                        m_list.append(fam_event.get_date_object().get_year())
    #                                    print(fam_event.get_date_object().get_year())
    #                                    m_year = fam_event.get_date_object().get_year()
                        if len(m_list)>0:
                            m_year = min(m_list)
                            alt_marr = m_year - b_year
    #                    else:
    #                        m_year = 0    
                        for m in m_list:
                            m_wm = m_wm+" "+str(m)               
                        
                
        #                person_details = [ person, person_name, person_ID, gender, b_year, d_year, m_year, b_role, m_date, diff,place_d]
                        person_details = [ person, person_name, person_ID, gender, b_year, d_year, m_year, m_date, m_wm, alt_tod, alt_marr, place_d]
        
                        pdet_list.append(person_details)
        i=1
        for pn in pdet_list:
            self.doc.start_row()
  
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            ST = "PN"+ str(pn[0])
#            self.doc.write_text(_("%s") % ST)
#    #        self.doc.write_text(_("Hallo0"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[1])
      #      self.doc.write_text(_("Hallo1"))
            self.doc.end_paragraph()
            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[2])
       #     self.doc.write_text(_("Hallo2"))
            self.doc.end_paragraph()
            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[3])
        #    self.doc.write_text(_("Hallo3"))
            self.doc.end_paragraph()
            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[4])
         #   self.doc.write_text(_("Hallo4"))
            self.doc.end_paragraph()
            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[5])
 #           self.doc.write_text(_("Hallo5"))
            self.doc.end_paragraph()
            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[6])
  #          self.doc.write_text(_("Hallo6"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[7])
  #          self.doc.write_text(_("Hallo7"))
            self.doc.end_paragraph()
            self.doc.end_cell()

  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[8])
  #          self.doc.write_text(_("Hallo8"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[9])
  #          self.doc.write_text(_("Hallo9"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
#            diff= pn[6] - pn[4]
            self.doc.write_text(_("%s") % pn[10])
#            self.doc.write_text(diff)
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[11])
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % i)
 #           self.doc.write_text(i)
  #          self.doc.write_text(_("LNR"))
            self.doc.end_paragraph()
            self.doc.end_cell()
            i +=1


            self.doc.end_row()

#########################
    def __write_statistics(self,list):
        """
        This procedure writes out each of the families related to the place
        """
# build classes
        #year_list = list(pdet_list[4])
        print(min(list[4]))
        #cm=min()
#        i=1
#        for pn in pdet_list:
#            self.doc.start_row()
#  
##            self.doc.start_cell("SRC-TableColumn")
##            self.doc.start_paragraph("SRC-ColumnTitle")
##            ST = "PN"+ str(pn[0])
##            self.doc.write_text(_("%s") % ST)
##    #        self.doc.write_text(_("Hallo0"))
##            self.doc.end_paragraph()
##            self.doc.end_cell()
#  
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[1])
#      #      self.doc.write_text(_("Hallo1"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#  
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[2])
#       #     self.doc.write_text(_("Hallo2"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#  
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[3])
#        #    self.doc.write_text(_("Hallo3"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#  
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[4])
#         #   self.doc.write_text(_("Hallo4"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#  
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[5])
# #           self.doc.write_text(_("Hallo5"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#  
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[6])
#  #          self.doc.write_text(_("Hallo6"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[7])
#  #          self.doc.write_text(_("Hallo7"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[8])
#  #          self.doc.write_text(_("Hallo8"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[9])
#  #          self.doc.write_text(_("Hallo9"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#            
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
##            diff= pn[6] - pn[4]
#            self.doc.write_text(_("%s") % pn[10])
##            self.doc.write_text(diff)
#            self.doc.end_paragraph()
 #           self.doc.end_cell()
 #
 #           self.doc.start_cell("SRC-TableColumn")
 #           self.doc.start_paragraph("SRC-ColumnTitle")
 #           self.doc.write_text(_("%s") % pn[11])
 #           self.doc.end_paragraph()
 #           self.doc.end_cell()
 #
 #           self.doc.start_cell("SRC-TableColumn")
 #           self.doc.start_paragraph("SRC-ColumnTitle")
 #           self.doc.write_text(_("%s") % i)
 ##           self.doc.write_text(i)
 # #          self.doc.write_text(_("LNR"))
 #           self.doc.end_paragraph()
  #          self.doc.end_cell()
  #          i +=1
  #
  #
  #          self.doc.end_row()
  #
#########################
            
    def __format_date(self, date_object):
        if not date_object: return
        d=date_object.get_day()    
        m=date_object.get_month()
        y=date_object.get_year()
        if (d == 0) and (m == 0):
            date_f = (" %s" % y)
        elif (d == 0) and not (m == 0):
            date_f = (" %s.%s" % (m, y))  
        else:       
            date_f = (" %s.%s.%s" % (d, m, y)) 
        return date_f           
        

        
    def __get_place_handles(self, places):
        """
        This procedure converts a string of place GIDs to a list of handles
        """
        place_handles = [] 
        for place_gid in places.split():
            place = self.database.get_place_from_gramps_id(place_gid)
            if place is not None:
                place_handles.append(place.get_handle())

        return place_handles
Ejemplo n.º 8
0
class ledigquote(Report):
    """
    ledigquote Report class
    """
    def __init__(self, database, options, user):
        """
        Create the ledigquote Report object produces the ledigquote report.
        
        The arguments are:

        database        - the GRAMPS database instance
        options         - instance of the Options class for this report
        user            - instance of a gen.user.User class

        This report needs the following parameters (class variables)
        that come in the options class.
        
        places          - List of places to report on.
#        center          - Center of report, person or event
        incpriv         - Whether to include private data

        """

        Report.__init__(self, database, options, user)

        self._user = user
        menu = options.menu
        places = menu.get_option_by_name('places').get_value()
        #        self.center  = menu.get_option_by_name('center').get_value()
        self.incpriv = menu.get_option_by_name('incpriv').get_value()

        self.set_locale(menu.get_option_by_name('trans').get_value())

        name_format = menu.get_option_by_name("name_format").get_value()
        if name_format != 0:
            self._name_display.set_default_format(name_format)
        self._nd = self._name_display

        if self.incpriv:
            self.database = database
        else:
            self.database = PrivateProxyDb(database)

        filter_option = menu.get_option_by_name('filter')
        self.filter = filter_option.get_filter()
        self.sort = Sort(self.database)

        if self.filter.get_name() != '':
            # Use the selected filter to provide a list of place handles
            plist = self.database.iter_place_handles()
            self.place_handles = self.filter.apply(self.database, plist)
        else:
            # Use the place handles selected without a filter
            self.place_handles = self.__get_place_handles(places)

        self.place_handles.sort(key=self.sort.by_place_title_key)

    def write_report(self):
        """
        The routine that actually creates the report.
        At this point, the document is opened and ready for writing.
        """

        # Write the title line. Set in INDEX marker so that this section will be
        # identified as a major category if this is included in a Book report.

        title = self._("Ledigenquote und Verheiratetenanteile ")
        mark = IndexMark(title, INDEX_TYPE_TOC, 1)
        self.doc.start_paragraph("PLC-ReportTitle")
        self.doc.write_text(title, mark)
        self.doc.end_paragraph()

        self.doc.start_paragraph("PLC-Section")
        self.doc.write_text(
            "Enthält alle Personen, die in diesem Ort geboren oder getauft wurden"
        )
        self.doc.end_paragraph()
        self.doc.start_table("LEQUODETTable", "SRC-LEQUODETTable")
        column_titles = [
            _("person"),
            _("name"),
            _("ID"),
            _("m/w"),
            _("birth"),
            _("death"), ("marriage"),
            _("place")
        ]
        i = 0
        self.doc.start_row()
        for title in column_titles:
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(title)
            self.doc.end_paragraph()
            self.doc.end_cell()
        self.doc.end_row()

        self.__write_data()

        self.doc.end_table()

    def __write_data(self):
        """
        This procedure writes out each of the families related to the place
        """
        i = 0
        iw = 0
        ifam = 0
        p_set = set()
        pdet_list = []
        QUAL_ESTIMATED = 1
        gender_dict = {0: "w", 1: "m", 2: "u"}

        for handle in self.place_handles:
            # first all events

            event_handles = [
                event_handle for (object_type, event_handle) in
                self.database.find_backlink_handles(handle, ['Event'])
            ]
            if event_handles:
                self.doc.start_paragraph("PLC-Section")
                self.doc.write_text(
                    self.database.get_place_from_handle(handle).get_title())
                self.doc.end_paragraph()
            print(len(event_handles))
            mi = 0
            for evt_handle in event_handles:
                event = self.database.get_event_from_handle(evt_handle)
                if (event.get_type().is_baptism()
                        or event.get_type().is_birth()):
                    #Alle Personen mit birth oder Bapt
                    pevt_list = [
                        ref_handle for (ref_type, ref_handle) in
                        self.database.find_backlink_handles(event.handle)
                        if ref_type == 'Person'
                    ]
                    for pevt in pevt_list:
                        p_found = self.database.get_person_from_handle(pevt)
                        for ev_ref in p_found.event_ref_list:
                            if ev_ref.role.is_primary():
                                e_det = self.database.get_event_from_handle(
                                    ev_ref.ref)
                                if (e_det.get_type().is_baptism()
                                        or e_det.get_type().is_birth()):
                                    p_set.add(pevt)

        p_list = list(p_set)
        for ph in p_set:
            m_role = "Rolle"
            person = self.database.get_person_from_handle(ph)
            person_name = person.get_primary_name().get_surname()
            person_ID = person.get_gramps_id()
            gender = gender_dict[person.get_gender()]
            m_date = ""

            birth_ref = person.get_birth_ref()
            b_year = 0
            if birth_ref:
                birth_obj = self.database.get_event_from_handle(
                    birth_ref.ref).get_date_object()
                if birth_obj.get_quality() is not QUAL_ESTIMATED:
                    b_year = birth_obj.get_year()
            m_year = 0
            for evt_ref in person.get_primary_event_ref_list():
                evt = self.database.get_event_from_handle(evt_ref.ref)
                if evt and evt.type.is_birth_fallback():
                    birth_obj = evt.get_date_object()
                    m_year = birth_obj.get_year()
                    m_role = "ROLLE " + str(evt_ref.role)
                    m_date = self._get_date(evt.get_date_object())
            diff = m_year - b_year
            death_ref = person.get_death_ref()
            d_year = 0
            if death_ref:
                death_obj = self.database.get_event_from_handle(
                    death_ref.ref).get_date_object()
                if death_obj.get_quality() is not QUAL_ESTIMATED:
                    d_year = death_obj.get_year()

            place_d = place_displayer.display_event(self.database, evt)
            #                                b_year = event.get_date_object().to_calendar(cal).get_year()
            #                                d_year = event.get_date_object().to_calendar(cal).get_year()
            #m_year = event.get_date_object().to_calendar(cal).get_year()
            person_details = [
                person, person_name, person_ID, gender, b_year, d_year, m_year,
                m_role, m_date, diff, place_d
            ]
            print(person_details[1], person_details[2], person_details[3],
                  person_details[4], person_details[5], person_details[6])
            pdet_list.append(person_details)

        i = 1
        for pn in pdet_list:
            self.doc.start_row()

            #            self.doc.start_cell("SRC-TableColumn")
            #            self.doc.start_paragraph("SRC-ColumnTitle")
            #            ST = "PN"+ str(pn[0])
            #            self.doc.write_text(_("%s") % ST)
            #    #        self.doc.write_text(_("Hallo0"))
            #            self.doc.end_paragraph()
            #            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[1])
            #      self.doc.write_text(_("Hallo1"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[2])
            #     self.doc.write_text(_("Hallo2"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[3])
            #    self.doc.write_text(_("Hallo3"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[4])
            #   self.doc.write_text(_("Hallo4"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[5])
            #           self.doc.write_text(_("Hallo5"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[6])
            #          self.doc.write_text(_("Hallo6"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            #            self.doc.start_cell("SRC-TableColumn")
            #            self.doc.start_paragraph("SRC-ColumnTitle")
            #            self.doc.write_text(_("%s") % pn[7])
            #  #          self.doc.write_text(_("Hallo7"))
            #            self.doc.end_paragraph()
            #            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[8])
            #          self.doc.write_text(_("Hallo8"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[9])
            #          self.doc.write_text(_("Hallo9"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            #            diff= pn[6] - pn[4]
            self.doc.write_text(_("%s") % pn[10])
            #            self.doc.write_text(diff)
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % i)
            #           self.doc.write_text(i)
            #          self.doc.write_text(_("LNR"))
            self.doc.end_paragraph()
            self.doc.end_cell()
            i += 1

            self.doc.end_row()

    def __format_date(self, date_object):
        if not date_object: return
        d = date_object.get_day()
        m = date_object.get_month()
        y = date_object.get_year()
        if (d == 0) and (m == 0):
            date_f = (" %s" % y)
        elif (d == 0) and not (m == 0):
            date_f = (" %s.%s" % (m, y))
        else:
            date_f = (" %s.%s.%s" % (d, m, y))
        return date_f

    def __get_place_handles(self, places):
        """
        This procedure converts a string of place GIDs to a list of handles
        """
        place_handles = []
        for place_gid in places.split():
            place = self.database.get_place_from_gramps_id(place_gid)
            if place is not None:
                place_handles.append(place.get_handle())

        return place_handles
Ejemplo n.º 9
0
class ledigquote(Report):
    """
    ledigquote Report class
    """
    def __init__(self, database, options, user):
        """
        Create the ledigquote Report object produces the ledigquote report.
        
        The arguments are:

        database        - the GRAMPS database instance
        options         - instance of the Options class for this report
        user            - instance of a gen.user.User class

        This report needs the following parameters (class variables)
        that come in the options class.
        
        places          - List of places to report on.
#        center          - Center of report, person or event
        incpriv         - Whether to include private data

        """

        Report.__init__(self, database, options, user)

        self._user = user
        menu = options.menu
        places = menu.get_option_by_name('places').get_value()
#        self.center  = menu.get_option_by_name('center').get_value()
        self.incpriv = menu.get_option_by_name('incpriv').get_value()

        self.set_locale(menu.get_option_by_name('trans').get_value())

        name_format = menu.get_option_by_name("name_format").get_value()
        if name_format != 0:
            self._name_display.set_default_format(name_format)
        self._nd = self._name_display
        
        if self.incpriv:
            self.database = database
        else:
            self.database = PrivateProxyDb(database)

        filter_option = menu.get_option_by_name('filter')
        self.filter = filter_option.get_filter()
        self.sort = Sort(self.database)

        if self.filter.get_name() != '':
            # Use the selected filter to provide a list of place handles
            plist = self.database.iter_place_handles()
            self.place_handles = self.filter.apply(self.database, plist)
        else:
            # Use the place handles selected without a filter
            self.place_handles = self.__get_place_handles(places)

        self.place_handles.sort(key=self.sort.by_place_title_key)
        
    def write_report(self):
        """
        The routine that actually creates the report.
        At this point, the document is opened and ready for writing.
        """

        # Write the title line. Set in INDEX marker so that this section will be
        # identified as a major category if this is included in a Book report.

        title = self._("Ledigenquote und Verheiratetenanteile ")
        mark = IndexMark(title, INDEX_TYPE_TOC, 1)        
        self.doc.start_paragraph("PLC-ReportTitle")
        self.doc.write_text(title, mark)
        self.doc.end_paragraph()

        self.doc.start_paragraph("PLC-Section")
        self.doc.write_text("Enthält alle Personen, die in diesem Ort geboren oder getauft wurden")
        self.doc.end_paragraph()
        self.doc.start_table("LEQUODETTable", "SRC-LEQUODETTable")
        column_titles = [_("person"), _("name"), _("ID"), _("m/w"), _("birth"), _("death"),("marriage"), _("place")] 
        i = 0
        self.doc.start_row()
        for title in column_titles:
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(title)
            self.doc.end_paragraph()
            self.doc.end_cell()
        self.doc.end_row()

        self.__write_data()

        self.doc.end_table()

    def __write_all_places(self):
        """
        This procedure writes out each of the selected places.
        """
        place_nbr = 1

        with self._user.progress(_("Ledigenquote"), 
                                  _("Generating report"), 
                                  len(self.place_handles)) as step:
            
            for handle in self.place_handles:
      #          self.__write_place(handle, place_nbr)
                self.__write_data(handle)
                place_nbr += 1
                # increment progress bar
                step()
           
    def __format_date(self, date_object):
        if not date_object: return
        d=date_object.get_day()    
        m=date_object.get_month()
        y=date_object.get_year()
        if (d == 0) and (m == 0):
            date_f = (" %s" % y)
        elif (d == 0) and not (m == 0):
            date_f = (" %s.%s" % (m, y))  
        else:       
            date_f = (" %s.%s.%s" % (d, m, y)) 
        return date_f           
        

    def __write_data(self):
        """
        This procedure writes out each of the families related to the place
        """
        i = 0
        iw = 0
        ifam = 0
        pe ={}
        marr =[]
        pn_list=[]
        p_list=[]
        QUAL_ESTIMATED = 1


        with self._user.progress(_("Ledigenquote Report"), 
                                  _("Generating report"), 
                                  len(self.place_handles)) as step:

            for handle in self.place_handles:        
    # first all events
                  
                event_handles = [event_handle for (object_type, event_handle) in
                                 self.database.find_backlink_handles(handle, ['Event'])]
 #               event_handles.sort(key=self.sort.by_date_key)
        
                if event_handles:
                    self.doc.start_paragraph("PLC-Section")
                    self.doc.write_text(self.database.get_place_from_handle(handle).get_title())
                    self.doc.end_paragraph()
                print(len(event_handles))
                mi = 0    
                for evt_handle in event_handles:
                    event = self.database.get_event_from_handle(evt_handle)
                    date = self._get_date(event.get_date_object())
                    date_sort = event.get_date_object().get_sort_value()
                    descr = event.get_description()
                    event_type = self._(self._get_type(event.get_type()))
                    event_place = event.place 
                    
                    ref_handles = [x for x in
                                   self.database.find_backlink_handles(evt_handle)]
                    ########################
#                            person_list = [
#            item[1] for item in
#            self.dbstate.db.find_backlink_handles(handle,['Person']) ]
                    ########################               
        #            print(mi, evt_handle)
                    #########################
                    if ( event.get_type().is_baptism() or event.get_type().is_birth() ):
                        pn_list = [
                            ref_handle
                            for (ref_type, ref_handle) in
                                self.database.find_backlink_handles(event.handle)
                                    if ref_type == 'Person'
                                      ]
                                      
                        person_list = list(set(pn_list))
                                     
                        print("Liste",len(pn_list),len(person_list))
                        if person_list:
                            for ph in person_list:
#                                print(pn)
                                pn = self.database.get_person_from_handle(ph)
                                person_name = pn.get_primary_name().get_surname()
                                person_ID = pn.get_gramps_id()
                                gender = pn.get_gender()
                                
                                birth_ref = pn.get_birth_ref()
                                b_year = 0
                                if birth_ref:
                                    birth_obj = self.database.get_event_from_handle(birth_ref.ref).get_date_object()
                                    if birth_obj.get_quality() is not QUAL_ESTIMATED:
                                        b_year = birth_obj.get_year() 
                                m_year = 0
                                
##############################                                
#                                if not b_year:
                                for evt_ref in pn.get_primary_event_ref_list():
                                    evt = self.database.get_event_from_handle(evt_ref.ref)
                                    if evt and evt.type.is_birth_fallback():
                                        birth_obj = evt.get_date_object()
                                        m_year = birth_obj.get_year()
                                        m_role = "ROLLE "+ str(evt_ref.role)
                                        m_date = self._get_date(evt.get_date_object())
                                diff = m_year - b_year
                                
                                                                                       
                                death_ref = pn.get_death_ref()
                                d_year = 0
                                if death_ref:
                                    death_obj = self.database.get_event_from_handle(death_ref.ref).get_date_object()
                                    if death_obj.get_quality() is not QUAL_ESTIMATED:
                                        d_year = death_obj.get_year()                                     
                                                
                                place_d = place_displayer.display_event(self.database, event)
#                                b_year = event.get_date_object().to_calendar(cal).get_year() 
#                                d_year = event.get_date_object().to_calendar(cal).get_year()  
                                #m_year = event.get_date_object().to_calendar(cal).get_year()                                         
                        person_details = [ pn, person_name, person_ID, gender, b_year, d_year, m_year, m_role, m_date, diff,place_d]
                        print(person_details[1],person_details[2],person_details[3],person_details[4],person_details[5],person_details[6])
                        p_list.append(person_details)
                        

        i=1
        for pn in p_list:
            self.doc.start_row()
  
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            ST = "PN"+ str(pn[0])
#            self.doc.write_text(_("%s") % ST)
#    #        self.doc.write_text(_("Hallo0"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[1])
      #      self.doc.write_text(_("Hallo1"))
            self.doc.end_paragraph()
            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[2])
       #     self.doc.write_text(_("Hallo2"))
            self.doc.end_paragraph()
            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[3])
        #    self.doc.write_text(_("Hallo3"))
            self.doc.end_paragraph()
            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[4])
         #   self.doc.write_text(_("Hallo4"))
            self.doc.end_paragraph()
            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[5])
 #           self.doc.write_text(_("Hallo5"))
            self.doc.end_paragraph()
            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[6])
  #          self.doc.write_text(_("Hallo6"))
            self.doc.end_paragraph()
            self.doc.end_cell()

#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[7])
#  #          self.doc.write_text(_("Hallo7"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()

  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[8])
  #          self.doc.write_text(_("Hallo8"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[9])
  #          self.doc.write_text(_("Hallo9"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
#            diff= pn[6] - pn[4]
            self.doc.write_text(_("%s") % pn[10])
#            self.doc.write_text(diff)
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % i)
 #           self.doc.write_text(i)
  #          self.doc.write_text(_("LNR"))
            self.doc.end_paragraph()
            self.doc.end_cell()
            i +=1


            self.doc.end_row()

            

        
    def __get_place_handles(self, places):
        """
        This procedure converts a string of place GIDs to a list of handles
        """
        place_handles = [] 
        for place_gid in places.split():
            place = self.database.get_place_from_gramps_id(place_gid)
            if place is not None:
                place_handles.append(place.get_handle())

        return place_handles
Ejemplo n.º 10
0
class ledigquote(Report):
    """
    ledigquote Report class
    """
    def __init__(self, database, options, user):
        """
        Create the ledigquote Report object produces the ledigquote report.
        
        The arguments are:

        database        - the GRAMPS database instance
        options         - instance of the Options class for this report
        user            - instance of a gen.user.User class

        This report needs the following parameters (class variables)
        that come in the options class.
        
        places          - List of places to report on.
#        classwidth          - classwidth of report, person or event
        incpriv         - Whether to include private data

        """

        Report.__init__(self, database, options, user)

        self._user = user
        menu = options.menu
        places = menu.get_option_by_name('places').get_value()
        self.classwidth  = menu.get_option_by_name('classwidth').get_value()
        self.incpriv = menu.get_option_by_name('incpriv').get_value()

        self.set_locale(menu.get_option_by_name('trans').get_value())

        name_format = menu.get_option_by_name("name_format").get_value()
        if name_format != 0:
            self._name_display.set_default_format(name_format)
        self._nd = self._name_display
        
        if self.incpriv:
            self.database = database
        else:
            self.database = PrivateProxyDb(database)

        filter_option = menu.get_option_by_name('filter')
        self.filter = filter_option.get_filter()
        self.sort = Sort(self.database)

        if self.filter.get_name() != '':
            # Use the selected filter to provide a list of place handles
            plist = self.database.iter_place_handles()
            self.place_handles = self.filter.apply(self.database, plist)
        else:
            # Use the place handles selected without a filter
            self.place_handles = self.__get_place_handles(places)

        self.place_handles.sort(key=self.sort.by_place_title_key)
        
    def write_report(self):
        """
        The routine that actually creates the report.
        At this point, the document is opened and ready for writing.
        """
        pdet_list=[]
        # Write the title line. Set in INDEX marker so that this section will be
        # identified as a major category if this is included in a Book report.

        title = self._("Ledigenquote und Verheiratetenanteile ")
        mark = IndexMark(title, INDEX_TYPE_TOC, 1)        
        self.doc.start_paragraph("PLC-ReportTitle")
        self.doc.write_text(title, mark)
        self.doc.end_paragraph()

        self.doc.start_paragraph("PLC-Section")
        self.doc.write_text("Enthält alle Personen, die in diesem Ort geboren oder getauft wurden")
        self.doc.end_paragraph()
        self.doc.start_table("LEQUODETTable", "SRC-LEQUODETTable")
        column_titles = [_("name"), _("Klasse"), _("ID"), _("m/w"), _("birth"), _("death"), _("marriage"), _("date"), _("weitere Heiraten"), _("Alter Tod"), _("Alter Hochzeit"), _("place"), _("LNR") ] 
        i = 0
        self.doc.start_row()
        for title in column_titles:
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(title)
            self.doc.end_paragraph()
            self.doc.end_cell()
        self.doc.end_row()

        self.__write_data(pdet_list, self.classwidth)

        self.doc.end_table()
        
# Männer Tabelle        
        self.doc.start_paragraph("PLC-Section")
        self.doc.write_text("Ledigenquote und Verheiratetenanteile bei Männern")
        self.doc.end_paragraph()
        self.doc.start_table("LEQUODETTable", "SRC-LEQUODETTable")
        column_titles = [_("cat"), _("ID"), _("m/w"), _("birth"), _("birthclass"),_("death"), _("marriage"), _("date"), _("weitere Heiraten"), _("Alter Tod"), _("Alter Hochzeit"), _("place"), _("LNR") ] 
        i = 0
        self.doc.start_row()
        for title in column_titles:
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(title)
            self.doc.end_paragraph()
            self.doc.end_cell()
        self.doc.end_row()

        self.__write_statistics(pdet_list, self.classwidth)

        self.doc.end_table()

    def __write_data(self,pdet_list,clw):
        """
        This procedure writes out each of the families related to the place
        """
        i = 0
        iw = 0
        ifam = 0
        p_set=set()
#        pdet_list=[]
        QUAL_ESTIMATED = 1
        gender_dict ={0:"w",1:"m", 2:"u"}


        for person in self.database.iter_people():
            birth_event = get_birth_or_fallback(self.database, person)
            b_year = 0
            alt_tod = 0
            b_role = "ROLLE"
            if birth_event:
                if birth_event.get_place_handle() in self.place_handles:
                    birth_obj = birth_event.get_date_object()
                    if birth_obj.get_quality() is not QUAL_ESTIMATED:
                        place_d = place_displayer.display_event(self.database, birth_event)                             
                        person_name = person.get_primary_name().get_surname()
                        person_ID = person.get_gramps_id()
                        gender = gender_dict[person.get_gender()]

                        m_date = self._get_date(birth_obj)
        #                if birth_obj.get_quality() is not QUAL_ESTIMATED:
                        b_year = int(birth_obj.get_year())
          #              b_role = "ROLLE "+ str(birth_event.role)
        #                    b_place = 
                        death_event = get_death_or_fallback(self.database, person)
                        d_year = 0
                        if death_event:
                            death_obj = death_event.get_date_object()
            #                if death_obj.get_quality() is not QUAL_ESTIMATED:
                            d_year = death_obj.get_year() 
                            alt_tod = d_year - b_year
                        m_year = 0    
    
                        alt_marr = 0
    
                        m_list=[]
    #                    m_date = ""
                        m_wm = "WEIT"
                        for family_handle in person.get_family_handle_list():
    #                        print(family_handle)
                            family = self.database.get_family_from_handle(family_handle)
            
                            for fam_event_ref in family.get_event_ref_list():
    #                            print(fam_event_ref)
                                if fam_event_ref:
                                    fam_event = self.database.get_event_from_handle(fam_event_ref.ref)
                                    if fam_event.type == EventType.MARRIAGE:
                                        print(fam_event.type)
                                        m_list.append(fam_event.get_date_object().get_year())
    #                                    print(fam_event.get_date_object().get_year())
    #                                    m_year = fam_event.get_date_object().get_year()
                        if len(m_list)>0:
                            m_year = min(m_list)
                            alt_marr = m_year - b_year
    #                    else:
    #                        m_year = 0    
                        for m in m_list:
                            m_wm = m_wm+" "+str(m)               
                        
                
        #                person_details = [ person, person_name, person_ID, gender, b_year, d_year, m_year, b_role, m_date, diff,place_d]
                        person_details = [ person, person_name, person_ID, gender, b_year, d_year, m_year, m_date, m_wm, alt_tod, alt_marr, place_d]
        
                        pdet_list.append(person_details)
        i=1
        for pn in pdet_list:
            self.doc.start_row()
  
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            ST = "PN"+ str(pn[0])
#            self.doc.write_text(_("%s") % ST)
#    #        self.doc.write_text(_("Hallo0"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[1])
      #      self.doc.write_text(_("Hallo1"))
            self.doc.end_paragraph()
            self.doc.end_cell()
            
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
           
            Klasse = int(int(pn[4])/clw)*clw
            self.doc.write_text(_("%s") % Klasse)
            self.doc.end_paragraph()
            self.doc.end_cell()
    
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[2])
       #     self.doc.write_text(_("Hallo2"))
            self.doc.end_paragraph()
            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[3])
        #    self.doc.write_text(_("Hallo3"))
            self.doc.end_paragraph()
            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[4])
         #   self.doc.write_text(_("Hallo4"))
            self.doc.end_paragraph()
            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[5])
 #           self.doc.write_text(_("Hallo5"))
            self.doc.end_paragraph()
            self.doc.end_cell()
  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[6])
  #          self.doc.write_text(_("Hallo6"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[7])
  #          self.doc.write_text(_("Hallo7"))
            self.doc.end_paragraph()
            self.doc.end_cell()

  
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[8])
  #          self.doc.write_text(_("Hallo8"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[9])
  #          self.doc.write_text(_("Hallo9"))
            self.doc.end_paragraph()
            self.doc.end_cell()

            
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
#            diff= pn[6] - pn[4]
            self.doc.write_text(_("%s") % pn[10])
#            self.doc.write_text(diff)
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % pn[11])
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % i)
 #           self.doc.write_text(i)
  #          self.doc.write_text(_("LNR"))
            self.doc.end_paragraph()
            self.doc.end_cell()
            i +=1


            self.doc.end_row()

#########################
    def __write_statistics(self,list,clw):
        """
        This procedure writes out each of the families related to the place
        """
# build classes
        #year_list = list(pdet_list[4])
#        print(min(list[4]))
        start = 1640
        grownup = 18
        byear_list=[]
        dyear_list=[]
        myear_list=[]
        for ldi in list:
            byear_list.append(int(ldi[4]))
            dyear_list.append(int(ldi[5]))
            myear_list.append(int(ldi[6]))
#            print(ldi[4], ldi[5], ldi[6])
#        for l in byear_list:
#            print(l)
#        print(min(byear_list),max(byear_list),len(byear_list))
#        print(min(dyear_list),max(dyear_list),len(dyear_list))
#        print(min(myear_list),max(myear_list),len(myear_list))
#        for l4 in list:
#            print(l4[4])
#        print(min(byear_list),max(byear_list),len(byear_list))

        schr =[]
        anz_birth =defaultdict(int)
        anz_death =defaultdict(int)
        anz_grownup =defaultdict(int)
        anz_married=defaultdict(int)
        anz_notmarried=defaultdict(int)
        anz_2529married=defaultdict(int)
        anz_2529=defaultdict(int)
        ant_2529=defaultdict(int)
        anz_45=defaultdict(int)
        ant_45=defaultdict(int)
        anz_45married=defaultdict(int)
        anz_20=defaultdict(int)
        ant_20=defaultdict(int)
        anz_20married=defaultdict(int)


        anz_ind=defaultdict(int)
        
        
        s = start
        print(clw)
        while (s < max(byear_list)and (s < 2100)):
            s+=int(clw)
            schr.append(s)
        for i,si in enumerate(schr):
            print("Jahr",i, si)
            
# person_details = [ person, person_name, person_ID, gender, b_year, d_year, m_year, m_date, m_wm, alt_tod, alt_marr, place_d]
#                     0         1           2         3       4        5       6       7       8     9        10       11    
# pdet_list.append(person_details)             

        for by in sorted(list, key = itemgetter(4,5)):
            if by[4]>start:
                ind = int(int(by[4])/clw)*clw
                print("CODE ", by[4], ind)
                anz_ind[ind]=ind

#anz geb
                anz_birth[ind]+=1
# dav tot
                if by[5]>0:
                    anz_death[ind]+=1   
# sicher nicht verheiratet
                    if by[10]==0:   
                        anz_notmarried[ind]+=1       

# erwachsenenalter ereicht
                if by[9]>=grownup:   
                    anz_grownup[ind]+=1
# verheiratet                           
                if by[10]>=0:   
                    anz_married[ind]+=1       
# Anteil Verheirateter bei 25-27jg
                if (by[5]>24) or (by[5] ==0 and by[10]<30):
                    anz_2529[ind]+=1
                    if (by[10]<30)and (by[10]>0):   
                        anz_2529married[ind]+=1

# Anteil Verheirateter bei >45jg
                if (by[5]>44) or (by[5] ==0 and by[10]<45):
                    anz_45[ind]+=1
                    if (by[10]<46)and (by[10]>0):   
                        anz_45married[ind]+=1
                        
# Anteil Verheirateter bei 20jg
                if (by[5]>44) or (by[5] ==0 and by[10]<21):
                    anz_20[ind]+=1
                    if (by[10]<21)and (by[10]>0):   
                        anz_20married[ind]+=1
                        



        for q in anz_2529married:
            print(q, anz_2529married[q], anz_2529[q], anz_2529married[q]/anz_2529[q], q / anz_2529[q])               
  #          ant_2529married = q / anz_2529[q]
#            print(q)    

        print("q", " anz_birth[q]", "anz_2529married[q]", "anz_2529[q]", "anz_2529married[q]/anz_2529[q]", "q / anz_2529[q]")    
        for q in anz_birth:
            print(q, anz_birth[q], anz_2529married[q], anz_2529[q], anz_2529married[q]/anz_2529[q], q / anz_2529[q])               
  

                                   

#        for i,si in enumerate(anz_birth):
#            print(i, si)
#        print (anz_birth.items())   

        title_stat = ["Jahr", "Geburten", "davon mit Sterbedatum", "Erwachsenenalter erreicht", "je verheiratet", "sicher ledig", "Verheiratetenanteil bei 25-30 jährigen Männern", "Verheiratetenanteil bei Männern über 45 Jahren", "Ledigenquote der über 45jährigen", "Ledigenquote der über 20jährigen"]
        
        self.doc.start_row()
        for t in title_stat:
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(t)
            self.doc.end_paragraph()
            self.doc.end_cell() 
        self.doc.end_row()
        
        for k in sorted(anz_birth.keys()):
            self.doc.start_row()
#            print(k, anz_birth[k])        
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % k)
            self.doc.end_paragraph()
            self.doc.end_cell()
            
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % anz_birth[k])
            self.doc.end_paragraph()
            self.doc.end_cell()

            
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % anz_ind[k])
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#            
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % anz_death[k])
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % anz_grownup[k])
            self.doc.end_paragraph()
            self.doc.end_cell()
            
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % anz_married[k])
            self.doc.end_paragraph()
            self.doc.end_cell()
            
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(_("%s") % anz_notmarried[k])
            self.doc.end_paragraph()
            self.doc.end_cell()
            
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            Pro25 = anz_2529married[k]*100/ anz_2529[k]
            self.doc.write_text(_("%.2f") % Pro25)            
            self.doc.end_paragraph()
            self.doc.end_cell()            

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            Pro45 = anz_45married[k]*100/ anz_45[k]
            self.doc.write_text(_("%.2f") % Pro45)            
            self.doc.end_paragraph()
            self.doc.end_cell()    
            
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            led45 = 100-(anz_45married[k]*100/ anz_45[k])
            self.doc.write_text(_("%.2f") % led45)            
            self.doc.end_paragraph()
            self.doc.end_cell()    
            
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            led20 = 100-anz_20married[k]*100/ anz_45[k]
            self.doc.write_text(_("%.2f") % led20)            
            self.doc.end_paragraph()
            self.doc.end_cell()    
            
            
                    
            self.doc.end_row()

                

        #cm=min()
#        i=1
#        for pn in pdet_list:
#            self.doc.start_row()
#  
##            self.doc.start_cell("SRC-TableColumn")
##            self.doc.start_paragraph("SRC-ColumnTitle")
##            ST = "PN"+ str(pn[0])
##            self.doc.write_text(_("%s") % ST)
##    #        self.doc.write_text(_("Hallo0"))
##            self.doc.end_paragraph()
##            self.doc.end_cell()
#  
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[1])
#      #      self.doc.write_text(_("Hallo1"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#  
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[2])
#       #     self.doc.write_text(_("Hallo2"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#  
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[3])
#        #    self.doc.write_text(_("Hallo3"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#  
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[4])
#         #   self.doc.write_text(_("Hallo4"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#  
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[5])
# #           self.doc.write_text(_("Hallo5"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#  
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[6])
#  #          self.doc.write_text(_("Hallo6"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[7])
#  #          self.doc.write_text(_("Hallo7"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[8])
#  #          self.doc.write_text(_("Hallo8"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("%s") % pn[9])
#  #          self.doc.write_text(_("Hallo9"))
#            self.doc.end_paragraph()
#            self.doc.end_cell()
#
#            
#            self.doc.start_cell("SRC-TableColumn")
#            self.doc.start_paragraph("SRC-ColumnTitle")
##            diff= pn[6] - pn[4]
#            self.doc.write_text(_("%s") % pn[10])
##            self.doc.write_text(diff)
#            self.doc.end_paragraph()
 #           self.doc.end_cell()
 #
 #           self.doc.start_cell("SRC-TableColumn")
 #           self.doc.start_paragraph("SRC-ColumnTitle")
 #           self.doc.write_text(_("%s") % pn[11])
 #           self.doc.end_paragraph()
 #           self.doc.end_cell()
 #
 #           self.doc.start_cell("SRC-TableColumn")
 #           self.doc.start_paragraph("SRC-ColumnTitle")
 #           self.doc.write_text(_("%s") % i)
 ##           self.doc.write_text(i)
 # #          self.doc.write_text(_("LNR"))
 #           self.doc.end_paragraph()
  #          self.doc.end_cell()
  #          i +=1
  #
  #
  #          self.doc.end_row()
  #
#########################
            
    def __format_date(self, date_object):
        if not date_object: return
        d=date_object.get_day()    
        m=date_object.get_month()
        y=date_object.get_year()
        if (d == 0) and (m == 0):
            date_f = (" %s" % y)
        elif (d == 0) and not (m == 0):
            date_f = (" %s.%s" % (m, y))  
        else:       
            date_f = (" %s.%s.%s" % (d, m, y)) 
        return date_f           
        

        
    def __get_place_handles(self, places):
        """
        This procedure converts a string of place GIDs to a list of handles
        """
        place_handles = [] 
        for place_gid in places.split():
            place = self.database.get_place_from_gramps_id(place_gid)
            if place is not None:
                place_handles.append(place.get_handle())

        return place_handles
Ejemplo n.º 11
0
class PeopleStatBuDReport(Report):
    """
    Place Report class
    """
    def __init__(self, database, options, user):
        """
        Create the PlaceReport object produces the Place report.
        
        The arguments are:

        database        - the GRAMPS database instance
        options         - instance of the Options class for this report
        user            - instance of a gen.user.User class

        This report needs the following parameters (class variables)
        that come in the options class.
        
        places          - List of places to report on.
        incpriv         - Whether to include private data

        """

        Report.__init__(self, database, options, user)

        self._user = user
        menu = options.menu
        places = menu.get_option_by_name('places').get_value()
        self.incpriv = menu.get_option_by_name('incpriv').get_value()

        if self.incpriv:
            self.__db = database
        else:
            self.__db = PrivateProxyDb(database)


        filter_option = menu.get_option_by_name('filter')
        self.filter = filter_option.get_filter()
        self.sort = Sort(self.__db)

        if self.filter.get_name() != '':
            # Use the selected filter to provide a list of place handles
            plist = self.__db.iter_place_handles()
            self.place_handles = self.filter.apply(self.__db, plist)
        else:
            # Use the place handles selected without a filter
            self.place_handles = self.__get_place_handles(places)

        self.place_handles.sort(key=self.sort.by_place_title_key)

    def write_report(self):
        """
        The routine the actually creates the report. At this point, the document
        is opened and ready for writing.
        """

        # Write the title line. Set in INDEX marker so that this section will be
        # identified as a major category if this is included in a Book report.

        title = _("Place Report")
        mark = IndexMark(title, INDEX_TYPE_TOC, 1)        
        self.doc.start_paragraph("PLC-ReportTitle")
        self.doc.write_text(title, mark)
        self.doc.end_paragraph()
        self.__write_all_places()
        self.count_data()

    def __write_all_places(self):
        """
        This procedure writes out each of the selected places.
        """
        place_nbr = 1

        self._user.begin_progress(_("Place Report"), 
                                  _("Generating report"), 
                                  len(self.place_handles))
        
        for handle in self.place_handles:
            self.__write_place(handle, place_nbr)
            place_nbr += 1
            # increment progress bar
            self._user.step_progress()
            
        self._user.end_progress()
        
    def count_data(self):
        """
        This procedure counts the data
        """

#***********************************************************************
#        # build Stat dictionary using recursive function tree()
#        # Stat[Place_handle][Year][EVT][Gender][CNT]
#               
#       Place_handle    place handle    self.__db.get_event_from_handle(eventref.ref).get_place_handle()
#       Year            self__db.get_event_from_handle(eventref.ref).get_date_object().get_year()
#       EVT             'BIRTH' etc.
#       Gender          ['m' 'w' 'u']                                  
#       CT              int
#

        genderlist = ['m','w','u']
              
        BIRTH = 'Birth'
        BAPT  = 'Bapt'
        DEATH = 'Death'
        BURR  = 'Burrial'
        CONFIRMATION = 'Confirmation'
        MARRIAGE = 'Marriage'
        
        sorttabledict ={'m':0,'w':1,'u':2,'ztotal':3}
        
        self._user.begin_progress(_("Place Stat Report"), 
                                  _("Generating report"), 
                                  100)
                                  
#                                  len(self.place_handles))

        Stat = StatTree()
        CT = 0
                
        for pe in self.__db.iter_people():
            EVT = BAPT
            for eventref in pe.event_ref_list:
                CT +=1
                if not eventref:
                    continue
                elif eventref.role != EventRoleType.PRIMARY:
                    # Only match primaries, no witnesses
                    continue
                if self.__db.get_event_from_handle(eventref.ref).get_date_object():
                    if self.__db.get_event_from_handle(eventref.ref).get_type() == EventType.BAPTISM:
                        EVT = BAPT
#                       continue
                    elif self.__db.get_event_from_handle(eventref.ref).get_type() == EventType.BIRTH:
                        if EVT == BAPT:
                            continue
                        else:
                            EVT = BIRTH
                            continue
                    elif self.__db.get_event_from_handle(eventref.ref).get_type() == EventType.BURIAL:
                        EVT = BURR
                    elif self.__db.get_event_from_handle(eventref.ref).get_type() == EventType.DEATH:
                        if EVT == BURR:
                            continue
                        else:
                            EVT = DEATH
                            continue
                    else:
                        continue    
                    Stat[self.__db.get_event_from_handle(eventref.ref).get_place_handle()][self.__db.get_event_from_handle(eventref.ref).get_date_object().get_year()][EVT][genderlist[pe.get_gender()]][CT] = "CNT"
                    
                # increment progress bar
                self._user.step_progress()

        self.doc.start_table("PersonRoleEventTable", "SRC-PersonEventRoleTable")
        column_titles = [_("year"), _("count"), _("m"), _("w"), _("u"),("total"), _("count"), _("m"), _("w"), _("u"),("total"), _("count"), _("m"), _("w"), _("u"),("total")] 
        i = 0
        self.doc.start_row()
        for title in column_titles:
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(title)
            self.doc.end_paragraph()
            self.doc.end_cell()
        self.doc.end_row()
        
        Anzk = 0
        Sumv = 0    
        
        self.doc.start_row()
        
        self.doc.start_cell("SRC-TableColumn")
        self.doc.start_paragraph("SRC-ColumnTitle")
#        self.doc.write_text(_("Anzahl Elemente in Stat [ORTE]: %s") %
#                                    len(Stat)) 
        self.doc.write_text(_("[ORTE]: %s") %
                                    len(Stat)) 
        self.doc.end_paragraph()
        self.doc.end_cell()     
        
        self.doc.end_row()

#       Orte schreiben
# 
#####   self.place_handles

        StKeys  = Stat.keys()
#        for h in StKeys:
        for h in self.place_handles:

            self.doc.start_row()
     
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            try:
#                self.doc.write_text(_("Anzahl Elemente in Stat.keys: %s") %
                self.doc.write_text(_("Place: %s") %
                                        self.__db.get_place_from_handle(h).title)
            except:
#                self.doc.write_text(_("Anzahl Elemente in Stat.keys: %s") %
                self.doc.write_text(_("Place: %s") %
                                        "ohne Bezeichnung")
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
#            self.doc.write_text(_("Anzahl jahr in Stat[i]: %s") %
#                                            len(Stat[h].keys())) 
            self.doc.write_text(_("%s") %
                                            len(Stat[h].keys())) 

            self.doc.end_paragraph()
            self.doc.end_cell()

            
            self.doc.end_row()

#       Jahre schreiben
#            
            for i in sorted(Stat[h].keys()):
                self.doc.start_row()
     
                self.doc.start_cell("SRC-TableColumn")
                self.doc.start_paragraph("SRC-ColumnTitle")
#                self.doc.write_text(_("Jahr in Stat[i]: %s") %
                self.doc.write_text(_("%s") %
                                            i) 
                self.doc.end_paragraph()
                self.doc.end_cell()
                
#       Init sumyear
                sumyeardic = {'m':'0' ,'w':'0', 'u':'0', 'ztotal':'0'}
                rowdic = {'m':'0' ,'w':'0', 'u':'0','ztotal':'0' }

#       Ereignisse schreiben
# 
                baptdru = 0
                burrdru = 0
                gesdru = 0
                for k in sorted(Stat[h][i].keys()):
#                    write BAPT or BURRIED
#                    self.doc.start_row()
      ##write BAPT              
                    if (baptdru == 0) and (burrdru == 0) and (k == BAPT):
                         rsum = 0
                         for gl in genderlist:
                             for l in Stat[h][i][k].keys():
                                 if l == gl:
                                     rowdic[gl] = str(len(Stat[h][i][k][l].keys()))
                                     rsum = rsum + len(Stat[h][i][k][l].keys())
                                     # increment progress bar
                                     self._user.step_progress()
                                 else:
                                     continue
                         rowdic['ztotal'] = str(rsum)             
                         sumyeardic = rowdic.copy( )
                         
                         
                         self.doc.start_cell("SRC-TableColumn")
                         self.doc.start_paragraph("SRC-ColumnTitle")
      #                   self.doc.write_text(_("Ereignis pro Jahr in Stat[h][k]: %s") %
                         self.doc.write_text(_("%s") %
                                                    k) 
                         self.doc.end_paragraph()
                         self.doc.end_cell()
      
                      
                         for gl in sorted(rowdic.keys(),key=sorttabledict.__getitem__):
                             self.doc.start_cell("SRC-TableColumn")
                             self.doc.start_paragraph("SRC-ColumnTitle")
                             self.doc.write_text(_("%s") %
                                                            rowdic[gl])
#                             self.doc.write_text(_("%s") %
 #                                                           gl)
                             self.doc.end_paragraph()
                             self.doc.end_cell()
                          # increment progress bar
                         self._user.step_progress()
                         baptdru = 1
                         gesdru += 1
                        
                    if (baptdru == 0) and (burrdru == 0) and (k == BURR):

                        ##Write LEER           
                        for ec in range(0,5):
                            self.doc.start_cell("SRC-TableColumn")
                            self.doc.start_paragraph("SRC-ColumnTitle")
                            self.doc.write_text(_("    "))
#                            self.doc.write_text(_("LEER %s") %
#                                                           len(Stat[h][i][k].keys()))

                            self.doc.end_paragraph()
                            self.doc.end_cell()
                        baptdru = 1    
  
#   ##write BURR
                    if (baptdru == 1) and (burrdru == 0) and (k == BURR):

                        rsum = 0
                        for gl in genderlist:
                            for l in Stat[h][i][k].keys():
                                if l == gl:
                                    rowdic[gl] = str(len(Stat[h][i][k][l].keys()))
                                    rsum = rsum + len(Stat[h][i][k][l].keys())
                                    # increment progress bar
                                    self._user.step_progress()
                                else:
                                    continue
                        rowdic['ztotal'] = str(rsum)             
#4.1                      for gl in sorted(rowdic.iterkeys(),key=sorttabledict.__getitem__):
                        for gl in sorted(rowdic.keys(),key=sorttabledict.__getitem__):
                             sumyeardic[gl]=str(int(sumyeardic[gl])-int(rowdic[gl]))

                        self.doc.start_cell("SRC-TableColumn")
                        self.doc.start_paragraph("SRC-ColumnTitle")
    #                    self.doc.write_text(_("Ereignis pro Jahr in Stat[h][k]: %s") %
                        self.doc.write_text(_("%s") %
                                                   k) 
                        self.doc.end_paragraph()
                        self.doc.end_cell()

                    
#4.1                        for gl in sorted(rowdic.iterkeys(),key=sorttabledict.__getitem__):
                        for gl in sorted(rowdic.keys(),key=sorttabledict.__getitem__):
                            self.doc.start_cell("SRC-TableColumn")
                            self.doc.start_paragraph("SRC-ColumnTitle")
                            self.doc.write_text(_("%s") %
                                                           rowdic[gl])
#                            self.doc.write_text(_("%s") %
 #                                                           gl)
                            self.doc.end_paragraph()
                            self.doc.end_cell()
                        # increment progress bar
                        self._user.step_progress()
                        burrdru = 1
                        gesdru = 2

                if (gesdru == 1):
                    ##Write LEER           
                    for ec in range(0,5):
                        self.doc.start_cell("SRC-TableColumn")
                        self.doc.start_paragraph("SRC-ColumnTitle")
                        self.doc.write_text(_("    "))
#                            self.doc.write_text(_("LEER %s") %
#                                                           len(Stat[h][i][k].keys()))


                        self.doc.end_paragraph()
                        self.doc.end_cell()
                    burrdru = 1


    ##write ZTOTAL
                   
                self.doc.start_cell("SRC-TableColumn")
                self.doc.start_paragraph("SRC-ColumnTitle")
                self.doc.write_text(_("ZTOTAL %s") %
                                               gesdru)
                self.doc.end_paragraph()
                self.doc.end_cell()

#4.1                for gl in sorted(sumyeardic.iterkeys(),key=sorttabledict.__getitem__):
                for gl in sorted(sumyeardic.keys(),key=sorttabledict.__getitem__):
                    self.doc.start_cell("SRC-TableColumn")
                    self.doc.start_paragraph("SRC-ColumnTitle")
                    self.doc.write_text(_("%s") %
                                                   sumyeardic[gl])
 #                   self.doc.write_text(_("%s") %
 #                                                           gl)
                    self.doc.end_paragraph()
                    self.doc.end_cell()
                self.doc.end_row()
               
           
                      
               #########################################################################
                                                     
        self.doc.end_table()
            
        self._user.end_progress()


        self.doc.start_table("RoleStatisticTable", "SRC-StatTable")
        stat_column_titles = [_("Relation"), _("count"), _("Percent")] 
        i = 0
        self.doc.start_row()
        for title in stat_column_titles:
            self.doc.start_cell("SRC-TableColumn")
            self.doc.start_paragraph("SRC-ColumnTitle")
            self.doc.write_text(title)
            self.doc.end_paragraph()
            self.doc.end_cell()
        self.doc.end_row()          
        
        self.doc.end_table()

               
 
    def __write_place(self, handle, place_nbr):
        """
        This procedure writes out the details of a single place
        """
        place = self.__db.get_place_from_handle(handle)
#p        location = place.get_main_location()
#        location = get_main_location(self.__db, place)
#
#        place_details = [_("Gramps ID: %s ") % place.get_gramps_id(),
#                         _("Street: %s ") % location.get_street(),
#                         _("Parish: %s ") % location.get_parish(),
#                         _("Locality: %s ") % location.get_locality(),
#                         _("City: %s ") % location.get_city(),
#                         _("County: %s ") % location.get_county(),
#                         _("State: %s") % location.get_state(),
#                         _("Country: %s ") % location.get_country()]
        self.doc.start_paragraph("PLC-PlaceTitle")
        self.doc.write_text(("%(nbr)s. %(place)s") % 
                                {'nbr' : place_nbr,
                                 'place' : place.get_title()})
        self.doc.end_paragraph()
        
        
        
    def __get_place_handles(self, places):
        """
        This procedure converts a string of place GIDs to a list of handles
        """
        place_handles = [] 
        for place_gid in places.split():
            place = self.__db.get_place_from_gramps_id(place_gid)
            if place is not None:
                #place can be None if option is gid of other fam tree
                place_handles.append(place.get_handle())

        return place_handles