Skip to main content

Table of Contents

Introduction​

Class TocEntry​

TocEntry(...)​

Create a TocEntry

Parameters:string_id (str)
The string-Id of the placeholder-link(s) belonging to this entry.
page (comet.CPage)
The page on which this placeholder-link(s) / entry is located.
key_values (dict)
Any key-values that should be stored for this entry.
links (list)
The placeholder-links (comet.CLink) associated to this entry.
Returns:The object's instance.
Return Type:TocEntry

get_attribute_value(...)​

(key)​

Retrieve a value from the entry's key-values.

Parameters:key (str)
The key of the value you want to retrieve.
Returns:The value at the specified key.
Return Type:str

Class TableOfContents​

TableOfContents(...)​

(entity_definition, page_range = None, placeholder_range = None, ids_sort_order = None)​

Create a table of contents-object by specifying a pagerange in which product-templates are located and placeholders from these templates, that are used as "identifier" for TOC-entries. These are found and used to initialize TocEntry-instaces. A TocEntry's key-values can be retrieved from its corresponding DataProvider to use in the Table of contents. Entries can be sorted based on a sequence of record-ids.
Automatically finds the records based on the given parameters upon initialization.

Parameters:entity_definition (dict)
A dictionary with dataquerying-information to be used by the data-provider-library for retrieving product-attributes to be used when inserting content in the TOC.
Expects these key-values:
type (str): The item-node type of the searched records from the XML-file.
base_attributes (list[str]): Attribute-keys of to be loaded from the entity's base-node.
attributes (list[str]): Attribute-keys of to be loaded from the entity's attribute-nodes.
page_range (list[comet.CPage])
A list of comet-page-instances of the document. The pages should be the ones, on which the "breadcrumb"-placeholders are used, that should be found and used to get the pagenumbers from (product-pages).
placeholder_range (list[int])
A list of placeholder-ids that will be searched in the document to get the page-occurences of records (For example breadcrumb-placeholder).
ids_sort_order (list[str])
Optionally specify a sequence of record-ids, that should be used when sorting TOC-entries.
Returns:The object's instance.
Return Type:TableOfContents

find_toc_entries()​

Finds placeholders in the document with the filters specified at object-initialization and creates TocEntry-objects from them.

Returns:A list of TocEntries of the found links.
Return Type:list[TocEntry]

get_entry(...)​

(id)​

Retrieve a TocEntry from the object by a given String-ID.

Parameters:id (str)
Returns:The TocEntry with the given String-ID.
Return Type:TocEntry

replace_pagenumbers(...)​

Find placeholders of a given Id in a given page range (usually a Toc-placeholder on Toc-pages) and replace the content of their textmodel with the pagenumbers of TocEntries associated to the palceholder's Ids. Optionally apply a hyperlink to the placeholder's object.

Parameters:placeholder_id (int)
A placeholder-Id (usually used in a Toc-template) that is used to find matching TocEntries and textmodels where the content is replaced by the entries' pagenumbers.
page_range (list)
The pages on which the placeholders are being used in templates (usually Toc-pages that are already built).
hyperlink_type (type)
Should a hyperlink be created in the text of the found frames (comet.CTextModel) or on the frame itself (comet.CPageItem or comet.CFrame)?
Returns:A list of tuples containing the placeholder-link- and hyperlink-objects
Return Type:_list[tuple[comet.CLink, comet.CHyperlink

Find placeholders of a given Id in a given page range (usually a Toc-placeholder on Toc-pages) and apply hyperlinks on the placeholders' objects to the associated TocEntries' pages.

Parameters:placeholder_id (int)
page_range (list)
hyperlink_type (type)
Returns:
Return Type:_list[comet.CHyperlink]

(source, target_page, name="")​

Create a hyperlink on an element of the document (source) to a page of the document.

Parameters:source (CFrame | tuple[CFrame, int, int])
The frame or range in a textframe on which the hyperlink is applied.
target_page (comet.CPage)
The page to which the hyperlink leads.
name (str)
The name of the hyperlink.
Returns:The created hyperlink or None.
Return Type:_comet.CHyperlink

Other functions​

evaluate_toc_entry_funcvars(...)​

(link, entry)​

Iterate over a link's function-variables and retrieve key-values.
If a function-variable-key begins with "tocText", the remaining string after that "prefix" is used as key and the function-variable's value is used as value.
If a function-variable-key begins with "tocKey", the remaining string after that "prefix" is used as key and the function-variable's value is used to retrieve a value from the given TocEntry.

Parameters:link (comet.CLink)
The placeholder-link from which the function-variable-values should be extracted.
entry (TocEntry)
The TocEntry from which key-values should be retrieved.
Returns:A dictionary with keys and values. The keys are derived from keys of function-variables.
Return Type:dict