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
3a0d1f58
Commit
3a0d1f58
authored
Apr 03, 2012
by
Michal Čihař
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
f7a541a4
6214f9a3
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
106 additions
and
83 deletions
+106
-83
accounts/i18n.py
accounts/i18n.py
+3
-0
accounts/management/commands/setupgroups.py
accounts/management/commands/setupgroups.py
+1
-2
accounts/models.py
accounts/models.py
+1
-2
docs/conf.py
docs/conf.py
+1
-1
lang/i18n.py
lang/i18n.py
+3
-0
lang/management/commands/setuplang.py
lang/management/commands/setuplang.py
+1
-1
trans/api.py
trans/api.py
+2
-2
trans/context_processors.py
trans/context_processors.py
+1
-1
trans/management/commands/__init__.py
trans/management/commands/__init__.py
+1
-1
trans/management/commands/checkgit.py
trans/management/commands/checkgit.py
+1
-1
trans/management/commands/cleanuptrans.py
trans/management/commands/cleanuptrans.py
+1
-2
trans/management/commands/commitgit.py
trans/management/commands/commitgit.py
+1
-1
trans/management/commands/loadpo.py
trans/management/commands/loadpo.py
+1
-1
trans/management/commands/rebuild_index.py
trans/management/commands/rebuild_index.py
+2
-3
trans/management/commands/updatechecks.py
trans/management/commands/updatechecks.py
+0
-1
trans/management/commands/updategit.py
trans/management/commands/updategit.py
+1
-1
trans/managers.py
trans/managers.py
+9
-9
trans/models.py
trans/models.py
+4
-8
trans/search.py
trans/search.py
+69
-43
trans/views.py
trans/views.py
+3
-3
No files found.
accounts/i18n.py
View file @
3a0d1f58
...
...
@@ -2,6 +2,9 @@
Fake file to translate messages from django-registration and django.contrib.auth.
'''
def
_
(
s
):
return
s
def
fake
():
_
(
u'This username is already taken. Please choose another.'
)
_
(
u'You must type the same password each time'
)
...
...
accounts/management/commands/setupgroups.py
View file @
3a0d1f58
from
django.core.management.base
import
BaseCommand
,
CommandError
from
trans.models
import
SubProject
from
django.core.management.base
import
BaseCommand
from
optparse
import
make_option
from
django.contrib.auth.models
import
Group
,
Permission
,
User
...
...
accounts/models.py
View file @
3a0d1f58
...
...
@@ -6,7 +6,6 @@ from django.contrib.auth.signals import user_logged_in
from
django.db.models.signals
import
post_save
from
django.utils.translation
import
ugettext_lazy
as
_
,
gettext
from
django.contrib
import
messages
from
django.utils.safestring
import
mark_safe
from
django.contrib.auth.models
import
Group
from
lang.models
import
Language
...
...
@@ -42,7 +41,7 @@ def set_lang(sender, **kwargs):
user
=
kwargs
[
'user'
]
try
:
profile
=
user
.
get_profile
()
except
Profile
.
DoesNotExist
,
e
:
except
Profile
.
DoesNotExist
:
profile
,
newprofile
=
Profile
.
objects
.
get_or_create
(
user
=
user
)
if
newprofile
:
messages
.
info
(
request
,
gettext
(
'Your profile has been migrated, you might want to adjust preferences.'
))
...
...
docs/conf.py
View file @
3a0d1f58
...
...
@@ -11,7 +11,7 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
import
sys
,
os
#
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
...
...
lang/i18n.py
View file @
3a0d1f58
...
...
@@ -6,6 +6,9 @@ Generated using:
./manage.py dumpdata --format=yaml lang | grep fields:| sed 's/.*name: / _("/; s/, nplu.*/")/'
'''
def
_
(
s
):
return
s
def
fake
():
_
(
"Afrikaans"
)
_
(
"Akan"
)
...
...
lang/management/commands/setuplang.py
View file @
3a0d1f58
# -*- coding: UTF-8 -*-
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
from
lang.models
import
Language
from
translate.lang
import
data
...
...
trans/api.py
View file @
3a0d1f58
from
django.conf
import
settings
from
django.views.decorators.csrf
import
csrf_exempt
from
django.http
import
HttpResponse
,
HttpResponse
Redirect
,
HttpResponseNotAllowed
,
HttpResponseNotFoun
d
,
HttpResponseBadRequest
from
trans.models
import
Project
,
SubProject
,
Translation
,
Unit
,
Suggestion
,
Check
from
django.http
import
HttpResponse
,
HttpResponse
NotAllowe
d
,
HttpResponseBadRequest
from
trans.models
import
Project
,
SubProject
from
django.shortcuts
import
get_object_or_404
import
json
...
...
trans/context_processors.py
View file @
3a0d1f58
import
trans
from
django.conf
import
settings
from
datetime
import
datetime
,
date
from
datetime
import
datetime
def
version
(
request
):
return
{
'version'
:
trans
.
VERSION
}
...
...
trans/management/commands/__init__.py
View file @
3a0d1f58
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
from
optparse
import
make_option
from
trans.models
import
Unit
...
...
trans/management/commands/checkgit.py
View file @
3a0d1f58
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
from
trans.models
import
SubProject
from
optparse
import
make_option
...
...
trans/management/commands/cleanuptrans.py
View file @
3a0d1f58
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
from
trans.models
import
Suggestion
,
Check
,
Unit
,
Project
from
lang.models
import
Language
from
optparse
import
make_option
class
Command
(
BaseCommand
):
help
=
'clenups orphaned checks and suggestions'
...
...
trans/management/commands/commitgit.py
View file @
3a0d1f58
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
from
trans.models
import
SubProject
from
optparse
import
make_option
...
...
trans/management/commands/loadpo.py
View file @
3a0d1f58
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
from
trans.models
import
SubProject
from
optparse
import
make_option
...
...
trans/management/commands/rebuild_index.py
View file @
3a0d1f58
...
...
@@ -3,7 +3,6 @@ from trans.models import Unit
from
lang.models
import
Language
import
trans.search
from
optparse
import
make_option
from
django.db.models
import
Q
class
Command
(
UnitCommand
):
help
=
'updates index for fulltext search'
...
...
@@ -27,7 +26,7 @@ class Command(UnitCommand):
if
base
.
count
()
==
0
:
return
with
trans
.
search
.
get_
source_writer
(
buffered
=
False
)
as
writer
:
with
trans
.
search
.
index
.
source_writer
(
buffered
=
False
)
as
writer
:
for
unit
in
base
.
values
(
'checksum'
,
'source'
,
'context'
,
'translation_id'
).
iterator
():
Unit
.
objects
.
add_to_source_index
(
unit
[
'checksum'
],
...
...
@@ -37,7 +36,7 @@ class Command(UnitCommand):
writer
)
for
lang
in
languages
:
with
trans
.
search
.
get_
target_writer
(
lang
=
lang
.
code
,
buffered
=
False
)
as
writer
:
with
trans
.
search
.
index
.
target_writer
(
lang
=
lang
.
code
,
buffered
=
False
)
as
writer
:
for
unit
in
base
.
filter
(
translation__language
=
lang
).
exclude
(
target
=
''
).
values
(
'checksum'
,
'target'
,
'translation_id'
).
iterator
():
Unit
.
objects
.
add_to_target_index
(
...
...
trans/management/commands/updatechecks.py
View file @
3a0d1f58
from
trans.management.commands
import
UnitCommand
from
optparse
import
make_option
class
Command
(
UnitCommand
):
help
=
'updates checks for units'
...
...
trans/management/commands/updategit.py
View file @
3a0d1f58
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
from
trans.models
import
SubProject
,
Project
from
optparse
import
make_option
...
...
trans/managers.py
View file @
3a0d1f58
from
django.db
import
models
,
connection
from
django.db
import
models
from
django.conf
import
settings
import
itertools
...
...
@@ -6,7 +6,7 @@ from lang.models import Language
from
whoosh
import
qparser
from
util
import
is_plural
,
split_plural
,
join_plural
,
msg_checksum
from
util
import
join_plural
,
msg_checksum
import
trans.search
from
translate.storage
import
factory
...
...
@@ -74,11 +74,11 @@ class TranslationManager(models.Manager):
Parses translation meta info and creates/updates translation object.
'''
lang
=
Language
.
objects
.
get
(
code
=
code
)
trans
,
created
=
self
.
get_or_create
(
trans
lation
,
created
=
self
.
get_or_create
(
language
=
lang
,
subproject
=
subproject
,
filename
=
path
)
trans
.
update_from_blob
(
blob_hash
,
force
)
trans
lation
.
update_from_blob
(
blob_hash
,
force
)
class
UnitManager
(
models
.
Manager
):
def
update_from_unit
(
self
,
translation
,
unit
,
pos
):
...
...
@@ -182,9 +182,9 @@ class UnitManager(models.Manager):
Updates/Adds to all indices given unit.
'''
if
writer_target
is
None
:
writer_target
=
trans
.
search
.
get_
target_writer
(
unit
.
translation
.
language
.
code
)
writer_target
=
trans
.
search
.
index
.
target_writer
(
unit
.
translation
.
language
.
code
)
if
writer_source
is
None
:
writer_source
=
trans
.
search
.
get_
source_writer
()
writer_source
=
trans
.
search
.
index
.
source_writer
()
self
.
add_to_source_index
(
unit
.
checksum
,
...
...
@@ -215,7 +215,7 @@ class UnitManager(models.Manager):
'''
ret
=
set
()
if
source
or
context
:
with
trans
.
search
.
get_
source_searcher
()
as
searcher
:
with
trans
.
search
.
index
.
source_searcher
()
as
searcher
:
if
source
:
ret
=
ret
.
union
(
self
.
__search
(
searcher
,
'source'
,
trans
.
search
.
SourceSchema
(),
query
))
if
context
:
...
...
@@ -223,7 +223,7 @@ class UnitManager(models.Manager):
if
translation
:
sample
=
self
.
all
()[
0
]
with
trans
.
search
.
get_
target_searcher
(
sample
.
translation
.
language
.
code
)
as
searcher
:
with
trans
.
search
.
index
.
target_searcher
(
sample
.
translation
.
language
.
code
)
as
searcher
:
ret
=
ret
.
union
(
self
.
__search
(
searcher
,
'target'
,
trans
.
search
.
TargetSchema
(),
query
))
if
checksums
:
...
...
@@ -236,7 +236,7 @@ class UnitManager(models.Manager):
Finds similar units to current unit.
'''
ret
=
set
([
unit
.
checksum
])
with
trans
.
search
.
get_
source_searcher
()
as
searcher
:
with
trans
.
search
.
index
.
source_searcher
()
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
)
...
...
trans/models.py
View file @
3a0d1f58
from
django.db
import
models
from
django.db.models
import
Q
from
django.contrib.auth.models
import
User
from
django.conf
import
settings
from
lang.models
import
Language
from
django.db.models
import
Sum
from
django.utils.translation
import
ugettext
_lazy
,
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
from
django.utils.safestring
import
mark_safe
from
django.core.mail
import
mail_admins
from
django.core.exceptions
import
ValidationError
...
...
@@ -30,7 +29,7 @@ logger = logging.getLogger('weblate')
def
validate_repoweb
(
val
):
try
:
test
=
val
%
{
'file'
:
'file.po'
,
'line'
:
'9'
}
val
%
{
'file'
:
'file.po'
,
'line'
:
'9'
}
except
Exception
,
e
:
raise
ValidationError
(
_
(
'Bad format string (%s)'
)
%
str
(
e
))
...
...
@@ -248,11 +247,8 @@ class SubProject(models.Model):
Ensures local tracking branch exists and is checkouted.
'''
gitrepo
=
self
.
get_repo
()
try
:
head
=
gitrepo
.
heads
[
self
.
branch
]
except
:
if
not
self
.
branch
in
gitrepo
.
heads
:
gitrepo
.
git
.
branch
(
'--track'
,
self
.
branch
,
'origin/%s'
%
self
.
branch
)
head
=
gitrepo
.
heads
[
self
.
branch
]
gitrepo
.
git
.
checkout
(
self
.
branch
)
del
gitrepo
...
...
@@ -545,7 +541,7 @@ class Translation(models.Model):
units
=
Unit
.
objects
.
filter
(
translation__language
=
self
.
language
,
translation__subproject__project
=
self
.
subproject
.
project
,
checksum
=
checksum
)
if
units
.
count
()
==
0
:
# Last unit referencing to these checks
Check
s
.
objects
.
filter
(
project
=
self
.
subproject
.
project
,
language
=
self
.
language
,
checksum
=
checksum
).
delete
()
Check
.
objects
.
filter
(
project
=
self
.
subproject
.
project
,
language
=
self
.
language
,
checksum
=
checksum
).
delete
()
else
:
# There are other units as well, but some checks (eg. consistency) needs update now
for
unit
in
units
:
...
...
trans/search.py
View file @
3a0d1f58
...
...
@@ -7,7 +7,7 @@ import os
from
whoosh.fields
import
SchemaClass
,
TEXT
,
ID
,
NUMERIC
from
django.db.models.signals
import
post_syncdb
from
django.conf
import
settings
from
whoosh
import
index
from
whoosh
.index
import
create_in
,
open_dir
from
whoosh.writing
import
BufferedWriter
class
TargetSchema
(
SchemaClass
):
...
...
@@ -22,14 +22,14 @@ class SourceSchema(SchemaClass):
translation
=
NUMERIC
def
create_source_index
():
return
index
.
create_in
(
return
create_in
(
settings
.
WHOOSH_INDEX
,
schema
=
SourceSchema
,
indexname
=
'source'
)
def
create_target_index
(
lang
):
return
index
.
create_in
(
return
create_in
(
settings
.
WHOOSH_INDEX
,
schema
=
TargetSchema
,
indexname
=
'target-%s'
%
lang
...
...
@@ -42,45 +42,71 @@ def create_index(sender=None, **kwargs):
post_syncdb
.
connect
(
create_index
)
def
get_source_index
():
if
not
hasattr
(
get_source_index
,
'ix_source'
):
get_source_index
.
ix_source
=
index
.
open_dir
(
settings
.
WHOOSH_INDEX
,
indexname
=
'source'
)
return
get_source_index
.
ix_source
def
get_target_index
(
lang
):
if
not
hasattr
(
get_target_index
,
'ix_target'
):
get_target_index
.
ix_target
=
{}
if
not
lang
in
get_target_index
.
ix_target
:
try
:
get_target_index
.
ix_target
[
lang
]
=
index
.
open_dir
(
class
Index
(
object
):
'''
Class to manage index readers and writers.
'''
_source
=
None
_target
=
{}
_source_writer
=
None
_target_writer
=
{}
def
source
(
self
):
'''
Returns source index.
'''
if
self
.
_source
is
None
:
self
.
_source
=
open_dir
(
settings
.
WHOOSH_INDEX
,
indexname
=
'
target-%s'
%
lang
indexname
=
'
source'
)
except
whoosh
.
index
.
EmptyIndexError
:
get_target_index
.
ix_target
[
lang
]
=
create_target_index
(
lang
)
return
get_target_index
.
ix_target
[
lang
]
def
get_source_writer
(
buffered
=
True
):
if
not
buffered
:
return
get_source_index
().
writer
()
if
not
hasattr
(
get_source_writer
,
'source_writer'
):
get_source_writer
.
source_writer
=
BufferedWriter
(
get_source_index
())
return
get_source_writer
.
source_writer
def
get_target_writer
(
lang
,
buffered
=
True
):
if
not
buffered
:
return
get_target_index
(
lang
).
writer
()
if
not
hasattr
(
get_target_writer
,
'target_writer'
):
get_target_writer
.
target_writer
=
{}
if
not
lang
in
get_target_writer
.
target_writer
:
get_target_writer
.
target_writer
[
lang
]
=
BufferedWriter
(
get_target_index
(
lang
))
return
get_target_writer
.
target_writer
[
lang
]
def
get_source_searcher
():
return
get_source_writer
().
searcher
()
def
get_target_searcher
(
lang
):
return
get_target_writer
(
lang
).
searcher
()
return
self
.
_source
def
target
(
self
,
lang
):
'''
Returns target index for given language.
'''
if
not
lang
in
self
.
_target
:
try
:
self
.
_target
[
lang
]
=
open_dir
(
settings
.
WHOOSH_INDEX
,
indexname
=
'target-%s'
%
lang
)
except
whoosh
.
index
.
EmptyIndexError
:
self
.
_target
[
lang
]
=
create_target_index
(
lang
)
return
self
.
_target
[
lang
]
def
source_writer
(
self
,
buffered
=
True
):
'''
Returns source index writer (by default buffered).
'''
if
not
buffered
:
return
self
.
source
().
writer
()
if
self
.
_source_writer
is
None
:
self
.
_source_writer
=
BufferedWriter
(
self
.
source
())
return
self
.
_source_writer
def
target_writer
(
self
,
lang
,
buffered
=
True
):
'''
Returns target index writer (by default buffered) for given language.
'''
if
not
buffered
:
return
self
.
target
(
lang
).
writer
()
if
not
lang
in
self
.
_target_writer
:
self
.
_target_writer
[
lang
]
=
BufferedWriter
(
self
.
target
(
lang
))
return
self
.
_target_writer
[
lang
]
def
source_searcher
(
self
):
'''
Returns source index searcher (on buffered writer).
'''
return
self
.
source_writer
().
searcher
()
def
target_searcher
(
self
,
lang
):
'''
Returns target index searcher (on buffered writer) for given language.
'''
return
self
.
target_writer
(
lang
).
searcher
()
index
=
Index
()
trans/views.py
View file @
3a0d1f58
...
...
@@ -2,9 +2,9 @@ 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
django.core.servers.basehttp
import
FileWrapper
from
django.utils.translation
import
ugettext
_lazy
,
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
from
django.template
import
RequestContext
,
loader
from
django.http
import
HttpResponse
,
HttpResponseRedirect
,
HttpResponseNot
Allowed
,
HttpResponseNot
Found
,
Http404
from
django.http
import
HttpResponse
,
HttpResponseRedirect
,
HttpResponseNotFound
,
Http404
from
django.contrib
import
messages
from
django.contrib.auth.decorators
import
login_required
,
permission_required
,
user_passes_test
from
django.contrib.auth.models
import
AnonymousUser
...
...
@@ -15,7 +15,7 @@ from django.core.urlresolvers import reverse
from
trans.models
import
Project
,
SubProject
,
Translation
,
Unit
,
Suggestion
,
Check
,
Dictionary
,
Change
from
lang.models
import
Language
from
trans.forms
import
TranslationForm
,
UploadForm
,
SimpleUploadForm
,
ExtraUploadForm
,
SearchForm
,
MergeForm
,
AutoForm
,
WordForm
,
DictUploadForm
,
ReviewForm
from
util
import
is_plural
,
split_plural
,
join_plural
from
util
import
join_plural
from
accounts.models
import
Profile
from
whoosh.analysis
import
StandardAnalyzer
,
StemmingAnalyzer
import
datetime
...
...
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