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
1be622c2
Commit
1be622c2
authored
Apr 17, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move notifications handling to accounts module
It is better to have it all in single place (fixes #252)
parent
855193e4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
125 additions
and
78 deletions
+125
-78
accounts/models.py
accounts/models.py
+108
-0
trans/models/subproject.py
trans/models/subproject.py
+2
-19
trans/models/translation.py
trans/models/translation.py
+2
-6
trans/models/unit.py
trans/models/unit.py
+13
-53
No files found.
accounts/models.py
View file @
1be622c2
...
...
@@ -42,6 +42,114 @@ from trans.util import get_user_display, get_site_url
import
weblate
def
notify_merge_failure
(
subproject
,
error
,
status
):
'''
Notification on merge failure.
'''
subscriptions
=
Profile
.
objects
.
subscribed_merge_failure
(
subproject
.
project
,
)
for
subscription
in
subscriptions
:
subscription
.
notify_merge_failure
(
subproject
,
error
,
status
)
# Notify admins
send_notification_email
(
'en'
,
'ADMINS'
,
'merge_failure'
,
subproject
,
{
'subproject'
:
subproject
,
'status'
:
status
,
'error'
:
error
,
}
)
def
notify_new_string
(
translation
):
'''
Notification on new string to translate.
'''
subscriptions
=
Profile
.
objects
.
subscribed_new_string
(
translation
.
subproject
.
project
,
translation
.
language
)
for
subscription
in
subscriptions
:
subscription
.
notify_new_string
(
translation
)
def
notify_new_translation
(
unit
,
oldunit
,
user
):
'''
Notify subscribed users about new translation
'''
subscriptions
=
Profile
.
objects
.
subscribed_any_translation
(
unit
.
translation
.
subproject
.
project
,
unit
.
translation
.
language
,
user
)
for
subscription
in
subscriptions
:
subscription
.
notify_any_translation
(
unit
,
oldunit
)
def
notify_new_contributor
(
unit
,
user
):
'''
Notify about new contributor.
'''
subscriptions
=
Profile
.
objects
.
subscribed_new_contributor
(
unit
.
translation
.
subproject
.
project
,
unit
.
translation
.
language
,
user
)
for
subscription
in
subscriptions
:
subscription
.
notify_new_contributor
(
unit
.
translation
,
user
)
def
notify_new_suggestion
(
unit
,
suggestion
,
user
):
'''
Notify about new suggestion.
'''
subscriptions
=
Profile
.
objects
.
subscribed_new_suggestion
(
unit
.
translation
.
subproject
.
project
,
unit
.
translation
.
language
,
user
)
for
subscription
in
subscriptions
:
subscription
.
notify_new_suggestion
(
unit
.
translation
,
suggestion
,
unit
)
def
notify_new_comment
(
unit
,
comment
,
user
,
report_source_bugs
):
'''
Notify about new comment.
'''
subscriptions
=
Profile
.
objects
.
subscribed_new_comment
(
unit
.
translation
.
subproject
.
project
,
comment
.
lang
,
user
)
for
subscription
in
subscriptions
:
subscription
.
notify_new_comment
(
unit
,
comment
)
# Notify upstream
if
comment
.
lang
is
None
and
report_source_bugs
!=
''
:
send_notification_email
(
'en'
,
report_source_bugs
,
'new_comment'
,
unit
.
translation
,
{
'unit'
:
unit
,
'comment'
:
comment
,
'subproject'
:
unit
.
translation
.
subproject
,
},
from_email
=
user
.
email
,
)
def
send_notification_email
(
language
,
email
,
notification
,
translation_obj
,
context
=
None
,
headers
=
None
,
from_email
=
None
):
'''
...
...
trans/models/subproject.py
View file @
1be622c2
...
...
@@ -593,25 +593,8 @@ class SubProject(models.Model, PercentMixin, URLMixin):
Sends out notifications on merge failure.
'''
# Notify subscribed users about failure
from
accounts.models
import
Profile
,
send_notification_email
subscriptions
=
Profile
.
objects
.
subscribed_merge_failure
(
self
.
project
,
)
for
subscription
in
subscriptions
:
subscription
.
notify_merge_failure
(
self
,
error
,
status
)
# Notify admins
send_notification_email
(
'en'
,
'ADMINS'
,
'merge_failure'
,
self
,
{
'subproject'
:
self
,
'status'
:
status
,
'error'
:
error
,
}
)
from
accounts.models
import
notify_merge_failure
notify_merge_failure
(
self
,
error
,
status
)
def
update_branch
(
self
,
request
=
None
):
'''
...
...
trans/models/translation.py
View file @
1be622c2
...
...
@@ -561,12 +561,8 @@ class Translation(models.Model, URLMixin):
# Notify subscribed users
if
was_new
:
from
accounts.models
import
Profile
subscriptions
=
Profile
.
objects
.
subscribed_new_string
(
self
.
subproject
.
project
,
self
.
language
)
for
subscription
in
subscriptions
:
subscription
.
notify_new_string
(
self
)
from
accounts.models
import
notify_new_string
notify_new_string
(
self
)
@
property
def
git_repo
(
self
):
...
...
trans/models/unit.py
View file @
1be622c2
...
...
@@ -577,7 +577,9 @@ class Unit(models.Model):
'''
Stores unit to backend.
'''
from
accounts.models
import
Profile
from
accounts.models
import
(
notify_new_translation
,
notify_new_contributor
)
from
trans.models.changes
import
Change
# Update lock timestamp
...
...
@@ -636,13 +638,7 @@ class Unit(models.Model):
self
.
translation
.
update_stats
()
# Notify subscribed users about new translation
subscriptions
=
Profile
.
objects
.
subscribed_any_translation
(
self
.
translation
.
subproject
.
project
,
self
.
translation
.
language
,
request
.
user
)
for
subscription
in
subscriptions
:
subscription
.
notify_any_translation
(
self
,
oldunit
)
notify_new_translation
(
self
,
oldunit
,
request
.
user
)
# Update user stats
profile
=
request
.
user
.
get_profile
()
...
...
@@ -655,16 +651,7 @@ class Unit(models.Model):
user
=
request
.
user
)
if
not
user_changes
.
exists
():
# Get list of subscribers for new contributor
subscriptions
=
Profile
.
objects
.
subscribed_new_contributor
(
self
.
translation
.
subproject
.
project
,
self
.
translation
.
language
,
request
.
user
)
for
subscription
in
subscriptions
:
subscription
.
notify_new_contributor
(
self
.
translation
,
request
.
user
)
notify_new_contributor
(
self
,
request
.
user
)
# Generate Change object for this change
if
gen_change
:
...
...
@@ -997,7 +984,7 @@ class Unit(models.Model):
'''
from
trans.models.unitdata
import
Suggestion
from
trans.models.changes
import
Change
from
accounts.models
import
Profile
from
accounts.models
import
notify_new_suggestion
if
not
user
.
is_authenticated
():
user
=
None
...
...
@@ -1020,17 +1007,7 @@ class Unit(models.Model):
)
# Notify subscribed users
subscriptions
=
Profile
.
objects
.
subscribed_new_suggestion
(
self
.
translation
.
subproject
.
project
,
self
.
translation
.
language
,
user
)
for
subscription
in
subscriptions
:
subscription
.
notify_new_suggestion
(
self
.
translation
,
suggestion
,
self
)
notify_new_suggestion
(
self
,
suggestion
,
user
)
# Update suggestion stats
if
user
is
not
None
:
...
...
@@ -1048,7 +1025,7 @@ class Unit(models.Model):
'''
from
trans.models.unitdata
import
Comment
from
trans.models.changes
import
Change
from
accounts.models
import
Profile
,
send_notification_email
from
accounts.models
import
notify_new_comment
new_comment
=
Comment
.
objects
.
create
(
user
=
user
,
...
...
@@ -1075,26 +1052,9 @@ class Unit(models.Model):
unit
.
update_has_comment
()
# Notify subscribed users
subscriptions
=
Profile
.
objects
.
subscribed_new_comment
(
self
.
translation
.
subproject
.
project
,
lang
,
user
notify_new_comment
(
self
,
new_comment
,
user
,
self
.
translation
.
subproject
.
report_source_bugs
)
for
subscription
in
subscriptions
:
subscription
.
notify_new_comment
(
self
,
new_comment
)
# Notify upstream
report_source_bugs
=
self
.
translation
.
subproject
.
report_source_bugs
if
lang
is
None
and
report_source_bugs
!=
''
:
send_notification_email
(
'en'
,
report_source_bugs
,
'new_comment'
,
self
.
translation
,
{
'unit'
:
self
,
'comment'
:
new_comment
,
'subproject'
:
self
.
translation
.
subproject
,
},
from_email
=
user
.
email
,
)
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