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
10d61c5e
Commit
10d61c5e
authored
Apr 09, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move suggestion handling to separate function
parent
56da9e44
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
37 deletions
+49
-37
trans/views/edit.py
trans/views/edit.py
+49
-37
No files found.
trans/views/edit.py
View file @
10d61c5e
...
...
@@ -309,7 +309,53 @@ def handle_merge(obj, request, profile, next_unit_url):
)
def
handle_suggestions
(
request
,
this_unit_url
):
'''
Handles suggestion deleting/accepting.
'''
# Check for authenticated users
if
not
request
.
user
.
is_authenticated
():
messages
.
error
(
request
,
_
(
'You need to log in to be able to manage suggestions!'
))
return
HttpResponseRedirect
(
this_unit_url
)
# Parse suggestion ID
if
'accept'
in
request
.
GET
:
if
not
request
.
user
.
has_perm
(
'trans.accept_suggestion'
):
messages
.
error
(
request
,
_
(
'You do not have privilege to accept suggestions!'
))
return
HttpResponseRedirect
(
this_unit_url
)
sugid
=
request
.
GET
[
'accept'
]
else
:
if
not
request
.
user
.
has_perm
(
'trans.delete_suggestion'
):
messages
.
error
(
request
,
_
(
'You do not have privilege to delete suggestions!'
))
return
HttpResponseRedirect
(
this_unit_url
)
sugid
=
request
.
GET
[
'delete'
]
try
:
sugid
=
int
(
sugid
)
suggestion
=
Suggestion
.
objects
.
get
(
pk
=
sugid
)
except
Suggestion
.
DoesNotExist
:
suggestion
=
None
if
suggestion
is
not
None
:
if
'accept'
in
request
.
GET
:
# Accept suggesiont
suggestion
.
accept
(
request
)
# Invalidate caches
for
unit
in
Unit
.
objects
.
filter
(
checksum
=
suggestion
.
checksum
):
unit
.
translation
.
invalidate_cache
(
'suggestions'
)
# Delete suggestion in both cases (accepted ones are no longer
# needed)
suggestion
.
delete
()
else
:
messages
.
error
(
request
,
_
(
'Invalid suggestion!'
))
# Redirect to same entry for possible editing
return
HttpResponseRedirect
(
this_unit_url
)
def
translate
(
request
,
project
,
subproject
,
lang
):
'''
Generic entry point for translating, suggesting and searching.
'''
obj
=
get_translation
(
request
,
project
,
subproject
,
lang
)
# Check locks
...
...
@@ -366,43 +412,9 @@ def translate(request, project, subproject, lang):
# Handle accepting/deleting suggestions
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!'
))
return
HttpResponseRedirect
(
this_unit_url
)
# Parse suggestion ID
if
'accept'
in
request
.
GET
:
if
not
request
.
user
.
has_perm
(
'trans.accept_suggestion'
):
messages
.
error
(
request
,
_
(
'You do not have privilege to accept suggestions!'
))
return
HttpResponseRedirect
(
this_unit_url
)
sugid
=
request
.
GET
[
'accept'
]
else
:
if
not
request
.
user
.
has_perm
(
'trans.delete_suggestion'
):
messages
.
error
(
request
,
_
(
'You do not have privilege to delete suggestions!'
))
return
HttpResponseRedirect
(
this_unit_url
)
sugid
=
request
.
GET
[
'delete'
]
try
:
sugid
=
int
(
sugid
)
suggestion
=
Suggestion
.
objects
.
get
(
pk
=
sugid
)
except
:
suggestion
=
None
if
suggestion
is
not
None
:
if
'accept'
in
request
.
GET
:
# Accept suggesiont
suggestion
.
accept
(
request
)
# Invalidate caches
for
unit
in
Unit
.
objects
.
filter
(
checksum
=
suggestion
.
checksum
):
unit
.
translation
.
invalidate_cache
(
'suggestions'
)
# Delete suggestion in both cases (accepted ones are no longer
# needed)
suggestion
.
delete
()
else
:
messages
.
error
(
request
,
_
(
'Invalid suggestion!'
))
# Redirect to same entry for possible editing
return
HttpResponseRedirect
(
this_unit_url
)
response
=
handle_suggestions
(
request
,
this_unit_url
)
if
response
is
not
None
:
return
response
# Grab actual unit
unit
=
obj
.
unit_set
.
get
(
pk
=
search_result
[
'ids'
][
offset
])
...
...
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