Exemplo n.º 1
0
def generate_view_context(pyntrest_handler):
    """TODO"""

    full_html_arr = []
    local_albumpath_abs = pyntrest_io.convert_url_path_to_local_filesystem_path(
        pyntrest_handler.main_images_path, '/')

    book = convert_to_bookchapter(local_albumpath_abs, 0)

    full_html_arr = assemble_full_html(book, full_html_arr)
    full_html = '\n'.join(full_html_arr)

    soup = BeautifulSoup(full_html, 'html.parser')
    for s in soup('hr'):
        s.extract()
    for s in soup('iframe'):
        s.extract()

    full_html = soup.prettify()

    context = {
        'page_title': book.title,
        'toc_label': 'Inhalt',
        'full_html': full_html
    }
    return context
Exemplo n.º 2
0
    def check_if_album_exists (self, request_path):
        """Converts the given request path to the related absolute file system
        path to the user's image folder and tests whether this folder
        exists."""

        local_albumpath_abs = convert_url_path_to_local_filesystem_path(
                  self.main_images_path, request_path)
        if (path.exists(local_albumpath_abs) and
            path.isdir(local_albumpath_abs)):
            return True
        else:
            return False
Exemplo n.º 3
0
 def test_convert_url_path_to_local_filesystem_path(self):
     self.assertRaises(
         TypeError, pyntrest_io.convert_url_path_to_local_filesystem_path)
     self.assertRaises(
         TypeError, pyntrest_io.convert_url_path_to_local_filesystem_path,
         None)
     self.assertEqual(
         path.join(''),
         pyntrest_io.convert_url_path_to_local_filesystem_path('', ''))
     self.assertEqual(
         path.join('test'),
         pyntrest_io.convert_url_path_to_local_filesystem_path('', 'test'))
     self.assertEqual(
         path.join('test', 'test2', 'test3'),
         pyntrest_io.convert_url_path_to_local_filesystem_path(
             '', '//test/test2//test3'))
     cwd = path.abspath(path.dirname(__file__))
     self.assertEqual(
         path.join(cwd, 'test', 'test2'),
         pyntrest_io.convert_url_path_to_local_filesystem_path(
             cwd, '//test/test2/'))
     self.assertEqual(
         path.join(cwd),
         pyntrest_io.convert_url_path_to_local_filesystem_path(cwd, ''))
     self.assertEqual(
         path.join(cwd),
         pyntrest_io.convert_url_path_to_local_filesystem_path(cwd, '//'))
Exemplo n.º 4
0
 def test_convert_url_path_to_local_filesystem_path (self):
     self.assertRaises(TypeError, pyntrest_io.convert_url_path_to_local_filesystem_path)
     self.assertRaises(TypeError, pyntrest_io.convert_url_path_to_local_filesystem_path, None)
     self.assertEqual(path.join(''), pyntrest_io.convert_url_path_to_local_filesystem_path('', ''))
     self.assertEqual(path.join('test'), pyntrest_io.convert_url_path_to_local_filesystem_path('', 'test'))
     self.assertEqual(path.join('test', 'test2', 'test3'), pyntrest_io.convert_url_path_to_local_filesystem_path('', '//test/test2//test3'))
     cwd = path.abspath(path.dirname(__file__))
     self.assertEqual(path.join(cwd, 'test', 'test2'), pyntrest_io.convert_url_path_to_local_filesystem_path(cwd, '//test/test2/'))
     self.assertEqual(path.join(cwd), pyntrest_io.convert_url_path_to_local_filesystem_path(cwd, ''))
     self.assertEqual(path.join(cwd), pyntrest_io.convert_url_path_to_local_filesystem_path(cwd, '//'))
Exemplo n.º 5
0
def generate_view_context(pyntrest_handler):
    """TODO"""

    full_html_arr = []
    local_albumpath_abs = pyntrest_io.convert_url_path_to_local_filesystem_path(
          pyntrest_handler.main_images_path, '/')

    book = convert_to_bookchapter(local_albumpath_abs, 0)


    full_html_arr = assemble_full_html(book, full_html_arr)
    full_html = '\n'.join(full_html_arr)

    soup = BeautifulSoup(full_html, 'html.parser')
    for s in soup('hr'):
        s.extract()
    for s in soup('iframe'):
        s.extract()

    full_html = soup.prettify()

    context = { 'page_title': book.title, 'toc_label': 'Inhalt',
               'full_html': full_html }
    return context
