Skip to content

Attachment

CLASS DESCRIPTION
Attachment

Python interface for Planka Attachments

Attachment

Attachment(schema: Schema, session: Planka)

Bases: PlankaModel[Attachment]

Python interface for Planka Attachments

METHOD DESCRIPTION
copy

Create a deepcopy of the model and its associated schema.

delete

Delete the Attachment

diff

Get a schema diff between two model schemas.

download

Get a byte Iterator for stream downloading

sync

Pull the latest state of the Attachment from the Planka Server

update

Update the Attachment with the provided values

ATTRIBUTE DESCRIPTION
__formatter__

Formatter func that allows overriding str behavior for models

TYPE: ModelFormatter[Self]

card

The Card the Attachment belongs to

TYPE: Card

created_at

When the Attachment was created

TYPE: datetime

creator

The User created the Attachment (Raises LookupError if User is not found in Board)

TYPE: User

data

The specific data associated with the action (type dependant)

TYPE: dict[str, Any]

name

The name of the Attachment

TYPE: str

type

The type of the action

updated_at

When the Attachment was last updated

TYPE: datetime

Source code in src/plankapy/v2/models/_base.py
30
31
32
33
34
35
36
def __init__(self, schema: Schema, session: Planka) -> None:
    self._schema = schema
    self.session = session
    self.endpoints = session.endpoints
    self.client = session.client
    self.current_role = session.current_role
    self.current_id = session.current_id

__formatter__ class-attribute instance-attribute

__formatter__: ModelFormatter[Self] = DEFAULT_FORMATTER

Formatter func that allows overriding str behavior for models

card property

card: Card

The Card the Attachment belongs to

created_at property

created_at: datetime

When the Attachment was created

creator property

creator: User

The User created the Attachment (Raises LookupError if User is not found in Board)

data property

data: dict[str, Any]

The specific data associated with the action (type dependant)

name property writable

name: str

The name of the Attachment

type property

type

The type of the action

updated_at property

updated_at: datetime

When the Attachment was last updated

copy

copy() -> Self

Create a deepcopy of the model and its associated schema.

Note

Since the endpoints for both instances of the Model are the same, any calls to update will restore the state and bring both copies into sync. copies like this are meant more for comparing changes when running a sync or update/assignemnt operation.

Example:

    >>> card_copy = card.copy()
    >>> card.name = 'Updated Name'
    >>> card_copy.name
    'Original Name'
    >>> card.name
    'Updated Name'
    >>> # This update may have had side effects
    >>> print(card_copy.diff(card))
    {'name': ('Original Name', 'Updated Name'), 'updatedAt': ('...2:00pm', '...2:45pm'), ...}

Source code in src/plankapy/v2/models/_base.py
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def copy(self) -> Self:
    """Create a deepcopy of the model and its associated schema.

    Note:
        Since the endpoints for both instances of the Model are the same, any 
        calls to update will restore the state and bring both copies into sync. 
        copies like this are meant more for comparing changes when running a sync 
        or update/assignemnt operation.

    Example:
    ```python
        >>> card_copy = card.copy()
        >>> card.name = 'Updated Name'
        >>> card_copy.name
        'Original Name'
        >>> card.name
        'Updated Name'
        >>> # This update may have had side effects
        >>> print(card_copy.diff(card))
        {'name': ('Original Name', 'Updated Name'), 'updatedAt': ('...2:00pm', '...2:45pm'), ...}
    ```
    """
    return copy.deepcopy(self)

delete

delete()

Delete the Attachment

Source code in src/plankapy/v2/models/attachment.py
78
79
80
def delete(self):
    """Delete the Attachment"""
    return self.endpoints.deleteAttachment(self.id)

diff

diff(other: PlankaModel[Schema]) -> Diff

Get a schema diff between two model schemas.

Note

Only matching keys are diffed. Any schema keys that are not in the source schema will not be checked in the target schema

Source code in src/plankapy/v2/models/_base.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
def diff(self, other: PlankaModel[Schema]) -> Diff:
    """Get a schema diff between two model schemas.

    Note:
        Only matching keys are diffed. Any schema keys that are not in the source schema 
        will not be checked in the target schema
    """
    return {
        k: (source, delta) 
        for k, source in self.schema
        if k in other.schema
        and (delta := other.schema[k]) 
        and delta != source
    }

download

download() -> Iterator[bytes]

Get a byte Iterator for stream downloading

Source code in src/plankapy/v2/models/attachment.py
82
83
84
def download(self) -> Iterator[bytes]:
    """Get a byte Iterator for stream downloading"""
    return self.client.get(self.schema['data']['url']).iter_bytes()

sync

sync() -> None

Pull the latest state of the Attachment from the Planka Server

Source code in src/plankapy/v2/models/attachment.py
67
68
69
70
71
72
def sync(self) -> None:
    """Pull the latest state of the Attachment from the Planka Server"""
    # No endpoint for attachments, need to get it through the associated Card
    _new = [a for a in self.card.attachments if a.id == self.id]
    if not _new:
        self.schema = _new.pop().schema

update

update(**kwargs: Unpack[Request_updateAttachment]) -> None

Update the Attachment with the provided values

Source code in src/plankapy/v2/models/attachment.py
74
75
76
def update(self, **kwargs: Unpack[paths.Request_updateAttachment]) -> None:
    """Update the Attachment with the provided values"""
    self.schema = self.endpoints.updateAttachment(self.id, **kwargs)['item']