Skip to content

Attachment

Bases: Attachment_

Source code in src/plankapy/interfaces.py
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
class Attachment(Attachment_):

    @property
    def creator(self) -> User:
        """User that created the attachment"""
        user_route = self.routes.get_user(id=self.creatorUserId)
        return User(**user_route()['item']).bind(self.routes)

    @property
    def card(self) -> Card:
        """Card the attachment belongs to"""
        card_route = self.routes.get_card(id=self.cardId)
        return Card(**card_route()['item']).bind(self.routes)

    def refresh(self):
        """Refreshes the attachment data"""
        for attachment in self.card.attachments:
            if attachment.id == self.id:
                self.__init__(**attachment)

    def data(self) -> bytes:
        """Attachment data as bytes

        Returns:
            Attachment data
        """
        return self.routes.handler._get_file(self.url)

    def download(self, path: Path) -> None:
        """Downloads the attachment to a file

        Args:
            path (Path): Path to the file to save the attachment to
        """
        with open(path, 'wb') as file:
            file.write(self.data())

    def update(self) -> Attachment:
        """Updates the attachment with new values"""
        route = self.routes.patch_attachment(id=self.id)
        self.__init__(**route(**self)['item'])
        return self

    def delete(self) -> Attachment:
        """Deletes the attachment

        Danger:
            This action is irreversible and cannot be undone

        Returns:
            Attachment: Deleted attachment instance
        """
        self.refresh()
        route = self.routes.delete_attachment(id=self.id)
        route()
        return self

card property

Card the attachment belongs to

creator property

User that created the attachment

data()

Attachment data as bytes

Returns:

Type Description
bytes

Attachment data

Source code in src/plankapy/interfaces.py
1745
1746
1747
1748
1749
1750
1751
def data(self) -> bytes:
    """Attachment data as bytes

    Returns:
        Attachment data
    """
    return self.routes.handler._get_file(self.url)

delete()

Deletes the attachment

Danger

This action is irreversible and cannot be undone

Returns:

Name Type Description
Attachment Attachment

Deleted attachment instance

Source code in src/plankapy/interfaces.py
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
def delete(self) -> Attachment:
    """Deletes the attachment

    Danger:
        This action is irreversible and cannot be undone

    Returns:
        Attachment: Deleted attachment instance
    """
    self.refresh()
    route = self.routes.delete_attachment(id=self.id)
    route()
    return self

download(path)

Downloads the attachment to a file

Parameters:

Name Type Description Default
path Path

Path to the file to save the attachment to

required
Source code in src/plankapy/interfaces.py
1753
1754
1755
1756
1757
1758
1759
1760
def download(self, path: Path) -> None:
    """Downloads the attachment to a file

    Args:
        path (Path): Path to the file to save the attachment to
    """
    with open(path, 'wb') as file:
        file.write(self.data())

refresh()

Refreshes the attachment data

Source code in src/plankapy/interfaces.py
1739
1740
1741
1742
1743
def refresh(self):
    """Refreshes the attachment data"""
    for attachment in self.card.attachments:
        if attachment.id == self.id:
            self.__init__(**attachment)

update()

Updates the attachment with new values

Source code in src/plankapy/interfaces.py
1762
1763
1764
1765
1766
def update(self) -> Attachment:
    """Updates the attachment with new values"""
    route = self.routes.patch_attachment(id=self.id)
    self.__init__(**route(**self)['item'])
    return self