Open Sorthos opened 4 years ago
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))
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)
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.