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
f8fd49a2
Commit
f8fd49a2
authored
Jan 16, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Various coding style improvements
parent
6c9dc740
Changes
19
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
188 additions
and
71 deletions
+188
-71
weblate/accounts/admin.py
weblate/accounts/admin.py
+12
-4
weblate/accounts/i18n.py
weblate/accounts/i18n.py
+6
-4
weblate/accounts/middleware.py
weblate/accounts/middleware.py
+21
-4
weblate/accounts/views.py
weblate/accounts/views.py
+25
-8
weblate/html/mail/new_translation.html
weblate/html/mail/new_translation.html
+0
-1
weblate/html/translate.html
weblate/html/translate.html
+0
-3
weblate/lang/admin.py
weblate/lang/admin.py
+1
-2
weblate/lang/models.py
weblate/lang/models.py
+0
-1
weblate/trans/admin_views.py
weblate/trans/admin_views.py
+16
-4
weblate/trans/api.py
weblate/trans/api.py
+20
-5
weblate/trans/context_processors.py
weblate/trans/context_processors.py
+8
-1
weblate/trans/forms.py
weblate/trans/forms.py
+7
-3
weblate/trans/management/commands/__init__.py
weblate/trans/management/commands/__init__.py
+4
-3
weblate/trans/management/commands/checkgit.py
weblate/trans/management/commands/checkgit.py
+0
-2
weblate/trans/management/commands/commitgit.py
weblate/trans/management/commands/commitgit.py
+0
-3
weblate/trans/management/commands/rebuild_index.py
weblate/trans/management/commands/rebuild_index.py
+15
-5
weblate/trans/managers.py
weblate/trans/managers.py
+36
-8
weblate/trans/search.py
weblate/trans/search.py
+2
-2
weblate/trans/templatetags/translations.py
weblate/trans/templatetags/translations.py
+15
-8
No files found.
weblate/accounts/admin.py
View file @
f8fd49a2
...
@@ -23,23 +23,31 @@ from weblate.accounts.models import Profile
...
@@ -23,23 +23,31 @@ from weblate.accounts.models import Profile
from
django.contrib.auth.admin
import
UserAdmin
from
django.contrib.auth.admin
import
UserAdmin
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
class
ProfileAdmin
(
admin
.
ModelAdmin
):
class
ProfileAdmin
(
admin
.
ModelAdmin
):
list_display
=
[
'user'
,
'get_full_name'
,
'language'
,
'suggested'
,
'translated'
]
list_display
=
[
search_fields
=
[
'user__username'
,
'user__email'
,
'user__first_name'
,
'user__last_name'
]
'user'
,
'get_full_name'
,
'language'
,
'suggested'
,
'translated'
]
search_fields
=
[
'user__username'
,
'user__email'
,
'user__first_name'
,
'user__last_name'
]
list_filter
=
[
'language'
]
list_filter
=
[
'language'
]
admin
.
site
.
register
(
Profile
,
ProfileAdmin
)
admin
.
site
.
register
(
Profile
,
ProfileAdmin
)
class
WeblateUserAdmin
(
UserAdmin
):
class
WeblateUserAdmin
(
UserAdmin
):
'''
'''
Custom UserAdmin to add listing of group membership and whether user is active.
Custom UserAdmin to add listing of group membership and whether user is
active.
'''
'''
list_display
=
UserAdmin
.
list_display
+
(
'is_active'
,
'user_groups'
)
list_display
=
UserAdmin
.
list_display
+
(
'is_active'
,
'user_groups'
)
list_filter
=
UserAdmin
.
list_filter
+
(
'groups'
,)
list_filter
=
UserAdmin
.
list_filter
+
(
'groups'
,)
def
user_groups
(
self
,
obj
):
def
user_groups
(
self
,
obj
):
"""
"""
Get group, separate by comma, and display empty string if user has no group
Get group, separate by comma, and display empty string if user has
no group
"""
"""
return
','
.
join
([
g
.
name
for
g
in
obj
.
groups
.
all
()])
return
','
.
join
([
g
.
name
for
g
in
obj
.
groups
.
all
()])
...
...
weblate/accounts/i18n.py
View file @
f8fd49a2
...
@@ -19,11 +19,14 @@
...
@@ -19,11 +19,14 @@
#
#
'''
'''
Fake file to translate messages from django-registration and django.contrib.auth.
Fake file to translate messages from django-registration and
django.contrib.auth.
'''
'''
def
_
(
s
):
return
s
def
_
(
text
):
return
text
def
fake
():
def
fake
():
_
(
u'This username is already taken. Please choose another.'
)
_
(
u'This username is already taken. Please choose another.'
)
...
@@ -55,4 +58,3 @@ def fake():
...
@@ -55,4 +58,3 @@ def fake():
_
(
'Strings with any failing checks'
)
_
(
'Strings with any failing checks'
)
_
(
'Fuzzy strings'
)
_
(
'Fuzzy strings'
)
_
(
'Translated strings'
)
_
(
'Translated strings'
)
weblate/accounts/middleware.py
View file @
f8fd49a2
...
@@ -23,6 +23,7 @@ import re
...
@@ -23,6 +23,7 @@ import re
from
django.conf
import
settings
from
django.conf
import
settings
from
django.contrib.auth.decorators
import
login_required
from
django.contrib.auth.decorators
import
login_required
class
RequireLoginMiddleware
(
object
):
class
RequireLoginMiddleware
(
object
):
"""
"""
Middleware component that wraps the login_required decorator around
Middleware component that wraps the login_required decorator around
...
@@ -45,14 +46,22 @@ class RequireLoginMiddleware(object):
...
@@ -45,14 +46,22 @@ class RequireLoginMiddleware(object):
define any exceptions (like login and logout URLs).
define any exceptions (like login and logout URLs).
"""
"""
def
__init__
(
self
):
def
__init__
(
self
):
self
.
required
=
self
.
get_setting_re
(
'LOGIN_REQUIRED_URLS'
,
[])
self
.
required
=
self
.
get_setting_re
(
self
.
exceptions
=
self
.
get_setting_re
(
'LOGIN_REQUIRED_URLS_EXCEPTIONS'
,
[
r'/accounts/(.*)$'
,
r'/media/(.*)$'
])
'LOGIN_REQUIRED_URLS'
,
[]
)
self
.
exceptions
=
self
.
get_setting_re
(
'LOGIN_REQUIRED_URLS_EXCEPTIONS'
,
[
r'/accounts/(.*)$'
,
r'/media/(.*)$'
]
)
def
get_setting_re
(
self
,
name
,
default
):
def
get_setting_re
(
self
,
name
,
default
):
'''
'''
Grabs regexp list from settings and compiles them
Grabs regexp list from settings and compiles them
'''
'''
return
tuple
([
re
.
compile
(
url
)
for
url
in
getattr
(
settings
,
name
,
default
)])
return
tuple
(
[
re
.
compile
(
url
)
for
url
in
getattr
(
settings
,
name
,
default
)]
)
def
process_view
(
self
,
request
,
view_func
,
view_args
,
view_kwargs
):
def
process_view
(
self
,
request
,
view_func
,
view_args
,
view_kwargs
):
'''
'''
...
@@ -62,17 +71,25 @@ class RequireLoginMiddleware(object):
...
@@ -62,17 +71,25 @@ class RequireLoginMiddleware(object):
# No need to process URLs if not configured
# No need to process URLs if not configured
if
len
(
self
.
required
)
==
0
:
if
len
(
self
.
required
)
==
0
:
return
None
return
None
# No need to process URLs if user already logged in
# No need to process URLs if user already logged in
if
request
.
user
.
is_authenticated
():
if
request
.
user
.
is_authenticated
():
return
None
return
None
# An exception match should immediately return None
# An exception match should immediately return None
for
url
in
self
.
exceptions
:
for
url
in
self
.
exceptions
:
if
url
.
match
(
request
.
path
):
if
url
.
match
(
request
.
path
):
return
None
return
None
# Requests matching a restricted URL pattern are returned
# Requests matching a restricted URL pattern are returned
# wrapped with the login_required decorator
# wrapped with the login_required decorator
for
url
in
self
.
required
:
for
url
in
self
.
required
:
if
url
.
match
(
request
.
path
):
if
url
.
match
(
request
.
path
):
return
login_required
(
view_func
)(
request
,
*
view_args
,
**
view_kwargs
)
return
login_required
(
view_func
)(
request
,
*
view_args
,
**
view_kwargs
)
# Explicitly return None for all non-matching requests
# Explicitly return None for all non-matching requests
return
None
return
None
weblate/accounts/views.py
View file @
f8fd49a2
...
@@ -32,14 +32,17 @@ from django.core.urlresolvers import reverse
...
@@ -32,14 +32,17 @@ from django.core.urlresolvers import reverse
from
weblate.accounts.models
import
set_lang
from
weblate.accounts.models
import
set_lang
from
weblate.accounts.forms
import
ProfileForm
,
SubscriptionForm
,
UserForm
,
ContactForm
from
weblate.accounts.forms
import
ProfileForm
,
SubscriptionForm
,
UserForm
,
ContactForm
def
mail_admins_sender
(
subject
,
message
,
sender
,
fail_silently
=
False
,
connection
=
None
,
def
mail_admins_sender
(
subject
,
message
,
sender
,
fail_silently
=
False
,
connection
=
None
,
html_message
=
None
):
html_message
=
None
):
"""Sends a message to the admins, as defined by the ADMINS setting."""
"""Sends a message to the admins, as defined by the ADMINS setting."""
if
not
settings
.
ADMINS
:
if
not
settings
.
ADMINS
:
return
return
mail
=
EmailMultiAlternatives
(
u'%s%s'
%
(
settings
.
EMAIL_SUBJECT_PREFIX
,
subject
),
mail
=
EmailMultiAlternatives
(
u'%s%s'
%
(
settings
.
EMAIL_SUBJECT_PREFIX
,
subject
),
message
,
sender
,
[
a
[
1
]
for
a
in
settings
.
ADMINS
],
message
,
sender
,
[
a
[
1
]
for
a
in
settings
.
ADMINS
],
connection
=
connection
)
connection
=
connection
)
if
html_message
:
if
html_message
:
mail
.
attach_alternative
(
html_message
,
'text/html'
)
mail
.
attach_alternative
(
html_message
,
'text/html'
)
mail
.
send
(
fail_silently
=
fail_silently
)
mail
.
send
(
fail_silently
=
fail_silently
)
...
@@ -51,8 +54,14 @@ def profile(request):
...
@@ -51,8 +54,14 @@ def profile(request):
if
request
.
method
==
'POST'
:
if
request
.
method
==
'POST'
:
# Read params
# Read params
form
=
ProfileForm
(
request
.
POST
,
instance
=
request
.
user
.
get_profile
())
form
=
ProfileForm
(
request
.
POST
,
instance
=
request
.
user
.
get_profile
())
subscriptionform
=
SubscriptionForm
(
request
.
POST
,
instance
=
request
.
user
.
get_profile
())
subscriptionform
=
SubscriptionForm
(
userform
=
UserForm
(
request
.
POST
,
instance
=
request
.
user
)
request
.
POST
,
instance
=
request
.
user
.
get_profile
()
)
userform
=
UserForm
(
request
.
POST
,
instance
=
request
.
user
)
if
form
.
is_valid
()
and
userform
.
is_valid
()
and
subscriptionform
.
is_valid
():
if
form
.
is_valid
()
and
userform
.
is_valid
()
and
subscriptionform
.
is_valid
():
# Save changes
# Save changes
form
.
save
()
form
.
save
()
...
@@ -75,8 +84,12 @@ def profile(request):
...
@@ -75,8 +84,12 @@ def profile(request):
return
response
return
response
else
:
else
:
form
=
ProfileForm
(
instance
=
request
.
user
.
get_profile
())
form
=
ProfileForm
(
instance
=
request
.
user
.
get_profile
())
subscriptionform
=
SubscriptionForm
(
instance
=
request
.
user
.
get_profile
())
subscriptionform
=
SubscriptionForm
(
userform
=
UserForm
(
instance
=
request
.
user
)
instance
=
request
.
user
.
get_profile
()
)
userform
=
UserForm
(
instance
=
request
.
user
)
profile
=
request
.
user
.
get_profile
()
profile
=
request
.
user
.
get_profile
()
response
=
render_to_response
(
'profile.html'
,
RequestContext
(
request
,
{
response
=
render_to_response
(
'profile.html'
,
RequestContext
(
request
,
{
...
@@ -89,6 +102,7 @@ def profile(request):
...
@@ -89,6 +102,7 @@ def profile(request):
response
.
set_cookie
(
settings
.
LANGUAGE_COOKIE_NAME
,
profile
.
language
)
response
.
set_cookie
(
settings
.
LANGUAGE_COOKIE_NAME
,
profile
.
language
)
return
response
return
response
def
contact
(
request
):
def
contact
(
request
):
if
request
.
method
==
'POST'
:
if
request
.
method
==
'POST'
:
form
=
ContactForm
(
request
.
POST
)
form
=
ContactForm
(
request
.
POST
)
...
@@ -102,7 +116,10 @@ def contact(request):
...
@@ -102,7 +116,10 @@ def contact(request):
),
),
form
.
cleaned_data
[
'email'
],
form
.
cleaned_data
[
'email'
],
)
)
messages
.
info
(
request
,
_
(
'Message has been sent to administrator.'
))
messages
.
info
(
request
,
_
(
'Message has been sent to administrator.'
)
)
return
HttpResponseRedirect
(
reverse
(
'home'
))
return
HttpResponseRedirect
(
reverse
(
'home'
))
else
:
else
:
initial
=
{}
initial
=
{}
...
...
weblate/html/mail/new_translation.html
View file @
f8fd49a2
...
@@ -43,4 +43,3 @@
...
@@ -43,4 +43,3 @@
{% include "mail/footer.html" %}
{% include "mail/footer.html" %}
{% endblock %}
{% endblock %}
weblate/html/translate.html
View file @
f8fd49a2
...
@@ -258,6 +258,3 @@
...
@@ -258,6 +258,3 @@
</div>
</div>
{% endblock %}
{% endblock %}
weblate/lang/admin.py
View file @
f8fd49a2
...
@@ -21,11 +21,10 @@
...
@@ -21,11 +21,10 @@
from
django.contrib
import
admin
from
django.contrib
import
admin
from
weblate.lang.models
import
Language
from
weblate.lang.models
import
Language
class
LanguageAdmin
(
admin
.
ModelAdmin
):
class
LanguageAdmin
(
admin
.
ModelAdmin
):
list_display
=
[
'name'
,
'code'
,
'get_plural_form'
,
'direction'
]
list_display
=
[
'name'
,
'code'
,
'get_plural_form'
,
'direction'
]
search_fields
=
[
'name'
,
'code'
]
search_fields
=
[
'name'
,
'code'
]
list_filter
=
(
'direction'
,
)
list_filter
=
(
'direction'
,
)
admin
.
site
.
register
(
Language
,
LanguageAdmin
)
admin
.
site
.
register
(
Language
,
LanguageAdmin
)
weblate/lang/models.py
View file @
f8fd49a2
...
@@ -203,7 +203,6 @@ class LanguageManager(models.Manager):
...
@@ -203,7 +203,6 @@ class LanguageManager(models.Manager):
# Create new one
# Create new one
return
self
.
auto_create
(
code
)
return
self
.
auto_create
(
code
)
def
auto_create
(
self
,
code
):
def
auto_create
(
self
,
code
):
'''
'''
Automatically creates new language based on code and best guess
Automatically creates new language based on code and best guess
...
...
weblate/trans/admin_views.py
View file @
f8fd49a2
...
@@ -30,6 +30,7 @@ import weblate
...
@@ -30,6 +30,7 @@ import weblate
import
os
import
os
@
staff_member_required
@
staff_member_required
def
report
(
request
):
def
report
(
request
):
'''
'''
...
@@ -39,6 +40,7 @@ def report(request):
...
@@ -39,6 +40,7 @@ def report(request):
'subprojects'
:
SubProject
.
objects
.
all
()
'subprojects'
:
SubProject
.
objects
.
all
()
}))
}))
@
staff_member_required
@
staff_member_required
def
performance
(
request
):
def
performance
(
request
):
'''
'''
...
@@ -93,16 +95,26 @@ def performance(request):
...
@@ -93,16 +95,26 @@ def performance(request):
'production-cache'
,
'production-cache'
,
))
))
# Check email setup
# Check email setup
default_mails
=
(
'root@localhost'
,
'webmaster@localhost'
,
'noreply@weblate.org'
)
default_mails
=
(
'root@localhost'
,
'webmaster@localhost'
,
'noreply@weblate.org'
)
checks
.
append
((
checks
.
append
((
_
(
'Email addresses'
),
_
(
'Email addresses'
),
settings
.
SERVER_EMAIL
not
in
default_mails
and
settings
.
DEFAULT_FROM_EMAIL
not
in
default_mails
,
settings
.
SERVER_EMAIL
not
in
default_mails
and
settings
.
DEFAULT_FROM_EMAIL
not
in
default_mails
,
'production-email'
,
'production-email'
,
))
))
return
render_to_response
(
"admin/performance.html"
,
RequestContext
(
request
,
{
return
render_to_response
(
"admin/performance.html"
,
RequestContext
(
request
,
{
'checks'
:
checks
,
'checks'
:
checks
,
}
)
)
}))
@
staff_member_required
@
staff_member_required
def
ssh
(
request
):
def
ssh
(
request
):
...
...
weblate/trans/api.py
View file @
f8fd49a2
...
@@ -20,7 +20,9 @@
...
@@ -20,7 +20,9 @@
from
django.conf
import
settings
from
django.conf
import
settings
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.decorators.csrf
import
csrf_exempt
from
django.http
import
HttpResponse
,
HttpResponseNotAllowed
,
HttpResponseBadRequest
from
django.http
import
(
HttpResponse
,
HttpResponseNotAllowed
,
HttpResponseBadRequest
)
from
django.shortcuts
import
get_object_or_404
from
django.shortcuts
import
get_object_or_404
from
django.contrib.sites.models
import
Site
from
django.contrib.sites.models
import
Site
...
@@ -80,7 +82,11 @@ def github_hook(request):
...
@@ -80,7 +82,11 @@ def github_hook(request):
branch
=
data
[
'ref'
].
split
(
'/'
)[
-
1
]
branch
=
data
[
'ref'
].
split
(
'/'
)[
-
1
]
except
KeyError
:
except
KeyError
:
return
HttpResponseBadRequest
(
'could not parse json!'
)
return
HttpResponseBadRequest
(
'could not parse json!'
)
logger
.
info
(
'received GitHub notification on repository %s, branch %s'
,
repo
,
branch
)
logger
.
info
(
'received GitHub notification on repository %s, branch %s'
,
repo
,
branch
)
for
obj
in
SubProject
.
objects
.
filter
(
repo
=
repo
,
branch
=
branch
):
for
obj
in
SubProject
.
objects
.
filter
(
repo
=
repo
,
branch
=
branch
):
logger
.
info
(
'GitHub notification will update %s'
,
obj
)
logger
.
info
(
'GitHub notification will update %s'
,
obj
)
t
=
threading
.
Thread
(
target
=
obj
.
do_update
)
t
=
threading
.
Thread
(
target
=
obj
.
do_update
)
...
@@ -93,14 +99,21 @@ def dt_handler(obj):
...
@@ -93,14 +99,21 @@ def dt_handler(obj):
if
hasattr
(
obj
,
'isoformat'
):
if
hasattr
(
obj
,
'isoformat'
):
return
obj
.
isoformat
()
return
obj
.
isoformat
()
else
:
else
:
raise
TypeError
(
'Object of type %s with value of %s is not JSON serializable'
%
(
type
(
obj
),
repr
(
obj
)))
raise
TypeError
(
'Object of type %s with value of %s is not JSON serializable'
%
(
type
(
obj
),
repr
(
obj
))
)
def
export_stats
(
request
,
project
,
subproject
):
def
export_stats
(
request
,
project
,
subproject
):
'''
'''
Exports stats in JSON format.
Exports stats in JSON format.
'''
'''
subprj
=
get_object_or_404
(
SubProject
,
slug
=
subproject
,
project__slug
=
project
)
subprj
=
get_object_or_404
(
SubProject
,
slug
=
subproject
,
project__slug
=
project
)
response
=
[]
response
=
[]
site
=
Site
.
objects
.
get_current
()
site
=
Site
.
objects
.
get_current
()
for
trans
in
subprj
.
translation_set
.
all
():
for
trans
in
subprj
.
translation_set
.
all
():
...
@@ -117,7 +130,9 @@ def export_stats(request, project, subproject):
...
@@ -117,7 +130,9 @@ def export_stats(request, project, subproject):
'failing'
:
trans
.
get_failing_checks
(),
'failing'
:
trans
.
get_failing_checks
(),
'failing_percent'
:
trans
.
get_failing_checks_percent
(),
'failing_percent'
:
trans
.
get_failing_checks_percent
(),
'url'
:
trans
.
get_share_url
(),
'url'
:
trans
.
get_share_url
(),
'url_translate'
:
'http://%s%s'
%
(
site
.
domain
,
trans
.
get_absolute_url
()),
'url_translate'
:
'http://%s%s'
%
(
site
.
domain
,
trans
.
get_absolute_url
()
),
})
})
return
HttpResponse
(
return
HttpResponse
(
json
.
dumps
(
response
,
default
=
dt_handler
),
json
.
dumps
(
response
,
default
=
dt_handler
),
...
...
weblate/trans/context_processors.py
View file @
f8fd49a2
...
@@ -22,17 +22,21 @@ import weblate
...
@@ -22,17 +22,21 @@ import weblate
from
django.conf
import
settings
from
django.conf
import
settings
from
datetime
import
datetime
from
datetime
import
datetime
def
version
(
request
):
def
version
(
request
):
return
{
'version'
:
weblate
.
VERSION
}
return
{
'version'
:
weblate
.
VERSION
}
def
weblate_url
(
request
):
def
weblate_url
(
request
):
return
{
return
{
'weblate_url'
:
'http://weblate.org/?utm_source=weblate&utm_term=%s'
%
weblate
.
VERSION
'weblate_url'
:
'http://weblate.org/?utm_source=weblate&utm_term=%s'
%
weblate
.
VERSION
}
}
def
title
(
request
):
def
title
(
request
):
return
{
'site_title'
:
settings
.
SITE_TITLE
}
return
{
'site_title'
:
settings
.
SITE_TITLE
}
def
date
(
request
):
def
date
(
request
):
return
{
return
{
'current_date'
:
datetime
.
utcnow
().
strftime
(
'%Y-%m-%d'
),
'current_date'
:
datetime
.
utcnow
().
strftime
(
'%Y-%m-%d'
),
...
@@ -40,17 +44,20 @@ def date(request):
...
@@ -40,17 +44,20 @@ def date(request):
'current_month'
:
datetime
.
utcnow
().
strftime
(
'%m'
),
'current_month'
:
datetime
.
utcnow
().
strftime
(
'%m'
),
}
}
def
url
(
request
):
def
url
(
request
):
return
{
return
{
'current_url'
:
request
.
get_full_path
(),
'current_url'
:
request
.
get_full_path
(),
}
}
def
mt
(
request
):
def
mt
(
request
):
return
{
return
{
'apertium_api_key'
:
settings
.
MT_APERTIUM_KEY
,
'apertium_api_key'
:
settings
.
MT_APERTIUM_KEY
,
'microsoft_api_key'
:
settings
.
MT_MICROSOFT_KEY
,
'microsoft_api_key'
:
settings
.
MT_MICROSOFT_KEY
,
}
}
def
registration
(
request
):
def
registration
(
request
):
return
{
return
{
'registration_open'
:
getattr
(
settings
,
'REGISTRATION_OPEN'
,
True
),
'registration_open'
:
getattr
(
settings
,
'REGISTRATION_OPEN'
,
True
),
...
...
weblate/trans/forms.py
View file @
f8fd49a2
...
@@ -19,7 +19,9 @@
...
@@ -19,7 +19,9 @@
#
#
from
django
import
forms
from
django
import
forms
from
django.utils.translation
import
ugettext_lazy
as
_
,
ugettext
,
pgettext_lazy
from
django.utils.translation
import
(
ugettext_lazy
as
_
,
ugettext
,
pgettext_lazy
)
from
django.utils.safestring
import
mark_safe
from
django.utils.safestring
import
mark_safe
from
django.utils.encoding
import
smart_unicode
from
django.utils.encoding
import
smart_unicode
from
django.forms
import
ValidationError
from
django.forms
import
ValidationError
...
@@ -124,7 +126,10 @@ class PluralField(forms.CharField):
...
@@ -124,7 +126,10 @@ class PluralField(forms.CharField):
class
TranslationForm
(
forms
.
Form
):
class
TranslationForm
(
forms
.
Form
):
checksum
=
forms
.
CharField
(
widget
=
forms
.
HiddenInput
)
checksum
=
forms
.
CharField
(
widget
=
forms
.
HiddenInput
)
target
=
PluralField
(
required
=
False
)
target
=
PluralField
(
required
=
False
)
fuzzy
=
forms
.
BooleanField
(
label
=
pgettext_lazy
(
'Checkbox for marking translation fuzzy'
,
'Fuzzy'
),
required
=
False
)
fuzzy
=
forms
.
BooleanField
(
label
=
pgettext_lazy
(
'Checkbox for marking translation fuzzy'
,
'Fuzzy'
),
required
=
False
)
class
AntispamForm
(
forms
.
Form
):
class
AntispamForm
(
forms
.
Form
):
...
@@ -286,4 +291,3 @@ class EnageLanguageForm(forms.Form):
...
@@ -286,4 +291,3 @@ class EnageLanguageForm(forms.Form):
super
(
EnageLanguageForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
super
(
EnageLanguageForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
'lang'
].
choices
+=
choices
self
.
fields
[
'lang'
].
choices
+=
choices
weblate/trans/management/commands/__init__.py
View file @
f8fd49a2
...
@@ -29,11 +29,13 @@ class WeblateCommand(BaseCommand):
...
@@ -29,11 +29,13 @@ class WeblateCommand(BaseCommand):
'''
'''
args
=
'<project/subproject>'
args
=
'<project/subproject>'
option_list
=
BaseCommand
.
option_list
+
(
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'--all'
,
make_option
(
'--all'
,
action
=
'store_true'
,
action
=
'store_true'
,
dest
=
'all'
,
dest
=
'all'
,
default
=
False
,
default
=
False
,
help
=
'process all subprojects'
),
help
=
'process all subprojects'
),
)
)
def
get_units
(
self
,
*
args
,
**
options
):
def
get_units
(
self
,
*
args
,
**
options
):
...
@@ -78,4 +80,3 @@ class WeblateCommand(BaseCommand):
...
@@ -78,4 +80,3 @@ class WeblateCommand(BaseCommand):
result
|=
found
result
|=
found
return
result
return
result
weblate/trans/management/commands/checkgit.py
View file @
f8fd49a2
...
@@ -32,5 +32,3 @@ class Command(WeblateCommand):
...
@@ -32,5 +32,3 @@ class Command(WeblateCommand):
r
=
s
.
get_repo
()
r
=
s
.
get_repo
()
print
'%s:'
%
s
print
'%s:'
%
s
print
r
.
git
.
status
()
print
r
.
git
.
status
()
weblate/trans/management/commands/commitgit.py
View file @
f8fd49a2
...
@@ -30,6 +30,3 @@ class Command(WeblateCommand):
...
@@ -30,6 +30,3 @@ class Command(WeblateCommand):
'''
'''
for
s
in
self
.
get_subprojects
(
*
args
,
**
options
):
for
s
in
self
.
get_subprojects
(
*
args
,
**
options
):
s
.
commit_pending
()
s
.
commit_pending
()
weblate/trans/management/commands/rebuild_index.py
View file @
f8fd49a2
...
@@ -21,7 +21,9 @@
...
@@ -21,7 +21,9 @@
from
weblate.trans.management.commands
import
WeblateCommand
from
weblate.trans.management.commands
import
WeblateCommand
from
weblate.trans.models
import
Unit
from
weblate.trans.models
import
Unit
from
weblate.lang.models
import
Language
from
weblate.lang.models
import
Language
from
weblate.trans.search
import
FULLTEXT_INDEX
,
create_source_index
,
create_target_index
from
weblate.trans.search
import
(
FULLTEXT_INDEX
,
create_source_index
,
create_target_index
)
from
optparse
import
make_option
from
optparse
import
make_option
...
@@ -50,7 +52,8 @@ class Command(WeblateCommand):
...
@@ -50,7 +52,8 @@ class Command(WeblateCommand):
# Update source index
# Update source index
with
FULLTEXT_INDEX
.
source_writer
(
buffered
=
False
)
as
writer
:
with
FULLTEXT_INDEX
.
source_writer
(
buffered
=
False
)
as
writer
:
for
unit
in
units
.
values
(
'checksum'
,
'source'
,
'context'
).
iterator
():
checksums
=
units
.
values
(
'checksum'
,
'source'
,
'context'
)
for
unit
in
checksums
.
iterator
():
Unit
.
objects
.
add_to_source_index
(
Unit
.
objects
.
add_to_source_index
(
unit
[
'checksum'
],
unit
[
'checksum'
],
unit
[
'source'
],
unit
[
'source'
],
...
@@ -61,11 +64,18 @@ class Command(WeblateCommand):
...
@@ -61,11 +64,18 @@ class Command(WeblateCommand):
# Update per language indices
# Update per language indices
for
lang
in
languages
:
for
lang
in
languages
:
with
FULLTEXT_INDEX
.
target_writer
(
lang
=
lang
.
code
,
buffered
=
False
)
as
writer
:
with
FULLTEXT_INDEX
.
target_writer
(
lang
=
lang
.
code
,
buffered
=
False
)
as
writer
:
language_units
=
units
.
filter
(
translation__language
=
lang
).
exclude
(
target
=
''
)
for
unit
in
language_units
.
values
(
'checksum'
,
'target'
).
iterator
():
language_units
=
units
.
filter
(
translation__language
=
lang
).
exclude
(
target
=
''
).
values
(
'checksum'
,
'target'
)
for
unit
in
language_units
.
iterator
():
Unit
.
objects
.
add_to_target_index
(
Unit
.
objects
.
add_to_target_index
(
unit
[
'checksum'
],
unit
[
'checksum'
],
unit
[
'target'
],
unit
[
'target'
],
writer
writer
)
)
weblate/trans/managers.py
View file @
f8fd49a2
...
@@ -28,7 +28,9 @@ from weblate.lang.models import Language
...
@@ -28,7 +28,9 @@ from weblate.lang.models import Language
from
whoosh
import
qparser
from
whoosh
import
qparser
from
util
import
msg_checksum
,
get_source
,
get_target
,
get_context
from
weblate.trans.util
import
(
msg_checksum
,
get_source
,
get_target
,
get_context
)
from
weblate.trans.search
import
FULLTEXT_INDEX
,
SOURCE_SCHEMA
,
TARGET_SCHEMA
from
weblate.trans.search
import
FULLTEXT_INDEX
,
SOURCE_SCHEMA
,
TARGET_SCHEMA
...
@@ -324,9 +326,9 @@ class UnitManager(models.Manager):
...
@@ -324,9 +326,9 @@ class UnitManager(models.Manager):
'''
'''
Wrapper for fulltext search.
Wrapper for fulltext search.
'''
'''
qp
=
qparser
.
QueryParser
(
field
,
schema
)
parser
=
qparser
.
QueryParser
(
field
,
schema
)
q
=
qp
.
parse
(
query
)
parsed
=
parser
.
parse
(
query
)
return
[
searcher
.
stored_fields
(
d
)[
'checksum'
]
for
d
in
searcher
.
docs_for_query
(
q
)]
return
[
searcher
.
stored_fields
(
d
)[
'checksum'
]
for
d
in
searcher
.
docs_for_query
(
parsed
)]
def
search
(
self
,
query
,
source
=
True
,
context
=
True
,
translation
=
True
,
checksums
=
False
):
def
search
(
self
,
query
,
source
=
True
,
context
=
True
,
translation
=
True
,
checksums
=
False
):
...
@@ -339,14 +341,32 @@ class UnitManager(models.Manager):
...
@@ -339,14 +341,32 @@ class UnitManager(models.Manager):
if
source
or
context
:
if
source
or
context
:
with
FULLTEXT_INDEX
.
source_searcher
(
not
settings
.
OFFLOAD_INDEXING
)
as
searcher
:
with
FULLTEXT_INDEX
.
source_searcher
(
not
settings
.
OFFLOAD_INDEXING
)
as
searcher
:
if
source
:
if
source
:
ret
=
ret
.
union
(
self
.
__search
(
searcher
,
'source'
,
SOURCE_SCHEMA
,
query
))
results
=
self
.
__search
(
searcher
,
'source'
,
SOURCE_SCHEMA
,
query
)
ret
=
ret
.
union
(
results
)
if
context
:
if
context
:
ret
=
ret
.
union
(
self
.
__search
(
searcher
,
'context'
,
SOURCE_SCHEMA
,
query
))
results
=
self
.
__search
(
searcher
,
'context'
,
SOURCE_SCHEMA
,
query
)
ret
=
ret
.
union
(
results
)
if
translation
:
if
translation
:
sample
=
self
.
all
()[
0
]
sample
=
self
.
all
()[
0
]
with
FULLTEXT_INDEX
.
target_searcher
(
sample
.
translation
.
language
.
code
,
not
settings
.
OFFLOAD_INDEXING
)
as
searcher
:
with
FULLTEXT_INDEX
.
target_searcher
(
sample
.
translation
.
language
.
code
,
not
settings
.
OFFLOAD_INDEXING
)
as
searcher
:
ret
=
ret
.
union
(
self
.
__search
(
searcher
,
'target'
,
TARGET_SCHEMA
,
query
))
results
=
self
.
__search
(
searcher
,
'target'
,
TARGET_SCHEMA
,
query
)
ret
=
ret
.
union
(
results
)
if
checksums
:
if
checksums
:
return
ret
return
ret
...
@@ -365,7 +385,14 @@ class UnitManager(models.Manager):
...
@@ -365,7 +385,14 @@ class UnitManager(models.Manager):
# Try to find at least configured number of similar strings, remove up to 4 words
# Try to find at least configured number of similar strings, remove up to 4 words
while
len
(
ret
)
<
settings
.
SIMILAR_MESSAGES
and
cnt
>
0
and
len
(
terms
)
-
cnt
<
4
:
while
len
(
ret
)
<
settings
.
SIMILAR_MESSAGES
and
cnt
>
0
and
len
(
terms
)
-
cnt
<
4
:
for
search
in
itertools
.
combinations
(
terms
,
cnt
):
for
search
in
itertools
.
combinations
(
terms
,
cnt
):
ret
=
ret
.
union
(
self
.
search
(
' '
.
join
(
search
),
True
,
False
,
False
,
True
))
results
=
self
.
search
(
' '
.
join
(
search
),
True
,
False
,
False
,
True
)
ret
=
ret
.
union
(
results
)
cnt
-=
1
cnt
-=
1
return
self
.
filter
(
return
self
.
filter
(
...
@@ -428,6 +455,7 @@ class DictionaryManager(models.Manager):
...
@@ -428,6 +455,7 @@ class DictionaryManager(models.Manager):
return
ret
return
ret
class
ChangeManager
(
models
.
Manager
):
class
ChangeManager
(
models
.
Manager
):
def
content
(
self
):
def
content
(
self
):
'''
'''
...
...
weblate/trans/search.py
View file @
f8fd49a2
...
@@ -84,7 +84,7 @@ class Index(object):
...
@@ -84,7 +84,7 @@ class Index(object):
try
:
try
:
self
.
_source
=
open_dir
(
self
.
_source
=
open_dir
(
settings
.
WHOOSH_INDEX
,
settings
.
WHOOSH_INDEX
,
indexname
=
'source'
indexname
=
'source'
)
)
except
whoosh
.
index
.
EmptyIndexError
:
except
whoosh
.
index
.
EmptyIndexError
:
self
.
_source
=
create_source_index
()
self
.
_source
=
create_source_index
()
...
@@ -101,7 +101,7 @@ class Index(object):
...
@@ -101,7 +101,7 @@ class Index(object):
try
:
try
:
self
.
_target
[
lang
]
=
open_dir
(
self
.
_target
[
lang
]
=
open_dir
(
settings
.
WHOOSH_INDEX
,
settings
.
WHOOSH_INDEX
,
indexname
=
'target-%s'
%
lang
indexname
=
'target-%s'
%
lang
)
)
except
whoosh
.
index
.
EmptyIndexError
:
except
whoosh
.
index
.
EmptyIndexError
:
self
.
_target
[
lang
]
=
create_target_index
(
lang
)
self
.
_target
[
lang
]
=
create_target_index
(
lang
)
...
...
weblate/trans/templatetags/translations.py
View file @
f8fd49a2
...
@@ -36,7 +36,9 @@ import weblate
...
@@ -36,7 +36,9 @@ import weblate
import
weblate.trans
import
weblate.trans
from
weblate.trans.simplediff
import
htmlDiff
from
weblate.trans.simplediff
import
htmlDiff
from
weblate.trans.util
import
split_plural
,
gravatar_for_email
,
get_user_display
from
weblate.trans.util
import
(
split_plural
,
gravatar_for_email
,
get_user_display
)
from
weblate.lang.models
import
Language
from
weblate.lang.models
import
Language
from
weblate.trans.models
import
Project
,
SubProject
,
Dictionary
from
weblate.trans.models
import
Project
,
SubProject
,
Dictionary
from
weblate.trans.checks
import
CHECKS
from
weblate.trans.checks
import
CHECKS
...
@@ -120,7 +122,10 @@ def fmttranslation(value, language=None, diff=None):
...
@@ -120,7 +122,10 @@ def fmttranslation(value, language=None, diff=None):
value
=
'<hr />'
.
join
(
parts
)
value
=
'<hr />'
.
join
(
parts
)
return
mark_safe
(
'<span lang="%s" dir="%s" class="direction">%s</span>'
%
(
language
.
code
,
language
.
direction
,
value
))
return
mark_safe
(
'<span lang="%s" dir="%s" class="direction">%s</span>'
%
(
language
.
code
,
language
.
direction
,
value
)
)
@
register
.
filter
@
register
.
filter
...
@@ -238,15 +243,17 @@ def gravatar(user, size=80):
...
@@ -238,15 +243,17 @@ def gravatar(user, size=80):
url
,
alt
,
size
,
size
url
,
alt
,
size
,
size
)
)
# Following code is heavily based on Django's django.contrib.humanize
# implementation of naturaltime
@
register
.
filter
@
register
.
filter
def
naturaltime
(
value
):
def
naturaltime
(
value
):
"""
"""
For date and time values shows how many seconds, minutes or hours ago
Heavily based on Django's django.contrib.humanize
compared to current timestamp returns representing string.
implementation of naturaltime
"""
if
not
isinstance
(
value
,
date
):
# datetime is a subclass of date
For date and time values shows how many seconds, minutes or hours ago
compared to current timestamp returns representing string.
"""
# datetime is a subclass of date
if
not
isinstance
(
value
,
date
):
return
value
return
value
now
=
timezone
.
now
()
now
=
timezone
.
now
()
...
...
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