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
Hide 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
from
django.contrib.auth.admin
import
UserAdmin
from
django.contrib.auth.models
import
User
class
ProfileAdmin
(
admin
.
ModelAdmin
):
list_display
=
[
'user'
,
'get_full_name'
,
'language'
,
'suggested'
,
'translated'
]
search_fields
=
[
'user__username'
,
'user__email'
,
'user__first_name'
,
'user__last_name'
]
list_display
=
[
'user'
,
'get_full_name'
,
'language'
,
'suggested'
,
'translated'
]
search_fields
=
[
'user__username'
,
'user__email'
,
'user__first_name'
,
'user__last_name'
]
list_filter
=
[
'language'
]
admin
.
site
.
register
(
Profile
,
ProfileAdmin
)
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_filter
=
UserAdmin
.
list_filter
+
(
'groups'
,)
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
()])
...
...
weblate/accounts/i18n.py
View file @
f8fd49a2
...
...
@@ -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
():
_
(
u'This username is already taken. Please choose another.'
)
...
...
@@ -55,4 +58,3 @@ def fake():
_
(
'Strings with any failing checks'
)
_
(
'Fuzzy strings'
)
_
(
'Translated strings'
)
weblate/accounts/middleware.py
View file @
f8fd49a2
...
...
@@ -23,6 +23,7 @@ import re
from
django.conf
import
settings
from
django.contrib.auth.decorators
import
login_required
class
RequireLoginMiddleware
(
object
):
"""
Middleware component that wraps the login_required decorator around
...
...
@@ -45,14 +46,22 @@ class RequireLoginMiddleware(object):
define any exceptions (like login and logout URLs).
"""
def
__init__
(
self
):
self
.
required
=
self
.
get_setting_re
(
'LOGIN_REQUIRED_URLS'
,
[])
self
.
exceptions
=
self
.
get_setting_re
(
'LOGIN_REQUIRED_URLS_EXCEPTIONS'
,
[
r'/accounts/(.*)$'
,
r'/media/(.*)$'
])
self
.
required
=
self
.
get_setting_re
(
'LOGIN_REQUIRED_URLS'
,
[]
)
self
.
exceptions
=
self
.
get_setting_re
(
'LOGIN_REQUIRED_URLS_EXCEPTIONS'
,
[
r'/accounts/(.*)$'
,
r'/media/(.*)$'
]
)
def
get_setting_re
(
self
,
name
,
default
):
'''
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
):
'''
...
...
@@ -62,17 +71,25 @@ class RequireLoginMiddleware(object):
# No need to process URLs if not configured
if
len
(
self
.
required
)
==
0
:
return
None
# No need to process URLs if user already logged in
if
request
.
user
.
is_authenticated
():
return
None
# An exception match should immediately return None
for
url
in
self
.
exceptions
:
if
url
.
match
(
request
.
path
):
return
None
# Requests matching a restricted URL pattern are returned
# wrapped with the login_required decorator
for
url
in
self
.
required
:
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
return
None
weblate/accounts/views.py
View file @
f8fd49a2
...
...
@@ -32,14 +32,17 @@ from django.core.urlresolvers import reverse
from
weblate.accounts.models
import
set_lang
from
weblate.accounts.forms
import
ProfileForm
,
SubscriptionForm
,
UserForm
,
ContactForm
def
mail_admins_sender
(
subject
,
message
,
sender
,
fail_silently
=
False
,
connection
=
None
,
html_message
=
None
):
"""Sends a message to the admins, as defined by the ADMINS setting."""
if
not
settings
.
ADMINS
:
return
mail
=
EmailMultiAlternatives
(
u'%s%s'
%
(
settings
.
EMAIL_SUBJECT_PREFIX
,
subject
),
message
,
sender
,
[
a
[
1
]
for
a
in
settings
.
ADMINS
],
connection
=
connection
)
mail
=
EmailMultiAlternatives
(
u'%s%s'
%
(
settings
.
EMAIL_SUBJECT_PREFIX
,
subject
),
message
,
sender
,
[
a
[
1
]
for
a
in
settings
.
ADMINS
],
connection
=
connection
)
if
html_message
:
mail
.
attach_alternative
(
html_message
,
'text/html'
)
mail
.
send
(
fail_silently
=
fail_silently
)
...
...
@@ -51,8 +54,14 @@ def profile(request):
if
request
.
method
==
'POST'
:
# Read params
form
=
ProfileForm
(
request
.
POST
,
instance
=
request
.
user
.
get_profile
())
subscriptionform
=
SubscriptionForm
(
request
.
POST
,
instance
=
request
.
user
.
get_profile
())
userform
=
UserForm
(
request
.
POST
,
instance
=
request
.
user
)
subscriptionform
=
SubscriptionForm
(
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
():
# Save changes
form
.
save
()
...
...
@@ -75,8 +84,12 @@ def profile(request):
return
response
else
:
form
=
ProfileForm
(
instance
=
request
.
user
.
get_profile
())
subscriptionform
=
SubscriptionForm
(
instance
=
request
.
user
.
get_profile
())
userform
=
UserForm
(
instance
=
request
.
user
)
subscriptionform
=
SubscriptionForm
(
instance
=
request
.
user
.
get_profile
()
)
userform
=
UserForm
(
instance
=
request
.
user
)
profile
=
request
.
user
.
get_profile
()
response
=
render_to_response
(
'profile.html'
,
RequestContext
(
request
,
{
...
...
@@ -89,6 +102,7 @@ def profile(request):
response
.
set_cookie
(
settings
.
LANGUAGE_COOKIE_NAME
,
profile
.
language
)
return
response
def
contact
(
request
):
if
request
.
method
==
'POST'
:
form
=
ContactForm
(
request
.
POST
)
...
...
@@ -102,7 +116,10 @@ def contact(request):
),
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'
))
else
:
initial
=
{}
...
...
weblate/html/mail/new_translation.html
View file @
f8fd49a2
...
...
@@ -43,4 +43,3 @@
{% include "mail/footer.html" %}
{% endblock %}
weblate/html/translate.html
View file @
f8fd49a2
...
...
@@ -258,6 +258,3 @@
</div>
{% endblock %}
weblate/lang/admin.py
View file @
f8fd49a2
...
...
@@ -21,11 +21,10 @@
from
django.contrib
import
admin
from
weblate.lang.models
import
Language
class
LanguageAdmin
(
admin
.
ModelAdmin
):
list_display
=
[
'name'
,
'code'
,
'get_plural_form'
,
'direction'
]
search_fields
=
[
'name'
,
'code'
]
list_filter
=
(
'direction'
,
)
admin
.
site
.
register
(
Language
,
LanguageAdmin
)
weblate/lang/models.py
View file @
f8fd49a2
...
...
@@ -203,7 +203,6 @@ class LanguageManager(models.Manager):
# Create new one
return
self
.
auto_create
(
code
)
def
auto_create
(
self
,
code
):
'''
Automatically creates new language based on code and best guess
...
...
weblate/trans/admin_views.py
View file @
f8fd49a2
...
...
@@ -30,6 +30,7 @@ import weblate
import
os
@
staff_member_required
def
report
(
request
):
'''
...
...
@@ -39,6 +40,7 @@ def report(request):
'subprojects'
:
SubProject
.
objects
.
all
()
}))
@
staff_member_required
def
performance
(
request
):
'''
...
...
@@ -93,16 +95,26 @@ def performance(request):
'production-cache'
,
))
# Check email setup
default_mails
=
(
'root@localhost'
,
'webmaster@localhost'
,
'noreply@weblate.org'
)
default_mails
=
(
'root@localhost'
,
'webmaster@localhost'
,
'noreply@weblate.org'
)
checks
.
append
((
_
(
'Email addresses'
),
settings
.
SERVER_EMAIL
not
in
default_mails
and
settings
.
DEFAULT_FROM_EMAIL
not
in
default_mails
,
'production-email'
,
))
return
render_to_response
(
"admin/performance.html"
,
RequestContext
(
request
,
{
'checks'
:
checks
,
return
render_to_response
(
"admin/performance.html"
,
RequestContext
(
request
,
{
'checks'
:
checks
,
}
)
)
}))
@
staff_member_required
def
ssh
(
request
):
...
...
weblate/trans/api.py
View file @
f8fd49a2
...
...
@@ -20,7 +20,9 @@
from
django.conf
import
settings
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.contrib.sites.models
import
Site
...
...
@@ -80,7 +82,11 @@ def github_hook(request):
branch
=
data
[
'ref'
].
split
(
'/'
)[
-
1
]
except
KeyError
:
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
):
logger
.
info
(
'GitHub notification will update %s'
,
obj
)
t
=
threading
.
Thread
(
target
=
obj
.
do_update
)
...
...
@@ -93,14 +99,21 @@ def dt_handler(obj):
if
hasattr
(
obj
,
'isoformat'
):
return
obj
.
isoformat
()
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
):
'''
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
=
[]
site
=
Site
.
objects
.
get_current
()
for
trans
in
subprj
.
translation_set
.
all
():
...
...
@@ -117,7 +130,9 @@ def export_stats(request, project, subproject):
'failing'
:
trans
.
get_failing_checks
(),
'failing_percent'
:
trans
.
get_failing_checks_percent
(),
'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
(
json
.
dumps
(
response
,
default
=
dt_handler
),
...
...
weblate/trans/context_processors.py
View file @
f8fd49a2
...
...
@@ -22,35 +22,42 @@ import weblate
from
django.conf
import
settings
from
datetime
import
datetime
def
version
(
request
):
return
{
'version'
:
weblate
.
VERSION
}
def
weblate_url
(
request
):
return
{
'weblate_url'
:
'http://weblate.org/?utm_source=weblate&utm_term=%s'
%
weblate
.
VERSION
}
def
title
(
request
):
return
{
'site_title'
:
settings
.
SITE_TITLE
}
def
date
(
request
):
return
{
'current_date'
:
datetime
.
utcnow
().
strftime
(
'%Y-%m-%d'
),
'current_year'
:
datetime
.
utcnow
().
strftime
(
'%Y'
),
'current_month'
:
datetime
.
utcnow
().
strftime
(
'%m'
),
}
}
def
url
(
request
):
return
{
'current_url'
:
request
.
get_full_path
(),
}
def
mt
(
request
):
return
{
'apertium_api_key'
:
settings
.
MT_APERTIUM_KEY
,
'microsoft_api_key'
:
settings
.
MT_MICROSOFT_KEY
,
}
def
registration
(
request
):
return
{
'registration_open'
:
getattr
(
settings
,
'REGISTRATION_OPEN'
,
True
),
...
...
weblate/trans/forms.py
View file @
f8fd49a2
...
...
@@ -19,7 +19,9 @@
#
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.encoding
import
smart_unicode
from
django.forms
import
ValidationError
...
...
@@ -124,7 +126,10 @@ class PluralField(forms.CharField):
class
TranslationForm
(
forms
.
Form
):
checksum
=
forms
.
CharField
(
widget
=
forms
.
HiddenInput
)
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
):
...
...
@@ -286,4 +291,3 @@ class EnageLanguageForm(forms.Form):
super
(
EnageLanguageForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
'lang'
].
choices
+=
choices
weblate/trans/management/commands/__init__.py
View file @
f8fd49a2
...
...
@@ -29,11 +29,13 @@ class WeblateCommand(BaseCommand):
'''
args
=
'<project/subproject>'
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'--all'
,
make_option
(
'--all'
,
action
=
'store_true'
,
dest
=
'all'
,
default
=
False
,
help
=
'process all subprojects'
),
help
=
'process all subprojects'
),
)
def
get_units
(
self
,
*
args
,
**
options
):
...
...
@@ -78,4 +80,3 @@ class WeblateCommand(BaseCommand):
result
|=
found
return
result
weblate/trans/management/commands/checkgit.py
View file @
f8fd49a2
...
...
@@ -32,5 +32,3 @@ class Command(WeblateCommand):
r
=
s
.
get_repo
()
print
'%s:'
%
s
print
r
.
git
.
status
()
weblate/trans/management/commands/commitgit.py
View file @
f8fd49a2
...
...
@@ -30,6 +30,3 @@ class Command(WeblateCommand):
'''
for
s
in
self
.
get_subprojects
(
*
args
,
**
options
):
s
.
commit_pending
()
weblate/trans/management/commands/rebuild_index.py
View file @
f8fd49a2
...
...
@@ -21,7 +21,9 @@
from
weblate.trans.management.commands
import
WeblateCommand
from
weblate.trans.models
import
Unit
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
...
...
@@ -50,7 +52,8 @@ class Command(WeblateCommand):
# Update source index
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
[
'checksum'
],
unit
[
'source'
],
...
...
@@ -61,11 +64,18 @@ class Command(WeblateCommand):
# Update per language indices
for
lang
in
languages
:
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
[
'checksum'
],
unit
[
'target'
],
writer
)
weblate/trans/managers.py
View file @
f8fd49a2
...
...
@@ -28,7 +28,9 @@ from weblate.lang.models import Language
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
...
...
@@ -324,9 +326,9 @@ class UnitManager(models.Manager):
'''
Wrapper for fulltext search.
'''
qp
=
qparser
.
QueryParser
(
field
,
schema
)
q
=
qp
.
parse
(
query
)
return
[
searcher
.
stored_fields
(
d
)[
'checksum'
]
for
d
in
searcher
.
docs_for_query
(
q
)]
parser
=
qparser
.
QueryParser
(
field
,
schema
)
parsed
=
parser
.
parse
(
query
)
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
):
...
...
@@ -339,14 +341,32 @@ class UnitManager(models.Manager):
if
source
or
context
:
with
FULLTEXT_INDEX
.
source_searcher
(
not
settings
.
OFFLOAD_INDEXING
)
as
searcher
:
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
:
ret
=
ret
.
union
(
self
.
__search
(
searcher
,
'context'
,
SOURCE_SCHEMA
,
query
))
results
=
self
.
__search
(
searcher
,
'context'
,
SOURCE_SCHEMA
,
query
)
ret
=
ret
.
union
(
results
)
if
translation
:
sample
=
self
.
all
()[
0
]
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
:
return
ret
...
...
@@ -365,7 +385,14 @@ class UnitManager(models.Manager):
# 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
:
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
return
self
.
filter
(
...
...
@@ -428,6 +455,7 @@ class DictionaryManager(models.Manager):
return
ret
class
ChangeManager
(
models
.
Manager
):
def
content
(
self
):
'''
...
...
weblate/trans/search.py
View file @
f8fd49a2
...
...
@@ -84,7 +84,7 @@ class Index(object):
try
:
self
.
_source
=
open_dir
(
settings
.
WHOOSH_INDEX
,
indexname
=
'source'
indexname
=
'source'
)
except
whoosh
.
index
.
EmptyIndexError
:
self
.
_source
=
create_source_index
()
...
...
@@ -101,7 +101,7 @@ class Index(object):
try
:
self
.
_target
[
lang
]
=
open_dir
(
settings
.
WHOOSH_INDEX
,
indexname
=
'target-%s'
%
lang
indexname
=
'target-%s'
%
lang
)
except
whoosh
.
index
.
EmptyIndexError
:
self
.
_target
[
lang
]
=
create_target_index
(
lang
)
...
...
weblate/trans/templatetags/translations.py
View file @
f8fd49a2
...
...
@@ -36,7 +36,9 @@ import weblate
import
weblate.trans
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.trans.models
import
Project
,
SubProject
,
Dictionary
from
weblate.trans.checks
import
CHECKS
...
...
@@ -120,7 +122,10 @@ def fmttranslation(value, language=None, diff=None):
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
...
...
@@ -238,15 +243,17 @@ def gravatar(user, size=80):
url
,
alt
,
size
,
size
)
# Following code is heavily based on Django's django.contrib.humanize
# implementation of naturaltime
@
register
.
filter
def
naturaltime
(
value
):
"""
For date and time values shows how many seconds, minutes or hours ago
compared to current timestamp returns representing string.
"""
if
not
isinstance
(
value
,
date
):
# datetime is a subclass of date
Heavily based on Django's django.contrib.humanize
implementation of naturaltime
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
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