Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
846897ad
Commit
846897ad
authored
Oct 31, 2012
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor out email sending from profile
parent
35b699bf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
41 deletions
+48
-41
weblate/accounts/models.py
weblate/accounts/models.py
+48
-41
No files found.
weblate/accounts/models.py
View file @
846897ad
...
...
@@ -46,6 +46,53 @@ import logging
logger
=
logging
.
getLogger
(
'weblate'
)
def
send_notification_email
(
language
,
email
,
notification
,
translation_obj
,
context
=
{},
headers
=
{}):
'''
Renders and sends notification email.
'''
cur_language
=
translation
.
get_language
()
try
:
logger
.
info
(
'sending notification %s on %s to %s'
,
notification
,
translation_obj
.
__unicode__
(),
email
)
# Load user language
translation
.
activate
(
language
)
# Template names
subject_template
=
'mail/%s_subject.txt'
%
notification
body_template
=
'mail/%s.txt'
%
notification
# Adjust context
domain
=
Site
.
objects
.
get_current
().
domain
context
[
'translation'
]
=
translation_obj
context
[
'current_site'
]
=
domain
context
[
'translation_url'
]
=
'http://%s%s'
%
(
domain
,
translation_obj
.
get_absolute_url
())
# Render subject
subject
=
render_to_string
(
subject_template
,
context
)
# Render body
body
=
render_to_string
(
body_template
,
context
)
# Define headers
headers
[
'Auto-Submitted'
]
=
'auto-generated'
headers
[
'X-AutoGenerated'
]
=
'yes'
headers
[
'Precedence'
]
=
'bulk'
headers
[
'X-Mailer'
]
=
'Weblate %s'
%
weblate
.
VERSION
# Create message
email
=
EmailMessage
(
settings
.
EMAIL_SUBJECT_PREFIX
+
subject
.
strip
(),
body
,
to
=
[
email
],
headers
=
headers
)
# Send it out
email
.
send
(
fail_silently
=
False
)
finally
:
translation
.
activate
(
cur_language
)
class
ProfileManager
(
models
.
Manager
):
'''
Manager providing shortcuts for subscription queries.
...
...
@@ -128,47 +175,7 @@ class Profile(models.Model):
'''
Wrapper for sending notifications to user.
'''
cur_language
=
translation
.
get_language
()
try
:
logger
.
info
(
'sending notification %s on %s to %s'
,
notification
,
translation_obj
.
__unicode__
(),
self
.
user
.
email
)
# Load user language
translation
.
activate
(
self
.
language
)
# Template names
subject_template
=
'mail/%s_subject.txt'
%
notification
body_template
=
'mail/%s.txt'
%
notification
# Adjust context
domain
=
Site
.
objects
.
get_current
().
domain
context
[
'translation'
]
=
translation_obj
context
[
'current_site'
]
=
domain
context
[
'translation_url'
]
=
'http://%s%s'
%
(
domain
,
translation_obj
.
get_absolute_url
())
# Render subject
subject
=
render_to_string
(
subject_template
,
context
)
# Render body
body
=
render_to_string
(
body_template
,
context
)
# Define headers
headers
[
'Auto-Submitted'
]
=
'auto-generated'
headers
[
'X-AutoGenerated'
]
=
'yes'
headers
[
'Precedence'
]
=
'bulk'
headers
[
'X-Mailer'
]
=
'Weblate %s'
%
weblate
.
VERSION
# Create message
email
=
EmailMessage
(
settings
.
EMAIL_SUBJECT_PREFIX
+
subject
.
strip
(),
body
,
to
=
[
self
.
user
.
email
],
headers
=
headers
)
# Send it out
email
.
send
(
fail_silently
=
False
)
finally
:
translation
.
activate
(
cur_language
)
send_notification_email
(
self
.
language
,
self
.
user
.
email
,
notification
,
translation_obj
,
context
,
headers
)
def
notify_any_translation
(
self
,
unit
,
oldunit
):
'''
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment