Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachment model missing __init__ #24

Open
Sorthos opened this issue Oct 24, 2019 · 2 comments
Open

Attachment model missing __init__ #24

Sorthos opened this issue Oct 24, 2019 · 2 comments

Comments

@Sorthos
Copy link

Sorthos commented Oct 24, 2019

I was trying to programmatically build templates with attachments and found that I couldn't do it due to an error in the models.py file. I modified it on my own end and it works perfectly now. I will submit a pull request with the update.

@bridge-four
Copy link

FYI -- this is still an issue. Just need to add this to the
Attachment class in models.py

def __init__(self, **kwargs):
        for key, default in Page._valid_properties.items():
            setattr(self, key, kwargs.get(key, default))

@makim0n
Copy link

makim0n commented Jun 20, 2022

I think there is a littel typo on the message above. Here is the complete Attachment class :

class Attachment(Model):
    _valid_properties = {'content': None, 'type': None, 'name': None}

    def __init__(self, **kwargs):
            for key, default in Attachment._valid_properties.items():
                setattr(self, key, kwargs.get(key, default))

    @classmethod
    def parse(cls, json):
        attachment = cls()
        for key, val in json.items():
            if key in cls._valid_properties:
                setattr(attachment, key, val)
        return attachment

and here is a working example to put attachment using the python api :

        with open("attachment.png", 'rb') as bin_blob:
            b64_attachment_content = base64.b64encode(bin_blob.read())

        attachment_mimetype = mimetypes.guess_type(attachment.png)[0]

        template = Template(name="test",
            html="<h1> hello world </h1>",
            subject="click click bang bang",
            attachments=[Attachment.parse({"name":"attachment.png", "type":attachment_mimetype, "content":b64_attachment_content.decode()})])

        template = api.templates.post(template)

EuanKerr added a commit to EuanKerr/api-client-python that referenced this issue Oct 4, 2022
EuanKerr added a commit to EuanKerr/api-client-python that referenced this issue Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants