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
8536a0f9
Commit
8536a0f9
authored
Jan 31, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide default values for configuration (issue #198)
parent
b09781d8
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
143 additions
and
43 deletions
+143
-43
weblate/settings_example.py
weblate/settings_example.py
+3
-2
weblate/trans/admin_views.py
weblate/trans/admin_views.py
+2
-1
weblate/trans/api.py
weblate/trans/api.py
+4
-4
weblate/trans/appsettings.py
weblate/trans/appsettings.py
+97
-0
weblate/trans/context_processors.py
weblate/trans/context_processors.py
+4
-3
weblate/trans/feeds.py
weblate/trans/feeds.py
+3
-3
weblate/trans/managers.py
weblate/trans/managers.py
+6
-6
weblate/trans/models.py
weblate/trans/models.py
+8
-8
weblate/trans/search.py
weblate/trans/search.py
+7
-7
weblate/trans/templatetags/translations.py
weblate/trans/templatetags/translations.py
+2
-2
weblate/trans/views.py
weblate/trans/views.py
+5
-5
weblate/trans/widgets.py
weblate/trans/widgets.py
+2
-2
No files found.
weblate/settings_example.py
View file @
8536a0f9
...
...
@@ -269,7 +269,8 @@ LOGGING = {
# Apertium Web Service, register at http://api.apertium.org/register.jsp
MT_APERTIUM_KEY
=
None
# Microsoft Translator service, register at http://www.bing.com/developers/createapp.aspx
# Microsoft Translator service, register at
# http://www.bing.com/developers/createapp.aspx
MT_MICROSOFT_KEY
=
None
# Path where git repositories are stored, it needs to be writable
...
...
@@ -324,7 +325,7 @@ WHOOSH_INDEX = os.path.join(WEB_ROOT, 'whoosh-index')
# List of quality checks
CHECK_LIST
=
(
'weblate.trans.checks.same.SameCheck'
,
'weblate.trans.checks.same.SameCheck'
,
'weblate.trans.checks.chars.BeginNewlineCheck'
,
'weblate.trans.checks.chars.EndNewlineCheck'
,
'weblate.trans.checks.chars.BeginSpaceCheck'
,
...
...
weblate/trans/admin_views.py
View file @
8536a0f9
...
...
@@ -26,6 +26,7 @@ from django.contrib.admin.views.decorators import staff_member_required
from
django.utils.translation
import
ugettext
as
_
from
django.contrib
import
messages
from
django.conf
import
settings
from
weblate.trans
import
appsettings
import
weblate
import
os
...
...
@@ -75,7 +76,7 @@ def performance(request):
checks
.
append
((
# Translators: Indexing is postponed to cron job
_
(
'Indexing offloading'
),
settings
.
OFFLOAD_INDEXING
,
app
settings
.
OFFLOAD_INDEXING
,
'production-indexing'
,
))
# Check for sane caching
...
...
weblate/trans/api.py
View file @
8536a0f9
...
...
@@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from
django.conf
import
settings
from
weblate.trans
import
app
settings
from
django.views.decorators.csrf
import
csrf_exempt
from
django.http
import
(
HttpResponse
,
HttpResponseNotAllowed
,
HttpResponseBadRequest
...
...
@@ -40,7 +40,7 @@ def update_subproject(request, project, subproject):
'''
API hook for updating git repos.
'''
if
not
settings
.
ENABLE_HOOKS
:
if
not
app
settings
.
ENABLE_HOOKS
:
return
HttpResponseNotAllowed
([])
obj
=
get_object_or_404
(
SubProject
,
slug
=
subproject
,
project__slug
=
project
)
thread
=
threading
.
Thread
(
target
=
obj
.
do_update
)
...
...
@@ -53,7 +53,7 @@ def update_project(request, project):
'''
API hook for updating git repos.
'''
if
not
settings
.
ENABLE_HOOKS
:
if
not
app
settings
.
ENABLE_HOOKS
:
return
HttpResponseNotAllowed
([])
obj
=
get_object_or_404
(
Project
,
slug
=
project
)
thread
=
threading
.
Thread
(
target
=
obj
.
do_update
)
...
...
@@ -66,7 +66,7 @@ def github_hook(request):
'''
API to handle commit hooks from Github.
'''
if
not
settings
.
ENABLE_HOOKS
:
if
not
app
settings
.
ENABLE_HOOKS
:
return
HttpResponseNotAllowed
([])
if
request
.
method
!=
'POST'
:
return
HttpResponseNotAllowed
([
'POST'
])
...
...
weblate/trans/appsettings.py
0 → 100644
View file @
8536a0f9
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2013 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from
django.conf
import
settings
import
os
def
get
(
name
,
default
):
'''
Returns setting from django settings with default value.
'''
return
getattr
(
settings
,
name
,
default
)
# Weblate installation root
WEB_ROOT
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
# Machine translation API keys
# Apertium Web Service, register at http://api.apertium.org/register.jsp
MT_APERTIUM_KEY
=
get
(
'MT_APERTIUM_KEY'
,
None
)
# Microsoft Translator service, register at
# http://www.bing.com/developers/createapp.aspx
MT_MICROSOFT_KEY
=
get
(
'MT_MICROSOFT_KEY'
,
None
)
# Path where git repositories are stored, it needs to be writable
GIT_ROOT
=
get
(
'GIT_ROOT'
,
'%s/repos/'
%
WEB_ROOT
)
# Title of site to use
SITE_TITLE
=
get
(
'SITE_TITLE'
,
'Weblate'
)
# Enable remote hooks
ENABLE_HOOKS
=
get
(
'ENABLE_HOOKS'
,
True
)
# Number of nearby messages to show in each direction
NEARBY_MESSAGES
=
get
(
'NEARBY_MESSAGES'
,
5
)
# Minimal number of similar messages to show
SIMILAR_MESSAGES
=
get
(
'SIMILAR_MESSAGES'
,
5
)
# Enable lazy commits
LAZY_COMMITS
=
get
(
'LAZY_COMMITS'
,
True
)
# Offload indexing
OFFLOAD_INDEXING
=
get
(
'OFFLOAD_INDEXING'
,
False
)
# Translation locking
AUTO_LOCK
=
get
(
'AUTO_LOCK'
,
True
)
AUTO_LOCK_TIME
=
get
(
'AUTO_LOCK_TIME'
,
60
)
LOCK_TIME
=
get
(
'LOCK_TIME'
,
15
*
60
)
# Where to put Whoosh index
WHOOSH_INDEX
=
get
(
'WHOOSH_INDEX'
,
os
.
path
.
join
(
WEB_ROOT
,
'whoosh-index'
))
# List of quality checks
CHECK_LIST
=
(
'weblate.trans.checks.same.SameCheck'
,
'weblate.trans.checks.chars.BeginNewlineCheck'
,
'weblate.trans.checks.chars.EndNewlineCheck'
,
'weblate.trans.checks.chars.BeginSpaceCheck'
,
'weblate.trans.checks.chars.EndSpaceCheck'
,
'weblate.trans.checks.chars.EndStopCheck'
,
'weblate.trans.checks.chars.EndColonCheck'
,
'weblate.trans.checks.chars.EndQuestionCheck'
,
'weblate.trans.checks.chars.EndExclamationCheck'
,
'weblate.trans.checks.chars.EndEllipsisCheck'
,
'weblate.trans.checks.format.PythonFormatCheck'
,
'weblate.trans.checks.format.PHPFormatCheck'
,
'weblate.trans.checks.format.CFormatCheck'
,
'weblate.trans.checks.consistency.PluralsCheck'
,
'weblate.trans.checks.consistency.ConsistencyCheck'
,
'weblate.trans.checks.consistency.DirectionCheck'
,
'weblate.trans.checks.chars.NewlineCountingCheck'
,
'weblate.trans.checks.markup.BBCodeCheck'
,
'weblate.trans.checks.chars.ZeroWidthSpaceCheck'
,
'weblate.trans.checks.markup.XMLTagsCheck'
,
'weblate.trans.checks.source.OptionalPluralCheck'
,
'weblate.trans.checks.source.EllipsisCheck'
,
)
weblate/trans/context_processors.py
View file @
8536a0f9
...
...
@@ -20,6 +20,7 @@
import
weblate
from
django.conf
import
settings
from
weblate.trans
import
appsettings
from
datetime
import
datetime
URL_BASE
=
'http://weblate.org/?utm_source=weblate&utm_term=%s'
...
...
@@ -36,7 +37,7 @@ def weblate_url(request):
def
title
(
request
):
return
{
'site_title'
:
settings
.
SITE_TITLE
}
return
{
'site_title'
:
app
settings
.
SITE_TITLE
}
def
date
(
request
):
...
...
@@ -55,8 +56,8 @@ def url(request):
def
mt
(
request
):
return
{
'apertium_api_key'
:
settings
.
MT_APERTIUM_KEY
,
'microsoft_api_key'
:
settings
.
MT_MICROSOFT_KEY
,
'apertium_api_key'
:
app
settings
.
MT_APERTIUM_KEY
,
'microsoft_api_key'
:
app
settings
.
MT_MICROSOFT_KEY
,
}
...
...
weblate/trans/feeds.py
View file @
8536a0f9
...
...
@@ -21,7 +21,7 @@
from
django.contrib.syndication.views
import
Feed
from
django.utils.translation
import
ugettext
as
_
from
django.shortcuts
import
get_object_or_404
from
django.conf
import
settings
from
weblate.trans
import
app
settings
from
django.core.urlresolvers
import
reverse
from
weblate.trans.models
import
Change
,
Translation
,
SubProject
,
Project
...
...
@@ -31,10 +31,10 @@ from weblate.lang.models import Language
class
ChangesFeed
(
Feed
):
def
title
(
self
):
return
_
(
'Recent changes in %s'
)
%
settings
.
SITE_TITLE
return
_
(
'Recent changes in %s'
)
%
app
settings
.
SITE_TITLE
def
description
(
self
):
return
_
(
'All recent changes made using Weblate in %s.'
)
%
settings
.
SITE_TITLE
return
_
(
'All recent changes made using Weblate in %s.'
)
%
app
settings
.
SITE_TITLE
def
link
(
self
):
return
reverse
(
'home'
)
...
...
weblate/trans/managers.py
View file @
8536a0f9
...
...
@@ -19,7 +19,7 @@
#
from
django.db
import
models
from
django.conf
import
settings
from
weblate.trans
import
app
settings
from
django.core.cache
import
cache
from
django.db.models
import
Q
import
itertools
...
...
@@ -350,7 +350,7 @@ class UnitManager(models.Manager):
'''
Updates/Adds to all indices given unit.
'''
if
settings
.
OFFLOAD_INDEXING
:
if
app
settings
.
OFFLOAD_INDEXING
:
from
weblate.trans.models
import
IndexUpdate
IndexUpdate
.
objects
.
get_or_create
(
unit
=
unit
,
source
=
source
)
return
...
...
@@ -388,7 +388,7 @@ class UnitManager(models.Manager):
'''
ret
=
set
()
if
source
or
context
:
with
FULLTEXT_INDEX
.
source_searcher
(
not
settings
.
OFFLOAD_INDEXING
)
as
searcher
:
with
FULLTEXT_INDEX
.
source_searcher
(
not
app
settings
.
OFFLOAD_INDEXING
)
as
searcher
:
if
source
:
results
=
self
.
__search
(
searcher
,
...
...
@@ -408,7 +408,7 @@ class UnitManager(models.Manager):
if
translation
:
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
app
settings
.
OFFLOAD_INDEXING
)
as
searcher
:
results
=
self
.
__search
(
searcher
,
'target'
,
...
...
@@ -427,12 +427,12 @@ class UnitManager(models.Manager):
Finds similar units to current unit.
'''
ret
=
set
([
unit
.
checksum
])
with
FULLTEXT_INDEX
.
source_searcher
(
not
settings
.
OFFLOAD_INDEXING
)
as
searcher
:
with
FULLTEXT_INDEX
.
source_searcher
(
not
app
settings
.
OFFLOAD_INDEXING
)
as
searcher
:
# Extract up to 10 terms from the source
terms
=
[
kw
for
kw
,
score
in
searcher
.
key_terms_from_text
(
'source'
,
unit
.
source
,
numterms
=
10
)
if
not
kw
in
IGNORE_SIMILAR
]
cnt
=
len
(
terms
)
# 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
)
<
app
settings
.
SIMILAR_MESSAGES
and
cnt
>
0
and
len
(
terms
)
-
cnt
<
4
:
for
search
in
itertools
.
combinations
(
terms
,
cnt
):
results
=
self
.
search
(
' '
.
join
(
search
),
...
...
weblate/trans/models.py
View file @
8536a0f9
...
...
@@ -20,7 +20,7 @@
from
django.db
import
models
from
django.contrib.auth.models
import
User
from
django.conf
import
settings
from
weblate.trans
import
app
settings
from
django.db.models
import
Sum
,
Q
from
django.utils.translation
import
ugettext
as
_
,
ugettext_lazy
from
django.utils.safestring
import
mark_safe
...
...
@@ -263,7 +263,7 @@ class Project(models.Model):
})
def
get_path
(
self
):
return
os
.
path
.
join
(
settings
.
GIT_ROOT
,
self
.
slug
)
return
os
.
path
.
join
(
app
settings
.
GIT_ROOT
,
self
.
slug
)
def
__unicode__
(
self
):
return
self
.
name
...
...
@@ -1438,9 +1438,9 @@ class Translation(models.Model):
Sets lock timestamp.
'''
if
explicit
:
seconds
=
settings
.
LOCK_TIME
seconds
=
app
settings
.
LOCK_TIME
else
:
seconds
=
settings
.
AUTO_LOCK_TIME
seconds
=
app
settings
.
AUTO_LOCK_TIME
new_lock_time
=
datetime
.
now
()
+
timedelta
(
seconds
=
seconds
)
...
...
@@ -1459,7 +1459,7 @@ class Translation(models.Model):
return
# Auto lock if we should
if
settings
.
AUTO_LOCK
:
if
app
settings
.
AUTO_LOCK
:
self
.
create_lock
(
request
.
user
)
return
...
...
@@ -1949,7 +1949,7 @@ class Translation(models.Model):
return
False
# Can we delay commit?
if
not
force_commit
and
settings
.
LAZY_COMMITS
:
if
not
force_commit
and
app
settings
.
LAZY_COMMITS
:
logger
.
info
(
'Delaying commiting %s in %s as %s'
,
self
.
filename
,
...
...
@@ -2807,8 +2807,8 @@ class Unit(models.Model):
'''
return
Unit
.
objects
.
filter
(
translation
=
self
.
translation
,
position__gte
=
self
.
position
-
settings
.
NEARBY_MESSAGES
,
position__lte
=
self
.
position
+
settings
.
NEARBY_MESSAGES
,
position__gte
=
self
.
position
-
app
settings
.
NEARBY_MESSAGES
,
position__lte
=
self
.
position
+
app
settings
.
NEARBY_MESSAGES
,
)
...
...
weblate/trans/search.py
View file @
8536a0f9
...
...
@@ -26,7 +26,7 @@ import whoosh
import
os
from
whoosh.fields
import
Schema
,
TEXT
,
ID
from
django.db.models.signals
import
post_syncdb
from
django.conf
import
settings
from
weblate.trans
import
app
settings
from
whoosh.index
import
create_in
,
open_dir
from
whoosh.writing
import
BufferedWriter
...
...
@@ -44,7 +44,7 @@ SOURCE_SCHEMA = Schema(
def
create_source_index
():
return
create_in
(
settings
.
WHOOSH_INDEX
,
app
settings
.
WHOOSH_INDEX
,
schema
=
SOURCE_SCHEMA
,
indexname
=
'source'
)
...
...
@@ -52,15 +52,15 @@ def create_source_index():
def
create_target_index
(
lang
):
return
create_in
(
settings
.
WHOOSH_INDEX
,
app
settings
.
WHOOSH_INDEX
,
schema
=
TARGET_SCHEMA
,
indexname
=
'target-%s'
%
lang
)
def
create_index
(
sender
=
None
,
**
kwargs
):
if
not
os
.
path
.
exists
(
settings
.
WHOOSH_INDEX
):
os
.
mkdir
(
settings
.
WHOOSH_INDEX
)
if
not
os
.
path
.
exists
(
app
settings
.
WHOOSH_INDEX
):
os
.
mkdir
(
app
settings
.
WHOOSH_INDEX
)
create_source_index
()
post_syncdb
.
connect
(
create_index
)
...
...
@@ -83,7 +83,7 @@ class Index(object):
if
self
.
_source
is
None
:
try
:
self
.
_source
=
open_dir
(
settings
.
WHOOSH_INDEX
,
app
settings
.
WHOOSH_INDEX
,
indexname
=
'source'
)
except
whoosh
.
index
.
EmptyIndexError
:
...
...
@@ -100,7 +100,7 @@ class Index(object):
if
not
lang
in
self
.
_target
:
try
:
self
.
_target
[
lang
]
=
open_dir
(
settings
.
WHOOSH_INDEX
,
app
settings
.
WHOOSH_INDEX
,
indexname
=
'target-%s'
%
lang
)
except
whoosh
.
index
.
EmptyIndexError
:
...
...
weblate/trans/templatetags/translations.py
View file @
8536a0f9
...
...
@@ -27,7 +27,7 @@ from django.utils.translation import ugettext as _, ungettext
from
django.utils.formats
import
date_format
from
django.utils
import
timezone
from
django
import
template
from
django.conf
import
settings
from
weblate.trans
import
app
settings
import
re
...
...
@@ -153,7 +153,7 @@ def site_title(value):
'''
Returns site title
'''
return
settings
.
SITE_TITLE
return
app
settings
.
SITE_TITLE
@
register
.
simple_tag
...
...
weblate/trans/views.py
View file @
8536a0f9
...
...
@@ -20,7 +20,7 @@
from
django.shortcuts
import
render_to_response
,
get_object_or_404
from
django.views.decorators.cache
import
cache_page
from
django.conf
import
settings
from
weblate.trans
import
app
settings
from
django.core.servers.basehttp
import
FileWrapper
from
django.utils.translation
import
ugettext
as
_
import
django.utils.translation
...
...
@@ -1927,9 +1927,9 @@ def js_config(request):
support.
'''
# Apertium support
if
settings
.
MT_APERTIUM_KEY
is
not
None
and
settings
.
MT_APERTIUM_KEY
!=
''
:
if
appsettings
.
MT_APERTIUM_KEY
is
not
None
and
app
settings
.
MT_APERTIUM_KEY
!=
''
:
try
:
listpairs
=
urllib2
.
urlopen
(
'http://api.apertium.org/json/listPairs?key=%s'
%
settings
.
MT_APERTIUM_KEY
)
listpairs
=
urllib2
.
urlopen
(
'http://api.apertium.org/json/listPairs?key=%s'
%
app
settings
.
MT_APERTIUM_KEY
)
pairs
=
listpairs
.
read
()
parsed
=
json
.
loads
(
pairs
)
apertium_langs
=
[
p
[
'targetLanguage'
]
for
p
in
parsed
[
'responseData'
]
if
p
[
'sourceLanguage'
]
==
'en'
]
...
...
@@ -1940,9 +1940,9 @@ def js_config(request):
apertium_langs
=
None
# Microsoft translator support
if
settings
.
MT_MICROSOFT_KEY
is
not
None
and
settings
.
MT_MICROSOFT_KEY
!=
''
:
if
appsettings
.
MT_MICROSOFT_KEY
is
not
None
and
app
settings
.
MT_MICROSOFT_KEY
!=
''
:
try
:
listpairs
=
urllib2
.
urlopen
(
'http://api.microsofttranslator.com/V2/Http.svc/GetLanguagesForTranslate?appID=%s'
%
settings
.
MT_MICROSOFT_KEY
)
listpairs
=
urllib2
.
urlopen
(
'http://api.microsofttranslator.com/V2/Http.svc/GetLanguagesForTranslate?appID=%s'
%
app
settings
.
MT_MICROSOFT_KEY
)
data
=
listpairs
.
read
()
parsed
=
ElementTree
.
fromstring
(
data
)
microsoft_langs
=
[
p
.
text
for
p
in
parsed
.
getchildren
()]
...
...
weblate/trans/widgets.py
View file @
8536a0f9
...
...
@@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from
django.conf
import
settings
from
weblate.trans
import
app
settings
from
django.http
import
HttpResponse
,
Http404
from
django.template
import
RequestContext
from
django.shortcuts
import
render_to_response
,
get_object_or_404
...
...
@@ -258,7 +258,7 @@ def render(request, project, widget='287x66', color=None, lang=None):
# Background 287 x 66, logo 64 px
surface
=
cairo
.
ImageSurface
.
create_from_png
(
os
.
path
.
join
(
settings
.
WEB_ROOT
,
'media'
,
widget_data
[
'name'
]
%
{
os
.
path
.
join
(
app
settings
.
WEB_ROOT
,
'media'
,
widget_data
[
'name'
]
%
{
'color'
:
color
,
'widget'
:
widget
,
})
...
...
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