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
72fd20fb
Commit
72fd20fb
authored
Mar 30, 2014
by
Vladimir Rusinov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some PEP8 errors and typos.
parent
64ae77a5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
78 deletions
+77
-78
weblate/accounts/forms.py
weblate/accounts/forms.py
+4
-4
weblate/trans/mixins.py
weblate/trans/mixins.py
+30
-30
weblate/trans/models/project.py
weblate/trans/models/project.py
+43
-43
weblate/trans/tests/test_models.py
weblate/trans/tests/test_models.py
+0
-1
No files found.
weblate/accounts/forms.py
View file @
72fd20fb
...
...
@@ -40,18 +40,18 @@ except ImportError:
def
remove_accents
(
input_str
):
'''
"""
Removes accents from a string.
'''
"""
nkfd_form
=
unicodedata
.
normalize
(
'NFKD'
,
unicode
(
input_str
))
only_ascii
=
nkfd_form
.
encode
(
'ASCII'
,
'ignore'
)
return
only_ascii
class
NoStripEmailField
(
forms
.
EmailField
):
'''
"""
Email field which does no stripping.
'''
"""
def
clean
(
self
,
value
):
value
=
self
.
to_python
(
value
)
# We call super-super method to skip default EmailField behavior
...
...
weblate/trans/mixins.py
View file @
72fd20fb
...
...
@@ -28,65 +28,65 @@ logger = logging.getLogger(__name__)
class
PercentMixin
(
object
):
'''
"""
Defines API to getting percentage status of translations.
'''
"""
_percents
=
None
def
get_percents
(
self
):
'''
"""
Returns percentages of translation status.
'''
"""
if
self
.
_percents
is
None
:
self
.
_percents
=
self
.
_get_percents
()
return
self
.
_percents
def
_get_percents
(
self
):
'''
"""
Returns percentages of translation status.
'''
"""
raise
NotImplementedError
()
def
get_translated_percent
(
self
):
'''
"""
Returns percent of translated strings.
'''
"""
return
self
.
get_percents
()[
0
]
def
get_fuzzy_percent
(
self
):
'''
"""
Returns percent of fuzzy strings.
'''
"""
return
self
.
get_percents
()[
1
]
def
get_failing_checks_percent
(
self
):
'''
"""
Returns percentage of failed checks.
'''
"""
return
self
.
get_percents
()[
2
]
class
URLMixin
(
object
):
'''
"""
Mixin providing standard shortcut API for few standard URLs
'''
"""
def
_reverse_url_name
(
self
):
'''
"""
Returns base name for URL reversing.
'''
"""
raise
NotImplementedError
()
def
_reverse_url_kwargs
(
self
):
'''
"""
Returns kwargs for URL reversing.
'''
"""
raise
NotImplementedError
()
def
reverse_url
(
self
,
name
=
None
):
'''
"""
Generic reverser for URL.
'''
"""
if
name
is
None
:
urlname
=
self
.
_reverse_url_name
()
else
:
...
...
@@ -122,33 +122,33 @@ class URLMixin(object):
class
PathMixin
(
object
):
'''
"""
Mixin for path manipulations.
'''
"""
_dir_path
=
None
def
_get_path
(
self
):
'''
"""
Actual calculation of path.
'''
"""
raise
NotImplementedError
()
def
get_path
(
self
):
'''
"""
Return path to directory.
Caching is really necessary for linked project, otherwise
we end up fetching linked subproject again and again.
'''
"""
if
self
.
_dir_path
is
None
:
self
.
_dir_path
=
self
.
_get_path
()
return
self
.
_dir_path
def
check_rename
(
self
,
old
):
'''
"""
Detects slug changes and possibly renames underlaying directory.
'''
"""
logger
.
debug
(
'check_rename: old slug is "%s", new is "%s"'
,
old
.
slug
,
self
.
slug
)
if
old
.
slug
!=
self
.
slug
:
...
...
@@ -162,9 +162,9 @@ class PathMixin(object):
os
.
rename
(
old_path
,
new_path
)
def
create_path
(
self
):
'''
"""
Create filesystem directory for storing data
'''
"""
path
=
self
.
get_path
()
if
not
os
.
path
.
exists
(
path
):
os
.
makedirs
(
path
)
weblate/trans/models/project.py
View file @
72fd20fb
...
...
@@ -54,16 +54,16 @@ MERGE_CHOICES = (
class
ProjectManager
(
models
.
Manager
):
def
all_acl
(
self
,
user
):
'''
"""
Returns list of projects user is allowed to access.
'''
"""
return
self
.
get_acl_status
(
user
)[
0
]
def
get_acl_status
(
self
,
user
):
'''
"""
Returns list of projects user is allowed to access
and flag whether there is any filtering active.
'''
"""
projects
=
self
.
all
()
project_ids
=
[
project
.
id
for
project
in
projects
if
project
.
has_acl
(
user
)
...
...
@@ -187,16 +187,16 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
app_label
=
'trans'
def
__init__
(
self
,
*
args
,
**
kwargs
):
'''
"""
Constructor to initialize some cache properties.
'''
"""
super
(
Project
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
has_acl
(
self
,
user
):
'''
"""
Checks whether current user is allowed to access this
project.
'''
"""
if
not
self
.
enable_acl
:
return
True
...
...
@@ -206,9 +206,9 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
return
user
.
has_perm
(
'trans.weblate_acl_%s'
%
self
.
slug
)
def
check_acl
(
self
,
request
):
'''
"""
Raises an error if user is not allowed to access this project.
'''
"""
if
not
self
.
has_acl
(
request
.
user
):
messages
.
error
(
request
,
...
...
@@ -235,31 +235,31 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
)
def
_reverse_url_name
(
self
):
'''
"""
Returns base name for URL reversing.
'''
"""
return
'project'
def
_reverse_url_kwargs
(
self
):
'''
"""
Returns kwargs for URL reversing.
'''
"""
return
{
'project'
:
self
.
slug
}
def
get_widgets_url
(
self
):
'''
"""
Returns absolute URL for widgets.
'''
"""
return
get_site_url
(
reverse
(
'widgets'
,
kwargs
=
{
'project'
:
self
.
slug
})
)
def
get_share_url
(
self
):
'''
"""
Returns absolute URL usable for sharing.
'''
"""
return
get_site_url
(
reverse
(
'engage'
,
kwargs
=
{
'project'
:
self
.
slug
})
)
...
...
@@ -316,31 +316,31 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
# pylint: disable=W0221
def
_get_percents
(
self
,
lang
=
None
):
'''
"""
Returns percentages of translation status.
'''
"""
# Import translations
from
weblate.trans.models.translation
import
Translation
# Get p
rercents
# Get p
ercents:
return
Translation
.
objects
.
get_percents
(
project
=
self
,
language
=
lang
)
# Arguments number differs from overridden method
# pylint: disable=W0221
def
get_translated_percent
(
self
,
lang
=
None
):
'''
"""
Returns percent of translated strings.
'''
"""
if
lang
is
None
:
return
super
(
Project
,
self
).
get_translated_percent
()
return
self
.
_get_percents
(
lang
)[
0
]
def
get_total
(
self
):
'''
"""
Calculates total number of strings to translate. This is done based on
assumption that all languages have same number of strings.
'''
"""
from
weblate.trans.models.translation
import
Translation
total
=
0
for
resource
in
self
.
subproject_set
.
all
():
...
...
@@ -351,23 +351,23 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
return
total
def
get_languages
(
self
):
'''
"""
Returns list of all languages used in project.
'''
"""
return
Language
.
objects
.
filter
(
translation__subproject__project
=
self
).
distinct
()
def
get_language_count
(
self
):
'''
"""
Returns number of languages used in this project.
'''
"""
return
self
.
get_languages
().
count
()
def
git_needs_commit
(
self
):
'''
"""
Checks whether there are some not committed changes.
'''
"""
for
resource
in
self
.
subproject_set
.
all
():
if
resource
.
git_needs_commit
():
return
True
...
...
@@ -386,52 +386,52 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
return
False
def
commit_pending
(
self
,
request
):
'''
"""
Commits any pending changes.
'''
"""
for
resource
in
self
.
subproject_set
.
all
():
resource
.
commit_pending
(
request
)
def
do_update
(
self
,
request
=
None
):
'''
"""
Updates all git repos.
'''
"""
ret
=
False
for
resource
in
self
.
subproject_set
.
all
():
ret
&=
resource
.
do_update
(
request
)
return
ret
def
do_push
(
self
,
request
=
None
):
'''
"""
Pushes all git repos.
'''
"""
ret
=
False
for
resource
in
self
.
subproject_set
.
all
():
ret
|=
resource
.
do_push
(
request
)
return
ret
def
do_reset
(
self
,
request
=
None
):
'''
"""
Pushes all git repos.
'''
"""
ret
=
False
for
resource
in
self
.
subproject_set
.
all
():
ret
|=
resource
.
do_reset
(
request
)
return
ret
def
can_push
(
self
):
'''
"""
Checks whether any suprojects can push.
'''
"""
ret
=
False
for
resource
in
self
.
subproject_set
.
all
():
ret
|=
resource
.
can_push
()
return
ret
def
get_last_change
(
self
):
'''
"""
Returns date of last change done in Weblate.
'''
"""
from
weblate.trans.models.changes
import
Change
try
:
change
=
Change
.
objects
.
content
().
filter
(
...
...
weblate/trans/tests/test_models.py
View file @
72fd20fb
...
...
@@ -198,7 +198,6 @@ class ProjectTest(RepoTestCase):
Project object testing.
"""
def
test_create
(
self
):
project
=
self
.
create_project
()
self
.
assertTrue
(
os
.
path
.
exists
(
project
.
get_path
()))
...
...
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