FileNode Utility functions¶
-
media_tree.utils.filenode.
get_file_link
(node, use_metadata=False, include_size=False, include_extension=False, include_icon=False, href=None, extra_class='', extra='')¶ Returns a formatted HTML link tag to the FileNode’s file, optionally including some meta information about the file.
-
media_tree.utils.filenode.
get_merged_filenode_list
(nodes, filter_media_types=None, exclude_media_types=None, filter=None, ordering=None, processors=None, max_depth=None, max_nodes=None)¶ Almost the same as
get_nested_filenode_list()
, but returns a flat (one-dimensional) list. Using the same QuerySet as in the example for get_nested_filenode_list, this method would return:[ <FileNode: Empty folder>, <FileNode: Photo folder>, <FileNode: photo1.jpg>, <FileNode: photo2.jpg>, <FileNode: photo3.jpg>, <FileNode: file.txt> ]
-
media_tree.utils.filenode.
get_nested_filenode_list
(nodes, filter_media_types=None, exclude_media_types=None, filter=None, ordering=None, processors=None, max_depth=None, max_nodes=None)¶ Returns a nested list of nodes, applying optional filters and processors to each node. Nested means that the resulting list will be multi-dimensional, i.e. each item in the list that is a folder containing child nodes will be followed by a sub-list containing those child nodes.
Example of returned list:
[ <FileNode: Empty folder>, <FileNode: Photo folder>, [<FileNode: photo1.jpg>, <FileNode: photo2.jpg>, <FileNode: another subfolder>], [<FileNode: photo3.jpg>] <FileNode: file.txt> ]
You can use this list in conjunction with Django’s built-in list template filters to output nested lists in templates:
{{ some_nested_list|unordered_list }}
Using the FileNode structure from the example, the above line would result in the following output:
<ul> <li>Empty folder</li> <li>Photo folder <ul> <li>photo1.jpg</li> <li>photo2.jpg</li> <li>another subfolder <ul> <li>photo3.jpg</li> </ul> </li> </ul> </li> <li>file.txt</li> </ul>
Parameters: - nodes – A QuerySet or list of FileNode objects
- filter_media_types – A list of media types to include in the resulting list, e.g.
media_types.DOCUMENT
- exclude_media_types – A list of media types to exclude from the resulting list
- filter – A dictionary of kwargs to be applied with
QuerySet.filter()
ifnodes
is a QuerySet - processors – A list of callables to be applied to each node, e.g.
force_unicode
if you want the list to contain strings instead of FileNode objects - max_depth – Can be used to limit the recursion depth (unlimited by default)
- max_nodes – Can be used to limit the number of items in the resulting list (unlimited by default)