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
065aa60e
Commit
065aa60e
authored
Mar 09, 2012
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document some methods
parent
5edbf55a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
6 deletions
+31
-6
trans/views.py
trans/views.py
+31
-6
No files found.
trans/views.py
View file @
065aa60e
...
...
@@ -23,12 +23,14 @@ logger = logging.getLogger('weblate')
def
home
(
request
):
projects
=
Project
.
objects
.
all
()
# Load user translations if user is authenticated
usertranslations
=
None
if
request
.
user
.
is_authenticated
():
profile
=
request
.
user
.
get_profile
()
usertranslations
=
Translation
.
objects
.
filter
(
language__in
=
profile
.
languages
.
all
()).
order_by
(
'subproject__project__name'
,
'subproject__name'
)
# Some stats
top_translations
=
Profile
.
objects
.
order_by
(
'-translated'
)[:
10
]
top_suggestions
=
Profile
.
objects
.
order_by
(
'-suggested'
)[:
10
]
...
...
@@ -80,15 +82,21 @@ def show_translation(request, project, subproject, lang):
def
download_translation
(
request
,
project
,
subproject
,
lang
):
obj
=
get_object_or_404
(
Translation
,
language__code
=
lang
,
subproject__slug
=
subproject
,
subproject__project__slug
=
project
)
# Retrieve ttkit store to get extension and mime type
store
=
obj
.
get_store
()
srcfilename
=
obj
.
get_filename
()
mime
=
store
.
Mimetypes
[
0
]
ext
=
store
.
Extensions
[
0
]
# Construct file name (do not use real filename as it is usually not that useful)
filename
=
'%s-%s-%s.%s'
%
(
project
,
subproject
,
lang
,
ext
)
# Django wrapper for sending file
wrapper
=
FileWrapper
(
file
(
srcfilename
))
response
=
HttpResponse
(
wrapper
,
mimetype
=
mime
)
# Fill in response headers
response
[
'Content-Disposition'
]
=
'attachment; filename=%s'
%
filename
response
[
'Content-Length'
]
=
os
.
path
.
getsize
(
srcfilename
)
...
...
@@ -120,6 +128,7 @@ def translate(request, project, subproject, lang):
unit
=
None
# Pre-process search form
if
request
.
method
==
'POST'
:
s
=
SearchForm
(
request
.
POST
)
else
:
...
...
@@ -146,6 +155,7 @@ def translate(request, project, subproject, lang):
if
request
.
method
==
'POST'
:
form
=
TranslationForm
(
request
.
POST
)
if
form
.
is_valid
():
# Check whether translation is not outdated
obj
.
check_sync
()
try
:
try
:
...
...
@@ -155,6 +165,7 @@ def translate(request, project, subproject, lang):
# let's pretend everyting is okay
unit
=
Unit
.
objects
.
filter
(
checksum
=
form
.
cleaned_data
[
'checksum'
],
translation
=
obj
)[
0
]
if
'suggest'
in
request
.
POST
:
# Handle suggesion saving
user
=
request
.
user
if
isinstance
(
user
,
AnonymousUser
):
user
=
None
...
...
@@ -164,20 +175,23 @@ def translate(request, project, subproject, lang):
language
=
unit
.
translation
.
language
,
project
=
unit
.
translation
.
subproject
.
project
,
user
=
user
)
# Update suggestion stats
if
profile
is
not
None
:
profile
.
suggested
+=
1
profile
.
save
()
elif
not
request
.
user
.
is_authenticated
():
# We accept translations only from authenticated
messages
.
add_message
(
request
,
messages
.
ERROR
,
_
(
'You need to login to be able to save translations!'
))
else
:
# Update unit and save it
unit
.
target
=
join_plural
(
form
.
cleaned_data
[
'target'
])
unit
.
fuzzy
=
form
.
cleaned_data
[
'fuzzy'
]
unit
.
save_backend
(
request
)
if
profile
is
not
None
:
profile
.
translated
+=
1
profile
.
save
()
# Update stats
profile
.
translated
+=
1
profile
.
save
()
#
Check and save
#
Redirect to next entry
return
HttpResponseRedirect
(
'%s?type=%s&oldpos=%d%s'
%
(
obj
.
get_translate_url
(),
rqtype
,
...
...
@@ -188,8 +202,9 @@ def translate(request, project, subproject, lang):
logger
.
error
(
'message %s disappeared!'
,
form
.
cleaned_data
[
'checksum'
])
messages
.
add_message
(
request
,
messages
.
ERROR
,
_
(
'Message you wanted to translate is no longer available!'
))
# Handle suggestions
# Handle
accepting/deleting
suggestions
if
'accept'
in
request
.
GET
or
'delete'
in
request
.
GET
:
# Check for authenticated users
if
not
request
.
user
.
is_authenticated
():
messages
.
add_message
(
request
,
messages
.
ERROR
,
_
(
'You need to login to be able to manage suggestions!'
))
return
HttpResponseRedirect
(
'%s?type=%s&oldpos=%d&dir=stay%s'
%
(
...
...
@@ -198,6 +213,8 @@ def translate(request, project, subproject, lang):
pos
,
search_url
))
# Parse suggestion ID
if
'accept'
in
request
.
GET
:
sugid
=
request
.
GET
[
'accept'
]
else
:
...
...
@@ -210,10 +227,14 @@ def translate(request, project, subproject, lang):
if
suggestion
is
not
None
:
if
'accept'
in
request
.
GET
:
# Accept suggesiont
suggestion
.
accept
(
request
)
# Delete suggestion in both cases (accepted ones are no longer needed)
suggestion
.
delete
()
else
:
messages
.
add_message
(
request
,
messages
.
ERROR
,
_
(
'Invalid suggestion!'
))
# Redirect to same entry for possible editing
return
HttpResponseRedirect
(
'%s?type=%s&oldpos=%d&dir=stay%s'
%
(
obj
.
get_translate_url
(),
rqtype
,
...
...
@@ -223,25 +244,29 @@ def translate(request, project, subproject, lang):
# If we failed to get unit above or on no POST
if
unit
is
None
:
# What unit to show
# What unit
set is about
to show
if
direction
==
'stay'
:
units
=
obj
.
unit_set
.
filter
(
position
=
pos
)
elif
direction
==
'back'
:
units
=
obj
.
unit_set
.
filter_type
(
rqtype
).
filter
(
position__lt
=
pos
).
order_by
(
'-position'
)
else
:
units
=
obj
.
unit_set
.
filter_type
(
rqtype
).
filter
(
position__gt
=
pos
)
# Apply search conditions
if
search_query
!=
''
:
query
=
Q
()
if
search_source
:
query
|=
Q
(
source__icontains
=
search_query
)
units
=
units
.
filter
(
query
)
# Grab actual unit
try
:
unit
=
units
[
0
]
except
IndexError
:
messages
.
add_message
(
request
,
messages
.
INFO
,
_
(
'You have reached end of translating.'
))
return
HttpResponseRedirect
(
obj
.
get_absolute_url
())
# Show secondary languages for logged in users
if
profile
:
secondary
=
Unit
.
objects
.
filter
(
checksum
=
unit
.
checksum
,
...
...
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