Exemplo n.º 6
0
    def generate_view_context(self, request_path):
        """The core "magic" method that reads the requested album filesystem
        path related to the virtual album path from the request and obtains all
        necessary information to create a neat web photo album"""

        local_albumpath_abs = convert_url_path_to_local_filesystem_path(
                  self.main_images_path, request_path)
        local_albumpath_rel = convert_url_path_to_local_filesystem_path(
                                                     '', request_path)
        mkdirs(path.join (self.static_fullsize_path, local_albumpath_rel))
        mkdirs(path.join (self.static_ithumbs_path, local_albumpath_rel))

        (album_title, album_description, album_cover, reversed_sorting,
         hide_cover, mods_on_top, _) = read_optional_album_metadata (
            local_albumpath_abs, pyntrest_config.META_INI_FILE_PATTERN)

        # setup sub albums
        subalbums = []
        for subalbum_name in get_immediate_subdirectories(local_albumpath_abs):
            self.process_subalbum (subalbums, subalbum_name,
            local_albumpath_rel, local_albumpath_abs)

        # sort subalbums by path
        if (mods_on_top):
            subalbums = sorted(subalbums, key=lambda subalbum:
                subalbum.last_modified, reverse=True)
        else:
            subalbums = sorted(subalbums, key=lambda subalbum:
                subalbum.path, reverse=False)

        # setup images
        images = []
        for image_name in listdir(local_albumpath_abs):
            subimage = self.process_subimage(image_name,
                                    local_albumpath_rel, local_albumpath_abs)
            if subimage is None:
                continue
            if (album_cover is None or hide_cover is False):
                images.append(subimage)
            else:
                if album_cover == image_name:
                    pass # ignore
                else:
                    images.append(subimage)

        # update image descriptions
        image_descriptions = read_optional_image_metadata(
                    local_albumpath_abs, pyntrest_config.META_INI_FILE_PATTERN)
        for image in images:
            basename = path.basename(image.location).lower()
            try:
                image_description = image_descriptions[basename]
                image.description = image_description
            except KeyError:
                pass # Ignore

        # sort images by path
        images = sorted(images, key=lambda albumimage: albumimage.location,
                        reverse=reversed_sorting)

        # setup breadcrumb
        breadcrumbs = []
        breadcrumb_paths = get_absolute_breadcrumb_filesystem_paths (
            request_path)
        local_albumpath_abs = self.main_images_path
        path_string = ''
        for breadcrumb_path in breadcrumb_paths:
            local_albumpath_abs = path.join(local_albumpath_abs,
                breadcrumb_path)
            path_string = path_string + '/' + breadcrumb_path
            path_string = sub ('[/]+' , '/', path_string)
            album_title, album_description, _, _, _, _, _= (
                read_optional_album_metadata (local_albumpath_abs,
                    pyntrest_config.META_INI_FILE_PATTERN))
            url_path = path_string
            if pyntrest_config.EXTERNAL_BASE_URL is not None:
                url_path  = pyntrest_config.EXTERNAL_BASE_URL + url_path

            web_path = WebPath(title=album_title, path=url_path)
            breadcrumbs.append(web_path)
        page_title = breadcrumbs[0].title
        breadcrumbs[0].title = pyntrest_config.WORDING_HOME

        # check for intro text
        intro_content = None
        intro_file = None
        subfiles = get_immediate_subfiles(local_albumpath_abs)
        for subfile in subfiles:
            matching = match(pyntrest_config.INTRO_MD_FILE_PATTERN,
                             subfile.lower())
            if matching != None:
                intro_file = path.join(local_albumpath_abs, subfile)

        if intro_file and path.isfile(intro_file):
            intro_content, _ = get_html_content(intro_file)

        # show header?
        show_breadcrumb = True
        first_page = len(breadcrumbs) == 1
        try:
            if first_page and pyntrest_config.SUPPRESS_BREADCRUMB_ON_HOME:
                show_breadcrumb = False
        except AttributeError:
            pass # just show it.

        context = { 'page_title': page_title,
                    'col_width': pyntrest_config.IMAGE_THUMB_WIDTH,
                    'col_height' : pyntrest_config.IMAGE_THUMB_HEIGHT,
                    'images': images,
                    'show_breadcrum': False,
                    'first_page': first_page,
                    'subalbums': subalbums,
                    'album_title' : album_title,
                    'album_description' : album_description,
                    'lang_images' : pyntrest_config.WORDING_IMAGES,
                    'lang_albums' : pyntrest_config.WORDING_ALBUM,
                    'breadcrumbs' : breadcrumbs,
                    'show_breadcrumb': show_breadcrumb,
                    'show_headings' :
                        pyntrest_config.SHOW_ALBUM_IMAGES_WORDINGS,
                   'intro_content' : intro_content}

        return context