trilium_alchemy.core.note.attributes
#
Class index#
Canonical
Interface to a note’s owned and inherited attributes. |
|
Interface to a note’s owned attributes. Implements same
interface as |
|
Interface to a note’s inherited attributes. Implements same
interface as |
Symbols#
- class trilium_alchemy.core.note.attributes.Attributes(note)#
Bases:
trilium_alchemy.core.note.extension.NoteExtension
trilium_alchemy.core.note.attributes.NameMap
collections.abc.MutableSequence
Interface to a note’s owned and inherited attributes.
Access as
Note.attributes
, a descriptor mapping to an instance of this class.Access as a list:
# add some attributes note.attributes.append(Label("myLabel")) note.attributes.append(Relation("myRelation", session.root)) for attr in note.attributes: print(f"Attribute: {attr}")
Attribute: Label(#myLabel, value=, attribute_id=None, note=Note(title=new note, note_id=None), position=10) Attribute: Relation(~myRelation, target=Note(title=root, note_id=root), attribute_id=None, note=Note(title=new note, note_id=None), position=20)
Index by attribute name, getting a list of attributes with that name:
# add a label note += Label("myLabel") print(note.attributes["myLabel"][0])
Label(#myLabel, value=, attribute_id=None, note=Note(title=new note, note_id=None), position=10)
Use
in
to check if an attribute exists by name:assert "myLabel" in note.attributes
When an attribute is deleted from the list, it’s automatically marked for delete:
# add a label label = Label("myLabel") note += label # delete from list del note.attributes[0] print(f"label.state: {label.state}")
label.state: State.DELETE
Assign a new list, deleting any existing attributes not in the list:
# add a label label1 = Label("myLabel1") note += label1 # assign a new list of attributes label2 = Label("myLabel2") note.attributes = [label2] print(f"label1.state: {label1.state}") print(f"label2.state: {label2.state}")
label1.state: State.DELETE label2.state: State.CREATE
This object is stateless;
Note.attributes.owned
andNote.attributes.inherited
are the sources of truth for owned and inherited attributes respectively.Todo
Add
Attributes.labels
,Attributes.relations
with same interface asAttributes
, filtered by attribute type- owned: OwnedAttributes#
-
Same interface as
Note.attributes
but filtered by owned attributes.
- inherited: InheritedAttributes#
-
Same interface as
Note.attributes
but filtered by inherited attributes.
- append(value)#
Inherited from:
collections.abc.MutableSequence
S.append(value) – append value to the end of the sequence
- clear()#
Inherited from:
collections.abc.MutableSequence
S.clear() -> None – remove all items from S
- reverse()#
Inherited from:
collections.abc.MutableSequence
S.reverse() – reverse IN PLACE
- extend(values)#
Inherited from:
collections.abc.MutableSequence
S.extend(iterable) – extend sequence by appending elements from the iterable
- pop(index=-1)#
Inherited from:
collections.abc.MutableSequence
S.pop([index]) -> item – remove and return item at index (default last). Raise IndexError if list is empty or index is out of range.
- remove(value)#
Inherited from:
collections.abc.MutableSequence
S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.
- index(value, start=0, stop=None)#
Inherited from:
collections.abc.Sequence
S.index(value, [start, [stop]]) -> integer – return first index of value. Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- count(value)#
Inherited from:
collections.abc.Sequence
S.count(value) -> integer – return number of occurrences of value
- class trilium_alchemy.core.note.attributes.OwnedAttributes(entity: Entity)#
Bases:
trilium_alchemy.core.note.attributes.NameMap
trilium_alchemy.core.note.extension.List
Interface to a note’s owned attributes. Implements same interface as
Attributes
but accessed asNote.attributes.owned
.- insert(i: int, value: Any)#
Inherited from:
trilium_alchemy.core.note.extension.List
S.insert(index, value) – insert value before index
- append(value)#
Inherited from:
collections.abc.MutableSequence
S.append(value) – append value to the end of the sequence
- clear()#
Inherited from:
collections.abc.MutableSequence
S.clear() -> None – remove all items from S
- reverse()#
Inherited from:
collections.abc.MutableSequence
S.reverse() – reverse IN PLACE
- extend(values)#
Inherited from:
collections.abc.MutableSequence
S.extend(iterable) – extend sequence by appending elements from the iterable
- pop(index=-1)#
Inherited from:
collections.abc.MutableSequence
S.pop([index]) -> item – remove and return item at index (default last). Raise IndexError if list is empty or index is out of range.
- remove(value)#
Inherited from:
collections.abc.MutableSequence
S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.
- index(value, start=0, stop=None)#
Inherited from:
collections.abc.Sequence
S.index(value, [start, [stop]]) -> integer – return first index of value. Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- count(value)#
Inherited from:
collections.abc.Sequence
S.count(value) -> integer – return number of occurrences of value
- class trilium_alchemy.core.note.attributes.InheritedAttributes(entity: Entity)#
Bases:
trilium_alchemy.core.note.extension.NoteStatefulExtension
trilium_alchemy.core.note.attributes.NameMap
collections.abc.Sequence
Interface to a note’s inherited attributes. Implements same interface as
Attributes
but accessed asNote.attributes.inherited
.Raises
ReadOnlyError
upon attempt to modify.- index(value, start=0, stop=None)#
Inherited from:
collections.abc.Sequence
S.index(value, [start, [stop]]) -> integer – return first index of value. Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- count(value)#
Inherited from:
collections.abc.Sequence
S.count(value) -> integer – return number of occurrences of value