Пример #1
0
    def placelistpage(self, report, title, place_handles):
        """
        Create a place index

        @param: report        -- The instance of the main report class for
                                 this report
        @param: title         -- Is the title of the web page
        @param: place_handles -- The handle for the place to add
        """
        BasePage.__init__(self, report, title)

        output_file, sio = self.report.create_file("places")
        result = self.write_header(self._("Places"))
        placelistpage, dummy_head, dummy_body, outerwrapper = result
        ldatec = 0
        prev_letter = " "

        # begin places division
        with Html("div", class_="content", id="Places") as placelist:
            outerwrapper += placelist

            # place list page message
            msg = self._(
                "This page contains an index of all the places in the "
                "database, sorted by their title. "
                "Clicking on a place’s "
                "title will take you to that place’s page.")
            placelist += Html("p", msg, id="description")

            # begin alphabet navigation
            index_list = get_first_letters(self.r_db,
                                           place_handles,
                                           _KEYPLACE,
                                           rlocale=self.rlocale)
            alpha_nav = alphabet_navigation(index_list, self.rlocale)
            if alpha_nav is not None:
                placelist += alpha_nav

            # begin places table and table head
            with Html("table",
                      class_="infolist primobjlist placelist") as table:
                placelist += table

                # begin table head
                thead = Html("thead")
                table += thead

                trow = Html("tr")
                thead += trow

                if self.display_coordinates:
                    trow.extend(
                        Html("th", label, class_=colclass, inline=True)
                        for (label, colclass
                             ) in [[self._("Letter"), "ColumnLetter"],
                                   [self._("Place Name | Name"), "ColumnName"],
                                   [self._("State/ Province"), "ColumnState"],
                                   [self._("Country"), "ColumnCountry"],
                                   [self._("Latitude"), "ColumnLatitude"],
                                   [self._("Longitude"), "ColumnLongitude"]])
                else:
                    trow.extend(
                        Html("th", label, class_=colclass, inline=True)
                        for (label, colclass
                             ) in [[self._("Letter"), "ColumnLetter"],
                                   [self._("Place Name | Name"), "ColumnName"],
                                   [self._("State/ Province"), "ColumnState"],
                                   [self._("Country"), "ColumnCountry"]])

                handle_list = sort_places(self.r_db, place_handles,
                                          self.rlocale)
                first = True

                # begin table body
                tbody = Html("tbody")
                table += tbody

                for (dummy_pname, place_handle) in handle_list:
                    place = self.r_db.get_place_from_handle(place_handle)
                    if place:
                        if place.get_change_time() > ldatec:
                            ldatec = place.get_change_time()
                        plc_title = self.report.obj_dict[Place][place_handle][
                            1]
                        main_location = get_main_location(self.r_db, place)

                        if plc_title and plc_title != " ":
                            letter = get_index_letter(first_letter(plc_title),
                                                      index_list, self.rlocale)
                        else:
                            letter = ' '

                        trow = Html("tr")
                        tbody += trow

                        tcell = Html("td", class_="ColumnLetter", inline=True)
                        trow += tcell
                        if first or primary_difference(letter, prev_letter,
                                                       self.rlocale):
                            first = False
                            prev_letter = letter
                            trow.attr = 'class = "BeginLetter"'

                            ttle = self._("Places beginning "
                                          "with letter %s") % letter
                            tcell += Html("a", letter, name=letter, title=ttle)
                        else:
                            tcell += " "

                        trow += Html("td",
                                     self.place_link(place.get_handle(),
                                                     plc_title,
                                                     place.get_gramps_id()),
                                     class_="ColumnName")

                        trow.extend(
                            Html("td",
                                 data or " ",
                                 class_=colclass,
                                 inline=True) for (colclass, data) in
                            [[
                                "ColumnState",
                                main_location.get(PlaceType.STATE, '')
                            ],
                             [
                                 "ColumnCountry",
                                 main_location.get(PlaceType.COUNTRY, '')
                             ]])

                        if self.display_coordinates:
                            tcell1 = Html("td",
                                          class_="ColumnLatitude",
                                          inline=True)
                            tcell2 = Html("td",
                                          class_="ColumnLongitude",
                                          inline=True)
                            trow += (tcell1, tcell2)

                            if place.lat and place.long:
                                latitude, longitude = conv_lat_lon(
                                    place.lat, place.long, "DEG")
                                tcell1 += latitude
                                tcell2 += longitude
                            else:
                                tcell1 += ' '
                                tcell2 += ' '

        # add clearline for proper styling
        # add footer section
        footer = self.write_footer(ldatec)
        outerwrapper += (FULLCLEAR, footer)

        # send page out for processing
        # and close the file
        self.xhtml_writer(placelistpage, output_file, sio, ldatec)
