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

Adds support for dynamic template data in personalizations #593

Merged
merged 4 commits into from
Aug 21, 2018

Conversation

0bsearch
Copy link
Contributor

@0bsearch 0bsearch commented Aug 1, 2018

Checklist

  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the [Contribution Guide] and my PR follows them.
  • I updated my branch with the master branch.
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation about the functionality in the appropriate .md file
  • I have added in line documentation to the code I modified

Short description of what this PR does:

Adds support for dynamic templates

Fixes #591

@thinkingserious thinkingserious added the status: code review request requesting a community code review or review from Twilio label Aug 1, 2018
@codecov
Copy link

codecov bot commented Aug 1, 2018

Codecov Report

Merging #593 into master will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #593      +/-   ##
==========================================
+ Coverage   86.61%   86.65%   +0.04%     
==========================================
  Files          32       32              
  Lines         979      982       +3     
  Branches      131      132       +1     
==========================================
+ Hits          848      851       +3     
  Misses         67       67              
  Partials       64       64
Impacted Files Coverage Δ
sendgrid/helpers/mail/personalization.py 92.94% <100%> (+0.25%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1ac58c6...e1cc256. Read the comment docs.

@thinkingserious thinkingserious added type: community enhancement feature request not on Twilio's roadmap difficulty: medium fix is medium in difficulty labels Aug 4, 2018
@af4ro
Copy link
Contributor

af4ro commented Aug 9, 2018

Thank you so much for your PR @3lnc!
This is a great PR and it covers all the aspects required by the specifications.

@@ -66,6 +66,38 @@ print(response.body)
print(response.headers)
```

### With dynamic templates
Copy link
Contributor

@af4ro af4ro Aug 9, 2018

Choose a reason for hiding this comment

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

Might be missing dynamic template updates in the rest of the templates file like here and here

Copy link
Contributor

Choose a reason for hiding this comment

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

You can check out some of the changes made here in #597

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding updates for rest of file: this is left on purpose, as old template system is still in place, as well as code to support it. So, I guess we still need documentation for it.

Or I'm missing the point

@af4ro af4ro added status: duplicate duplicate issue and removed status: code review request requesting a community code review or review from Twilio labels Aug 13, 2018
@thinkingserious thinkingserious added status: work in progress Twilio or the community is in the process of implementing and removed status: duplicate duplicate issue labels Aug 16, 2018
@thinkingserious thinkingserious merged commit e1cc256 into sendgrid:master Aug 21, 2018
thinkingserious added a commit that referenced this pull request Aug 21, 2018
@thinkingserious
Copy link
Contributor

Hello @3lnc,

Thanks again for the PR!

We appreciate your contribution and look forward to continued collaboration. Thanks!

Team SendGrid DX

@0bsearch 0bsearch deleted the dynamic_template_support branch August 21, 2018 07:47
@@ -1,6 +1,10 @@
class Personalization(object):
"""A Personalization defines who should receive an individual message and
how that message should be handled.

:var dynamic_template_data: data for dynamic transactional template.
Should be JSON-serializeable structure. No pre-processing sill be done

Choose a reason for hiding this comment

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

Typo: sillwill

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! Fixed :)

@djw27
Copy link

djw27 commented Aug 29, 2018

Should this not also remove the use of Substitution from mail_example.py since this has been deprecated?

I also think this is a different type of interface to existing personalizations etc so could be confusing to newcomers as to why dynamic_template_data is added differently, i.e. setting the attribute directly on the personalization rather than using a setter like all other attributes?

Just my thoughts...

@0bsearch
Copy link
Contributor Author

@djw27 by the time this PR was opened I had no info on deprecation of substitution. Could you please provide reference for this info?

Regarding descriptors interface ­— personally, I really dislike the current state of codebase being overcrowded with getters. This is really not pythonic way, as there's no setters with custom logic. Hiding attributes with _name + @property is actually gives nothing but pain — in case you need to modify helper objects dynamically. But that's IMO only.

Regarding "raw" implementation of dynamic_template_data — this is conscious decision. Dynamic templates requires json. Which is pretty "technical". I mean, if json is needed for handlebars, you probably know what json is and how to map json into python datastructures. All the validation we can do on python side is done while serializing.

Making this interface via setters will require class(es) with recurrent references — all this just to make nested structure. Taking into account that data classes is almost wrappers around dictionaries — I'm pretty sure that raw implementation is better way.

@thinkingserious
Copy link
Contributor

Thanks for the feedback @djw27 and @3lnc!

I'm currently working on an update to this SDK where your feedback would be greatly helpful. If you have time, please take a look.

With Best Regards,

Elmer

@djw27
Copy link

djw27 commented Aug 30, 2018

@3lnc I 100% agree with your points! I don't blame you not knowing that substitutions are being deprecated, I stumbled across the documentation by chance for dynamic templates: https://dynamic-templates.api-docs.io/3.0/mail-send-with-dynamic-transactional-templates/v3-mail-send

I guess it's a wider question for @thinkingserious, but at stage it would be pretty difficult to completely overhaul the interface used for this library. I'll take a look at your link in the mean time!

@thinkingserious
Copy link
Contributor

Hello @djw27,

I'm looking forward to your feedback on the SDK update. Thanks!

With Best Regards,

Elmer

@Corey-Evans
Copy link

@thinkingserious Are substitutions still being deprecated? I remember reading this a few months back. However, now I can't find any reference to this (including on the link referenced above).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: medium fix is medium in difficulty status: work in progress Twilio or the community is in the process of implementing type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Dynamic Template Support
6 participants