trilium_alchemy.core.declarative.decorators
¶
Decorators to add attributes and children declaratively.
Function index¶
Canonical
Adds a |
|
Adds a |
|
Adds a |
|
Adds a |
|
Add |
|
Instantiate provided class and add as child, creating a
|
Symbols¶
- trilium_alchemy.core.declarative.decorators.label(name: str, value: str = '', inheritable: bool = False, accumulate: bool = False)¶
Aliases:
trilium_alchemy.label
trilium_alchemy.core.label
trilium_alchemy.core.declarative.label
Adds a
Label
to aBaseDeclarativeNote
orBaseDeclarativeMixin
subclass.Example:
@label("sorted") class MyNote(BaseDeclarativeNote): pass
- Parameters:
- name: str
Label name
- value: str = ''
Label value, or empty string
- inheritable: bool = False
Whether label should be inherited to children
- accumulate: bool = False
Whether label should be added if an attribute with this name already exists from a subclassed
BaseDeclarativeNote
orBaseDeclarativeMixin
- trilium_alchemy.core.declarative.decorators.relation(name: str, target_cls: type[BaseDeclarativeNote], inheritable: bool = False, accumulate: bool = False)¶
Aliases:
trilium_alchemy.relation
trilium_alchemy.core.relation
trilium_alchemy.core.declarative.relation
Adds a
Relation
to aBaseDeclarativeNote
orBaseDeclarativeMixin
subclass.Example:
# define a task template @label("task") class Task(BaseTemplateNote): icon = "bx bx-task" # define a note with ~template=Task @relation("template", Task) class TaskNote(BaseDeclarativeNote): pass # create a task task = TaskNote() assert task["template"] is Task() assert task["template"]["iconClass"] == "bx bx-task"
- Parameters:
- name: str
Relation name
- target_cls: type[BaseDeclarativeNote]
Class of relation target, will be instantiated when this note is instantiated (so it must have
BaseDeclarativeNote.singleton
,BaseDeclarativeNote.note_id_
, orBaseDeclarativeNote.note_id_seed
set)- inheritable: bool = False
Whether relation should be inherited to children
- accumulate: bool = False
Whether relation should be added if an attribute with this name already exists from a subclassed
BaseDeclarativeNote
orBaseDeclarativeMixin
- trilium_alchemy.core.declarative.decorators.label_def(name: str, promoted: bool = True, multi: bool = False, value_type: Literal[text, number, boolean, date, datetime, url] = 'text', inheritable: bool = False, accumulate: bool = False)¶
Aliases:
trilium_alchemy.label_def
trilium_alchemy.core.label_def
trilium_alchemy.core.declarative.label_def
Adds a
Label
definition (promoted label) to aBaseDeclarativeNote
orBaseDeclarativeMixin
subclass.Example:
@label("task") @label_def("priority", value_type="number") class Task(Template): icon = "bx bx-task"
- Parameters:
- name: str
Label name
- promoted: bool = True
Show in UI
- multi: bool = False
Allow multiple labels with this name in UI
- value_type: Literal[text, number, boolean, date, datetime, url] = 'text'
Type of label value
- inheritable: bool = False
Whether label should be inherited to children
- accumulate: bool = False
Whether label should be added if an attribute with this name already exists from a subclassed
BaseDeclarativeNote
orBaseDeclarativeMixin
- trilium_alchemy.core.declarative.decorators.relation_def(name: str, promoted: bool = True, multi: bool = False, inverse: str | None = None, inheritable: bool = False, accumulate: bool = False)¶
Aliases:
trilium_alchemy.relation_def
trilium_alchemy.core.relation_def
trilium_alchemy.core.declarative.relation_def
Adds a
Relation
definition (promoted relation) to aBaseDeclarativeNote
orBaseDeclarativeMixin
subclass.Example:
@label("task") @label_def("priority", value_type="number") @relation_def("project", inheritable=True) class Task(Template): icon = "bx bx-task"
- Parameters:
- name: str
Relation name
- promoted: bool = True
Show in UI
- multi: bool = False
Allow multiple relations with this name in UI
- inverse: str | None = None
Inverse relation, e.g. if
name = "isParentOf"
this could be"isChildOf"
- inheritable: bool = False
Whether relation should be inherited to children
- accumulate: bool = False
Whether relation should be added if an attribute with this name already exists from a subclassed
BaseDeclarativeNote
orBaseDeclarativeMixin
- trilium_alchemy.core.declarative.decorators.children(*children: type[BaseDeclarativeNote] | tuple[type[BaseDeclarativeNote], str])¶
Aliases:
trilium_alchemy.children
trilium_alchemy.core.children
trilium_alchemy.core.declarative.children
Add
BaseDeclarativeNote
subclasses as children, implicitly creating aBranch
. May use a tuple of(child_cls, prefix)
to additionally set branch prefix.Example:
class Child1(BaseDeclarativeNote): pass class Child2(BaseDeclarativeNote): pass @children( Child1, (Child2, "My prefix"), ) class Parent(BaseDeclarativeNote): pass
- Parameters:
- children
Classes to add as children
- trilium_alchemy.core.declarative.decorators.child(child: type[Note], prefix: str = '', expanded: bool | None = None)¶
Aliases:
trilium_alchemy.child
trilium_alchemy.core.child
trilium_alchemy.core.declarative.child
Instantiate provided class and add as child, creating a
Branch
and setting provided kwargs.Example:
class Child(BaseDeclarativeNote): pass @child(Child, prefix="My prefix") class Parent(BaseDeclarativeNote): pass