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
a0285b0b
Commit
a0285b0b
authored
Apr 12, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update comment stats on runtime
parent
3e8959c5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
43 deletions
+64
-43
trans/models/unit.py
trans/models/unit.py
+56
-0
trans/models/unitdata.py
trans/models/unitdata.py
+6
-0
trans/views/edit.py
trans/views/edit.py
+2
-43
No files found.
trans/models/unit.py
View file @
a0285b0b
...
@@ -1054,3 +1054,59 @@ class Unit(models.Model):
...
@@ -1054,3 +1054,59 @@ class Unit(models.Model):
# Update unit flags
# Update unit flags
for
unit
in
suggestion
.
get_related_units
():
for
unit
in
suggestion
.
get_related_units
():
unit
.
update_has_suggestion
()
unit
.
update_has_suggestion
()
def
add_comment
(
self
,
user
,
lang
,
text
):
'''
Adds comment to this unit.
'''
from
trans.models.unitdata
import
Comment
,
Change
from
accounts.models
import
Profile
new_comment
=
Comment
.
objects
.
create
(
user
=
user
,
checksum
=
self
.
checksum
,
project
=
self
.
translation
.
subproject
.
project
,
comment
=
text
language
=
lang
)
Change
.
objects
.
create
(
unit
=
self
,
action
=
Change
.
ACTION_COMMENT
,
translation
=
self
.
translation
,
user
=
request
.
user
)
# Invalidate counts cache
if
lang
is
None
:
self
.
translation
.
invalidate_cache
(
'sourcecomments'
)
else
:
self
.
translation
.
invalidate_cache
(
'targetcomments'
)
# Update unit stats
for
unit
in
new_comment
.
get_related_units
():
unit
.
update_has_comment
()
# Notify subscribed users
subscriptions
=
Profile
.
objects
.
subscribed_new_comment
(
self
.
translation
.
subproject
.
project
,
lang
,
request
.
user
)
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
=
request
.
user
.
email
,
)
trans/models/unitdata.py
View file @
a0285b0b
...
@@ -117,6 +117,12 @@ class Comment(models.Model, RelatedUnitMixin):
...
@@ -117,6 +117,12 @@ class Comment(models.Model, RelatedUnitMixin):
def
get_user_display
(
self
):
def
get_user_display
(
self
):
return
get_user_display
(
self
.
user
,
link
=
True
)
return
get_user_display
(
self
.
user
,
link
=
True
)
def
delete
(
self
,
*
args
,
**
kwargs
):
super
(
Suggestion
,
self
).
delete
(
*
args
,
**
kwargs
)
# Update unit flags
for
unit
in
suggestion
.
get_related_units
():
unit
.
update_has_comment
()
CHECK_CHOICES
=
[(
x
,
CHECKS
[
x
].
name
)
for
x
in
CHECKS
]
CHECK_CHOICES
=
[(
x
,
CHECKS
[
x
].
name
)
for
x
in
CHECKS
]
...
...
trans/views/edit.py
View file @
a0285b0b
...
@@ -28,7 +28,7 @@ from django.utils import formats
...
@@ -28,7 +28,7 @@ from django.utils import formats
import
uuid
import
uuid
import
time
import
time
from
trans.models
import
SubProject
,
Unit
,
Suggestion
,
Change
,
Comment
from
trans.models
import
SubProject
,
Unit
,
Suggestion
,
Change
from
trans.forms
import
(
from
trans.forms
import
(
TranslationForm
,
SearchForm
,
TranslationForm
,
SearchForm
,
MergeForm
,
AutoForm
,
ReviewForm
,
MergeForm
,
AutoForm
,
ReviewForm
,
...
@@ -561,49 +561,8 @@ def comment(request, pk):
...
@@ -561,49 +561,8 @@ def comment(request, pk):
form
=
CommentForm
(
request
.
POST
)
form
=
CommentForm
(
request
.
POST
)
if
form
.
is_valid
():
if
form
.
is_valid
():
new_comment
=
Comment
.
objects
.
create
(
unit
.
add_comment
(
request
.
user
,
lang
,
form
.
cleaned_data
[
'comment'
])
user
=
request
.
user
,
checksum
=
obj
.
checksum
,
project
=
obj
.
translation
.
subproject
.
project
,
comment
=
form
.
cleaned_data
[
'comment'
],
language
=
lang
)
Change
.
objects
.
create
(
unit
=
obj
,
action
=
Change
.
ACTION_COMMENT
,
translation
=
obj
.
translation
,
user
=
request
.
user
)
# Invalidate counts cache
if
lang
is
None
:
obj
.
translation
.
invalidate_cache
(
'sourcecomments'
)
else
:
obj
.
translation
.
invalidate_cache
(
'targetcomments'
)
messages
.
info
(
request
,
_
(
'Posted new comment'
))
messages
.
info
(
request
,
_
(
'Posted new comment'
))
# Notify subscribed users
subscriptions
=
Profile
.
objects
.
subscribed_new_comment
(
obj
.
translation
.
subproject
.
project
,
lang
,
request
.
user
)
for
subscription
in
subscriptions
:
subscription
.
notify_new_comment
(
obj
,
new_comment
)
# Notify upstream
report_source_bugs
=
obj
.
translation
.
subproject
.
report_source_bugs
if
lang
is
None
and
report_source_bugs
!=
''
:
send_notification_email
(
'en'
,
report_source_bugs
,
'new_comment'
,
obj
.
translation
,
{
'unit'
:
obj
,
'comment'
:
new_comment
,
'subproject'
:
obj
.
translation
.
subproject
,
},
from_email
=
request
.
user
.
email
,
)
else
:
else
:
messages
.
error
(
request
,
_
(
'Failed to add comment!'
))
messages
.
error
(
request
,
_
(
'Failed to add comment!'
))
...
...
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