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
e4988cc5
Commit
e4988cc5
authored
Jul 24, 2012
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement checks for translation locking (issue #60)
parent
7e10b166
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
6 deletions
+51
-6
weblate/trans/models.py
weblate/trans/models.py
+45
-0
weblate/trans/views.py
weblate/trans/views.py
+6
-6
No files found.
weblate/trans/models.py
View file @
e4988cc5
...
...
@@ -897,6 +897,51 @@ class Translation(models.Model):
return
0
return
round
(
self
.
translated
*
100.0
/
self
.
total
,
1
)
def
is_locked
(
self
,
request
=
None
):
'''
Check whether the translation is locked and
possibly emmits messages if request object is
provided.
'''
# Check for project lock
if
self
.
subproject
.
locked
:
if
request
is
not
None
:
messages
.
error
(
request
,
_
(
'This translation is currently locked for updates!'
))
return
True
# Check for translation lock
if
self
.
is_user_locked
():
if
request
is
not
None
:
messages
.
error
(
request
,
_
(
'This translation is locked by %s for translation till %s!'
)
%
(
self
.
lock_user
.
get_full_name
(),
self
.
lock_timestamp
,
)
)
return
True
return
False
def
is_user_locked
(
self
):
'''
Checks whether there is valid user lock on this translation.
'''
# Any user?
if
self
.
lock_user
is
None
:
return
False
# Is lock still valid?
if
self
.
lock_timestamp
<
datetime
.
now
():
# Clear the lock
self
.
lock_user
=
None
self
.
save
()
return
False
return
True
def
get_non_translated
(
self
):
return
self
.
total
-
self
.
translated
...
...
weblate/trans/views.py
View file @
e4988cc5
...
...
@@ -343,8 +343,8 @@ def show_translation(request, project, subproject, lang):
obj
=
get_object_or_404
(
Translation
,
language__code
=
lang
,
subproject__slug
=
subproject
,
subproject__project__slug
=
project
,
enabled
=
True
)
last_changes
=
Change
.
objects
.
filter
(
unit__translation
=
obj
).
order_by
(
'-timestamp'
)[:
10
]
if
obj
.
subproject
.
locked
:
messages
.
error
(
request
,
_
(
'This translation is currently locked for updates!'
)
)
# Check locks
obj
.
is_locked
(
request
)
# How much is user allowed to configure upload?
if
request
.
user
.
has_perm
(
'trans.author_translation'
):
...
...
@@ -655,8 +655,8 @@ def get_filter_name(rqtype, search_query):
def
translate
(
request
,
project
,
subproject
,
lang
):
obj
=
get_object_or_404
(
Translation
,
language__code
=
lang
,
subproject__slug
=
subproject
,
subproject__project__slug
=
project
,
enabled
=
True
)
if
obj
.
subproject
.
locked
:
messages
.
error
(
request
,
_
(
'This translation is currently locked for updates!'
)
)
# Check locks
locked
=
obj
.
is_locked
(
request
)
if
request
.
user
.
is_authenticated
():
profile
=
request
.
user
.
get_profile
()
...
...
@@ -686,7 +686,7 @@ def translate(request, project, subproject, lang):
))
form
=
TranslationForm
(
request
.
POST
)
if
form
.
is_valid
()
and
not
obj
.
subproject
.
locked
:
if
form
.
is_valid
()
and
not
locked
:
# Check whether translation is not outdated
obj
.
check_sync
()
try
:
...
...
@@ -807,7 +807,7 @@ def translate(request, project, subproject, lang):
messages
.
error
(
request
,
_
(
'Message you wanted to translate is no longer available!'
))
# Handle accepting/deleting suggestions
if
not
obj
.
subproject
.
locked
and
(
'accept'
in
request
.
GET
or
'delete'
in
request
.
GET
):
if
not
locked
and
(
'accept'
in
request
.
GET
or
'delete'
in
request
.
GET
):
# Check for authenticated users
if
not
request
.
user
.
is_authenticated
():
messages
.
error
(
request
,
_
(
'You need to log in to be able to manage suggestions!'
))
...
...
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