Example #1
0
 def _run(self):
     """
     Go through directories that are mentioned in the database via
     media files, and include all images that are not all ready
     included.
     """
     if not self.prepared:
         self.prepare()
     self.set_total(len(self.dir_list))
     for directory in self.dir_list:
         for (dirpath, dirnames, filenames) in os.walk(directory):
             if ".git" in dirnames:
                 dirnames.remove('.git')  # don't visit .git directories
             for filename in filenames:
                 media_full_path = os.path.join(dirpath, filename)
                 if media_full_path not in self.path_list:
                     self.path_list.append(media_full_path)
                     mime_type = get_type(media_full_path)
                     if is_image_type(mime_type):
                         obj = Media()
                         obj.set_path(media_full_path)
                         obj.set_mime_type(mime_type)
                         (root, ext) = os.path.splitext(filename)
                         obj.set_description(root)
                         self.db.add_media(obj, self.trans)
         self.update()
     return True
Example #2
0
 def _run(self):
     """
     Go through directories that are mentioned in the database via
     media files, and include all images that are not all ready
     included.
     """
     if not self.prepared:
         self.prepare()
     self.set_total(len(self.dir_list))
     for directory in self.dir_list:
         for (dirpath, dirnames, filenames) in os.walk(directory):
             if ".git" in dirnames:
                 dirnames.remove('.git')  # don't visit .git directories
             for filename in filenames:
                 media_full_path = os.path.join(dirpath, filename)
                 if media_full_path not in self.path_list:
                     self.path_list.append(media_full_path)
                     mime_type = get_type(media_full_path)
                     if is_image_type(mime_type):
                         obj = Media()
                         obj.set_path(media_full_path)
                         obj.set_mime_type(mime_type)
                         (root, ext) = os.path.splitext(filename)
                         obj.set_description(root)
                         self.db.add_media(obj, self.trans)
         self.update()
     return True
