Skip to content

Allow django_backend to take advantage of message_streams#103

Merged
nicholasserra merged 3 commits intothemartorana:masterfrom
hkhanna:backend-message-stream
Oct 15, 2021
Merged

Allow django_backend to take advantage of message_streams#103
nicholasserra merged 3 commits intothemartorana:masterfrom
hkhanna:backend-message-stream

Conversation

@hkhanna
Copy link
Copy Markdown

@hkhanna hkhanna commented Aug 16, 2021

#94 allowed the PMMail class to add a message_stream, but this functionality was not provided to the ordinary django_backend. This PR allows a developer to set the message_stream attribute on the EmailMessage instance to use a non-default message stream.

@brendanwood
Copy link
Copy Markdown

Hello, just wanted to bump this PR because we'd like to start using Postmark broadcast streams and can't until this is merged. Happy to help with testing or whatever else is needed to get this merged!

@hkhanna
Copy link
Copy Markdown
Author

hkhanna commented Oct 4, 2021

Agreed! I'd love to get this merged as well. @themartorana let me know if there is anything you need from me.

self.track_opens = getattr(settings, 'POSTMARK_TRACK_OPENS', False)

if 'message_stream' in kwargs:
self.message_stream = kwargs['message_stream']
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you also test the case where you can pass message_stream into the EmailMessage kwargs? As opposed to setting it on the instance after instantiation? I ask because these other kwargs track_opens and tag del the kwarg after

del kwargs['tag']

Thinking we probably need to do the same here as it might raise an error upstream.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I've added it. But note that I can't find any reference to these classes anywhere, including the README.

I'm guessing users can use these as a convenience if they want to pass args to the __init__() function of an EmailMultiAlternatives subclass. But the way the README suggests usage is just to set tag or message_stream as an attribute on EmailMultiAlternatives after instantiation.


if 'message_stream' in kwargs:
self.message_stream = kwargs['message_stream']
else:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above ^

Comment thread postmark/django_backend.py Outdated
else:
attachments.append(item)

message_stream = getattr(message, "message_stream", None)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed ticks and quotes. Can we change this to ticks to match the others?

@nicholasserra
Copy link
Copy Markdown
Collaborator

Thanks! Sorry for the delay.

Was this manually tested? I'll likely do the same. Think theres a unit test we can add too? Will look more in depth asap.

@hkhanna
Copy link
Copy Markdown
Author

hkhanna commented Oct 7, 2021

Thanks! Sorry for the delay.

Was this manually tested? I'll likely do the same. Think theres a unit test we can add too? Will look more in depth asap.

Yup, I manually tested it back in August and confirmed it selected the correct stream on Postmark.

@hkhanna
Copy link
Copy Markdown
Author

hkhanna commented Oct 7, 2021

Added a unit test and made the requested changes. Thanks @nicholasserra! Hope we can get this merged soon.

@nicholasserra
Copy link
Copy Markdown
Collaborator

Thank you :) I'll check this out this week.

@nicholasserra
Copy link
Copy Markdown
Collaborator

Tested LGTM thank you

I'll try to get this out in a new version ASAP

@nicholasserra nicholasserra merged commit 4bb3da1 into themartorana:master Oct 15, 2021
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

Successfully merging this pull request may close these issues.

3 participants