Table layout component for displaying media files as rows.
Column Headers
Table header rendering based on configured columns.
render_list_header
def render_list_header( config:GalleryConfig, # Gallery configuration show_selection:bool=False, # Show selection checkbox column)->functools.partial(<function ft_hx at 0x7f6e136ab240>, 'thead'): # Table header
Render the table header row.
from fasthtml.common import to_xml# Test list headerconfig = GalleryConfig()header = render_list_header(config)html = to_xml(header)assert"<thead"in htmlassert"Name"in htmlassert"Type"in htmlassert"Size"in htmlassert"Modified"in html# Test with selection columnheader = render_list_header(config, show_selection=True)html = to_xml(header)# Check for selection column (empty header) and all 4 data columnsassert'class="w-10"'in html # Selection column with widthassert"Name"in htmlassert"Type"in htmlassert"Size"in htmlassert"Modified"in htmlprint("render_list_header tests passed!")
render_list_header tests passed!
List Row
Individual row component for a media file.
render_list_row
def render_list_row( file_info:FileInfo, # File to render config:GalleryConfig, # Gallery configuration index:int, # Index in the list is_selected:bool=False, # Whether file is selected preview_url:Optional=None, # URL for preview action select_url:Optional=None, # URL for selection action hx_target:Optional=None, # HTMX target for swaps)->functools.partial(<function ft_hx at 0x7f6e136ab240>, 'tr'): # Table row
Render a media file as a table row.
# Test list rowconfig = GalleryConfig()file_info = FileInfo( name="song.mp3", path="/music/song.mp3", is_directory=False, file_type=FileType.AUDIO, extension="mp3", size=5000000)row = render_list_row( file_info=file_info, config=config, index=0, preview_url="/preview")html = to_xml(row)assert"<tr"in htmlassert"song.mp3"in htmlassert"media-gallery-row-0"in htmlassert"Audio"in html # Type columnassert"hx-post"in html# Test with selectionselect_config = GalleryConfig(selection_mode=SelectionMode.SINGLE)row = render_list_row( file_info=file_info, config=select_config, index=1, is_selected=True, select_url="/select")html = to_xml(row)assert"checkbox"in htmlassert"checked"in htmlprint("render_list_row tests passed!")
render_list_row tests passed!
List View
Complete list view with table structure.
render_list_view
def render_list_view( files:List, # Files to display config:GalleryConfig, # Gallery configuration selected_paths:Optional=None, # Currently selected paths preview_url:Optional=None, # URL for preview action select_url:Optional=None, # URL for selection action hx_target:Optional=None, # HTMX target for swaps start_index:int=0, # Starting index for IDs (for pagination))->Any: # List view component