WhakerKit 2.0

https://sourceforge.net/projects/whakerkit/

Module whakerkit.nodes

Class WhakerKitDocumentCardNode

Description

Node to represents details of a document into a card.

Constructor

Create the card node.

Parameters
  • parent: (str) The parent node identifier
  • doc: (ImmutableDocument) The document to show details
  • docfilepath: (str) The file path of the document
View Source
def __init__(self, parent, doc: ImmutableDocument=None, doc_file_path: str='#'):
    """Create the card node.

    :param parent: (str) The parent node identifier
    :param doc: (ImmutableDocument) The document to show details
    :param doc_file_path: (str) The file path of the document

    """
    author = doc.author.replace(whakerkit.sg.FIELDS_NAME_SEPARATOR, ' ')
    icon_path = self.get_icon_path(doc.filetype)
    attributes = WhakerKitDocsManager.data_attributes(doc)
    super(WhakerKitDocumentCardNode, self).__init__(parent, doc.folder_name, 'article', attributes=attributes)
    self.add_attribute('id', doc.folder_name)
    self.add_attribute('class', 'card')
    header_card = HTMLNode(self.identifier, 'header_card', 'header')
    img_card = HTMLNode(header_card.identifier, None, 'img', attributes={'src': icon_path, 'alt': 'file extension'})
    header_card.append_child(img_card)
    self.append_child(header_card)
    main_card = HTMLNode(self.identifier, 'main_card', 'main')
    WhakerKitDocumentCardNode.__add_info(main_card, ' '.join(['<i>', get_msg(MSG_NAME), '</i><b>', doc.filename, '</b>']))
    WhakerKitDocumentCardNode.__add_info(main_card, '<i>' + get_msg(MSG_WHO) + '</i>' + author)
    WhakerKitDocumentCardNode.__add_info(main_card, '<i>' + get_msg(MSG_DATE) + '</i>' + doc.date.strftime('%Y-%m-%d'))
    WhakerKitDocumentCardNode.__add_info(main_card, '<i>' + get_msg(MSG_TYPE) + '</i>' + doc.filetype)
    if len(doc.description) > 0:
        WhakerKitDocumentCardNode.__add_info(main_card, doc.description)
    self.append_child(main_card)
    footer_card = HTMLNode(self.identifier, 'footer_card', 'footer')
    btn = WhakerKitDownloadNode(footer_card.identifier, href=doc_file_path, folder_name=doc.folder_name, text=get_msg(MSG_DOWNLOAD).format(nb=doc.downloads))
    btn.add_attribute('class', 'btn_download')
    footer_card.append_child(btn)
    self.append_child(footer_card)

Public functions

get_icon_path

Get the image extension for the file.

Parameters
  • extension: (str) The extension of the file without the dot
Returns
  • (str) The icon path
View Source
@staticmethod
def get_icon_path(extension: str) -> str:
    """Get the image extension for the file.

        :param extension: (str) The extension of the file without the dot
        :return: (str) The icon path

        """
    extension = extension.lower()
    if extension in WhakerKitDocumentCardNode.FILE_ICONS:
        return WhakerKitDocumentCardNode.FILE_ICONS[extension]
    if extension in WhakerKitDocumentCardNode.EXTENSIONS['image']:
        return WhakerKitDocumentCardNode.FILE_ICONS['image']
    if extension in WhakerKitDocumentCardNode.EXTENSIONS['code']:
        return WhakerKitDocumentCardNode.FILE_ICONS['code']
    return WhakerKitDocumentCardNode.FILE_ICONS['default']

Protected functions

__add_info

Add a paragraph to the card.

Parameters
  • parent
  • value
View Source
@staticmethod
def __add_info(parent: HTMLNode, value=''):
    """Add a paragraph to the card."""
    p = HTMLNode(parent.identifier, None, 'span', value=value)
    parent.append_child(p)