Example #3
0
    def placepage(self, report, the_lang, the_title, place_handle, place_name):
        """
        Create a place page

        @param: report       -- The instance of the main report class
                                for this report
        @param: the_lang     -- The lang to process
        @param: the_title    -- The title page related to the language
        @param: place_handle -- The handle for the place to add
        @param: place_name   -- The alternate place name
        """
        place = report.database.get_place_from_handle(place_handle)
        if not place:
            return
        BasePage.__init__(self, report, the_lang, the_title,
                          place.get_gramps_id())
        self.bibli = Bibliography()
        ldatec = place.get_change_time()
        apname = _pd.display(self.r_db, place)

        if place_name == apname: # store only the primary named page
            output_file, sio = self.report.create_file(place_handle, "plc")
        self.uplink = True
        self.page_title = place_name
        (placepage, head, dummy_body,
         outerwrapper) = self.write_header(_("Places"))

        self.placemappages = self.report.options['placemappages']
        self.mapservice = self.report.options['mapservice']
        self.googlemapkey = self.report.options['googlemapkey']
        self.stamenopts = self.report.options['stamenopts']

        # begin PlaceDetail Division
        with Html("div", class_="content", id="PlaceDetail") as placedetail:
            outerwrapper += placedetail

            media_list = place.get_media_list()
            if self.create_media:
                thumbnail = self.disp_first_img_as_thumbnail(media_list,
                                                             place)
                if thumbnail is not None:
                    if media_list[0].ref in self.report.obj_dict[Media]:
                        placedetail += thumbnail

            # add section title
            placedetail += Html("h3",
                                html_escape(place_name),
                                inline=True)

            # begin summaryarea division and places table
            with Html("div", id='summaryarea') as summaryarea:
                placedetail += summaryarea

                with Html("table", class_="infolist place") as table:
                    summaryarea += table

                    # list the place fields
                    self.dump_place(place, table)

            # place gallery
            if self.create_media and not self.report.options['inc_uplaces']:
                # Don't diplay media for unused places. It generates
                # "page not found" if they are not collected in pass 1.
                placegallery = self.disp_add_img_as_gallery(media_list, place)
                if placegallery is not None:
                    placedetail += placegallery

            # place notes
            notelist = self.display_note_list(place.get_note_list(), Place)
            if notelist is not None:
                placedetail += notelist

            # place urls
            urllinks = self.display_url_list(place.get_url_list())
            if urllinks is not None:
                placedetail += urllinks

            # add place map here
            # Link to Gramps marker
            fname = "/".join(['images', 'marker.png'])
            marker_path = self.report.build_url_image("marker.png",
                                                      "images", self.uplink)

            if self.placemappages:
                if place and (place.lat and place.long):
                    placetitle = place_name

                    # add narrative-maps CSS...
                    if the_lang and not self.usecms:
                        fname = "/".join(["..", "css", "narrative-maps.css"])
                    else:
                        fname = "/".join(["css", "narrative-maps.css"])
                    url = self.report.build_url_fname(fname, None, self.uplink)
                    head += Html("link", href=url, type="text/css",
                                 media="screen", rel="stylesheet")

                    # add MapService specific javascript code
                    src_js = GOOGLE_MAPS + "api/js"
                    if self.mapservice == "Google":
                        if self.googlemapkey:
                            src_js += "?key=" + self.googlemapkey
                        head += Html("script", type="text/javascript",
                                     src=src_js, inline=True)
                    else: # OpenStreetMap, Stamen...
                        src_js = self.secure_mode
                        src_js += ("ajax.googleapis.com/ajax/libs/jquery/1.9.1/"
                                   "jquery.min.js")
                        head += Html("script", type="text/javascript",
                                     src=src_js, inline=True)
                        src_js = "https://openlayers.org/en/latest/build/ol.js"
                        head += Html("script", type="text/javascript",
                                     src=src_js, inline=True)
                        url = "https://openlayers.org/en/latest/css/ol.css"
                        head += Html("link", href=url, type="text/css",
                                     rel="stylesheet")

                    # section title
                    placedetail += Html("h4", self._("Place Map"), inline=True)

                    # begin map_canvas division
                    with Html("div", id="map_canvas", inline=True) as canvas:
                        placedetail += canvas

            # add div for popups.
            if self.mapservice == "Google":
                with Html("div", id="popup", inline=True) as popup:
                    placedetail += popup
            else:
                with Html("div", id="popup", class_="ol-popup",
                          inline=True) as popup:
                    placedetail += popup
                    popup += Html("a", href="#", id="popup-closer",
                                  class_="ol-popup-closer")
                    popup += Html("div", id="popup-title",
                                  class_="ol-popup-title")
                    popup += Html("div", id="popup-content")
                with Html("div", id="tooltip", class_="ol-popup",
                          inline=True) as tooltip:
                    placedetail += tooltip
                    tooltip += Html("div", id="tooltip-content")

            # source references
            if not self.report.options['inc_uplaces']:
                # We can't display source reference when we display
                # unused places. These info are not in the collected objects.
                # This is to avoid "page not found" errors.
                srcrefs = self.display_ind_sources(place)
                if srcrefs is not None:
                    placedetail += srcrefs

            # References list
            ref_list = self.display_bkref_list(Place, place_handle)
            if ref_list is not None:
                placedetail += ref_list

            # Begin inline javascript code because jsc is a
            # docstring, it does NOT have to be properly indented
            if self.placemappages:
                if place and (place.lat and place.long):
                    latitude, longitude = conv_lat_lon(place.get_latitude(),
                                                       place.get_longitude(),
                                                       "D.D8")
                    tracelife = " "
                    if self.create_media and media_list:
                        for fmedia in media_list:
                            photo_hdle = fmedia.get_reference_handle()
                            photo = self.r_db.get_media_from_handle(photo_hdle)
                            mime_type = photo.get_mime_type()
                            descr = photo.get_description()

                            if mime_type and is_image_type(mime_type):
                                uplnk = self.uplink
                                (pth,
                                 dummy_) = self.report.prepare_copy_media(photo)
                                srbuf = self.report.build_url_fname
                                newpath = srbuf(pth, image=True, uplink=uplnk)
                                imglnk = self.media_link(photo_hdle, newpath,
                                                         descr, uplink=uplnk,
                                                         usedescr=False)
                                if photo_hdle in self.report.obj_dict[Media]:
                                    tracelife += str(imglnk)
                                break # We show only the first image
                    scripts = Html()
                    if self.mapservice == "Google":
                        with Html("script", type="text/javascript",
                                  indent=False) as jsc:
                            scripts += jsc
                            # Google adds Latitude/ Longitude to its maps...
                            plce = placetitle.replace("'", "\\'")
                            jsc += MARKER_PATH % marker_path
                            jsc += MARKERS % ([[plce,
                                                latitude,
                                                longitude,
                                                1, tracelife]],
                                              latitude, longitude,
                                              10)
                    elif self.mapservice == "OpenStreetMap":
                        with Html("script", type="text/javascript") as jsc:
                            scripts += jsc
                            jsc += MARKER_PATH % marker_path
                            jsc += OSM_MARKERS % ([[float(longitude),
                                                    float(latitude),
                                                    placetitle, tracelife]],
                                                  longitude, latitude, 10)
                            jsc += OPENLAYER
                    else: # STAMEN
                        with Html("script", type="text/javascript") as jsc:
                            scripts += jsc
                            jsc += MARKER_PATH % marker_path
                            jsc += STAMEN_MARKERS % ([[float(longitude),
                                                       float(latitude),
                                                       placetitle, tracelife]],
                                                     self.stamenopts,
                                                     longitude, latitude, 10)
                            jsc += OPENLAYER
                    placedetail += scripts

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

        # send page out for processing
        # and close the file
        if place_name == apname: # store only the primary named page
            self.xhtml_writer(placepage, output_file, sio, ldatec)