Пример #2
0
    def placelistpage(self, report, the_lang, the_title):
        """
        Create a place index

        @param: report        -- The instance of the main report class
                                 for this report
        @param: the_lang      -- The lang to process
        @param: the_title     -- The title page related to the language
        """
        BasePage.__init__(self, report, the_lang, the_title)

        output_file, sio = self.report.create_file("places")
        result = self.write_header(self._("Places"))
        placelistpage, dummy_head, dummy_body, outerwrapper = result
        ldatec = 0

        # begin places division
        with Html("div", class_="content", id="Places") as placelist:
            outerwrapper += placelist

            # place list page message
            msg = self._("This page contains an index of all the places in the "
                         "database, sorted by their title. "
                         "Clicking on a place’s "
                         "title will take you to that place’s page.")
            placelist += Html("p", msg, id="description")

            # begin alphabet navigation
            # Assemble all the places
            index = AlphabeticIndex(self.rlocale)
            # self.report.obj_dict[PlaceName] is a dict with key place_name and
            # values (place_fname, place_name, place.gramps_id, event)
            for (place_name, value) in self.report.obj_dict[PlaceName].items():
                index.addRecord(place_name, value)

            # Extract the buckets from the index
            index_list = []
            index.resetBucketIterator()
            while index.nextBucket():
                if index.bucketRecordCount != 0:
                    index_list.append(index.bucketLabel)
            # Output the navigation
            alpha_nav = alphabet_navigation(index_list, self.rlocale)
            if alpha_nav:
                placelist += alpha_nav

            # begin places table and table head
            with Html("table",
                      class_="infolist primobjlist placelist") as table:
                placelist += table

                # begin table head
                thead = Html("thead")
                table += thead

                trow = Html("tr")
                thead += trow

                if self.display_coordinates:
                    trow.extend(
                        Html("th", label, class_=colclass, inline=True)
                        for (label, colclass) in [
                            [self._("Letter"), "ColumnLetter"],
                            [self._("Name", "Place Name"), "ColumnName"],
                            [self._("State/Province"), "ColumnState"],
                            [self._("Country"), "ColumnCountry"],
                            [self._("Latitude"), "ColumnLatitude"],
                            [self._("Longitude"), "ColumnLongitude"]
                        ]
                    )
                else:
                    trow.extend(
                        Html("th", label, class_=colclass, inline=True)
                        for (label, colclass) in [
                            [self._("Letter"), "ColumnLetter"],
                            [self._("Name", "Place Name"), "ColumnName"],
                            [self._("State/Province"), "ColumnState"],
                            [self._("Country"), "ColumnCountry"]
                        ]
                    )

                # begin table body
                tbody = Html("tbody")
                table += tbody

                # For each bucket, output the places in that bucket
                index.resetBucketIterator()
                output = []
                dup_index = 0
                while index.nextBucket():
                    if index.bucketRecordCount != 0:
                        bucket_letter = index.bucketLabel
                        bucket_link = bucket_letter
                        if bucket_letter in output:
                            bucket_link = "%s (%i)" % (bucket_letter, dup_index)
                            dup_index += 1
                        output.append(bucket_letter)
                        # Assemble all the places in this bucket into a dict for
                        # sorting
                        place_dict = dict()
                        while index.nextRecord():
                            place_name = index.recordName
                            value = index.recordData
                            place_dict[place_name] = value

                        handle_list = sort_places(self.r_db,
                                                place_dict,
                                                self.rlocale)
                        first_place = True
                        for (pname, place_handle) in handle_list:
                            (ldatec, first_place) \
                            = self.__output_place(ldatec,
                                                  trow, first_place, pname,
                                                  place_handle, bucket_letter,
                                                  bucket_link)

        # add clearline for proper styling
        # add footer section
        footer = self.write_footer(ldatec)
        outerwrapper += (FULLCLEAR, footer)

        # send page out for processing
        # and close the file
        self.xhtml_writer(placelistpage, output_file, sio, ldatec)