Refactor e-mail generation and previewing
Review Request #8885 — Created April 6, 2017 and submitted
Previously e-mail generation and previewing used duplicated logic. The
preview_{foo}_email
views would duplicate the logic used to generate
the template context that themail_{foo}
methods (that actually built
& sent the e-mails out).Now, we have utilities for building e-mail messages
(prepare_{foo}_mail
) that generate anEMailMessage
but do not send
it and a generic e-mail sending & error-handling utility in
send_email
. The logic for catching failed e-mails was present in each
method that sent an e-mail and it is now unified in a single place.Additionally, we have a decorator that generates e-mail preview views
from functions that can generate the necessary arguments to provide to a
prepare_{foo}_email
. This way the view only needs to compute the state
necessary, which has resulted in a large amount of deduplication.Unit tests have been updated to reference the new methods.
Ran unit tests.
Description | From | Last Updated |
---|---|---|
email/decorators.py should be in this diff. |
brennie | |
I don't think you meant to add reviewboard/notifications/original_cbs.py ? |
david | |
'reviewboard.notifications.email.decorators.preview_email' imported but unused |
reviewbot | |
'reviewboard.notifications.email.message.prepare_password_changed_mail' imported but unused |
reviewbot | |
Might be slightly more intuitive as: if not (siteconfig.get('mail_send_review_close_mail') and review_request.public): |
david | |
While here, can you remove the blank line and fix the ordering? |
chipx86 | |
"djblets" |
chipx86 | |
Let's reverse this check. It's quicker to check a boolean. |
chipx86 | |
No ending paren. |
chipx86 | |
No ending paren. |
chipx86 | |
Let's check trivial first. |
chipx86 | |
I think we have a :http: you can use for HTTP codes. |
chipx86 | |
This is :django:setting: |
chipx86 | |
raise |
chipx86 | |
Let's use .update here. |
chipx86 | |
We can use build_server_url(). |
chipx86 | |
If .target_groups is already fetched, this is fine. If not, we should use .values_list(). (If the former, we should document … |
chipx86 | |
This won't work. It's missing a second argument. Good indication that we're missing a test condition or tests aren't passing. |
chipx86 | |
Can this not be imported higher up? |
chipx86 | |
This could be combined. |
chipx86 | |
Reads kinda weird. Maybe just "Whether the review should only be sent to the submitter of the review request." |
chipx86 | |
Can be inline above in extra_context. |
chipx86 | |
Can now use Python 2.7 set syntax. |
chipx86 | |
Wrapped weird. |
chipx86 | |
Wrapping and paragraph break issues. |
chipx86 | |
Let's use .update({...}) |
chipx86 | |
No need for the parens after for. |
chipx86 | |
This can probably be one statement. |
chipx86 | |
"updated" |
chipx86 | |
Capitalize the beginning of each. |
chipx86 | |
Let's put one per line. Helps a little with readability here, given the statement below. |
chipx86 | |
I doubt you want these. We should have a unit test covering this case. |
chipx86 | |
2 blank lines. |
chipx86 | |
Blank line should remain. |
chipx86 | |
Trailing comma. |
chipx86 | |
local variable 'e' is assigned to but never used |
reviewbot | |
Missing period. |
chipx86 | |
E501 line too long (81 > 79 characters) |
reviewbot | |
E501 line too long (81 > 79 characters) |
reviewbot | |
E501 line too long (81 > 79 characters) |
reviewbot | |
E501 line too long (81 > 79 characters) |
reviewbot | |
E501 line too long (81 > 79 characters) |
reviewbot | |
E501 line too long (80 > 79 characters) |
reviewbot |
Description: |
|
---|
Description: |
|
---|
Checks run (2 succeeded, 1 failed with error)
Change Summary:
Update description wrt to refactoring /r/8889 out.
Description: |
|
---|
Change Summary:
Refactored many changes out of this one.
Depends On: |
|
||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Diff: |
Revision 3 (+816 -802)
|
Checks run (1 failed, 1 succeeded, 1 failed with error)
Pyflakes
-
reviewboard/accounts/views.py (Diff revision 3) -
reviewboard/accounts/views.py (Diff revision 3) 'reviewboard.notifications.email.message.prepare_password_changed_mail' imported but unused
Diff: |
Revision 4 (+816 -802)
|
---|
Checks run (2 succeeded, 1 failed with error)
Diff: |
Revision 5 (+890 -802)
|
---|
Checks run (2 succeeded, 1 failed with error)
Diff: |
Revision 6 (+890 -803)
|
---|
Checks run (2 succeeded, 1 failed with error)
-
-
-
reviewboard/notifications/email/callbacks.py (Diff revision 6) Might be slightly more intuitive as:
if not (siteconfig.get('mail_send_review_close_mail') and review_request.public):
Change Summary:
Addressed David's issues.
Diff: |
Revision 7 (+890 -803)
|
---|
Checks run (2 succeeded, 1 failed with error)
Change Summary:
Force UTF8 charset in content type.
Diff: |
Revision 8 (+891 -803)
|
---|
Checks run (2 succeeded, 1 failed with error)
-
Loving the e-mail changes :) Fantastic cleanup.
-
reviewboard/notifications/email/__init__.py (Diff revision 8) While here, can you remove the blank line and fix the ordering?
-
-
reviewboard/notifications/email/callbacks.py (Diff revision 8) Let's reverse this check. It's quicker to check a boolean.
-
-
-
-
reviewboard/notifications/email/decorators.py (Diff revision 8) I think we have a
:http:
you can use for HTTP codes. -
-
-
-
-
reviewboard/notifications/email/message.py (Diff revision 8) If
.target_groups
is already fetched, this is fine. If not, we should use.values_list()
.(If the former, we should document that.)
-
reviewboard/notifications/email/message.py (Diff revision 8) This won't work. It's missing a second argument.
Good indication that we're missing a test condition or tests aren't passing.
-
-
-
reviewboard/notifications/email/message.py (Diff revision 8) Reads kinda weird. Maybe just "Whether the review should only be sent to the submitter of the review request."
-
-
-
-
-
-
-
-
-
-
reviewboard/notifications/email/utils.py (Diff revision 8) Let's put one per line. Helps a little with readability here, given the statement below.
-
reviewboard/notifications/email/utils.py (Diff revision 8) I doubt you want these. We should have a unit test covering this case.
-
-
-
Change Summary:
Addressed Christian's issues.
Diff: |
Revision 9 (+891 -799)
|
---|
Checks run (1 failed, 1 succeeded, 1 failed with error)
Pyflakes
-
reviewboard/notifications/email/utils.py (Diff revision 9) local variable 'e' is assigned to but never used
Change Summary:
flake8
Diff: |
Revision 10 (+891 -799)
|
---|
Checks run (2 succeeded, 1 failed with error)
Diff: |
Revision 11 (+891 -799)
|
---|
Checks run (1 failed, 1 succeeded)
flake8
-
reviewboard/notifications/email/message.py (Diff revision 11) E501 line too long (81 > 79 characters)
-
reviewboard/notifications/email/message.py (Diff revision 11) E501 line too long (81 > 79 characters)
-
reviewboard/notifications/email/message.py (Diff revision 11) E501 line too long (81 > 79 characters)
-
reviewboard/notifications/email/signal_handlers.py (Diff revision 11) E501 line too long (81 > 79 characters)
-
reviewboard/notifications/email/signal_handlers.py (Diff revision 11) E501 line too long (81 > 79 characters)
-
reviewboard/notifications/email/signal_handlers.py (Diff revision 11) E501 line too long (80 > 79 characters)