Commit 0652bd96 authored by Michal Čihař's avatar Michal Čihař

Be more consistent in method documentation

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent acd63f2d
...@@ -43,14 +43,11 @@ class ProjectManager(models.Manager): ...@@ -43,14 +43,11 @@ class ProjectManager(models.Manager):
# pylint: disable=W0232 # pylint: disable=W0232
def all_acl(self, user): def all_acl(self, user):
""" """Returns list of projects user is allowed to access."""
Returns list of projects user is allowed to access.
"""
return self.get_acl_status(user)[0] return self.get_acl_status(user)[0]
def get_acl_status(self, user): def get_acl_status(self, user):
""" """Returns list of projects user is allowed to access
Returns list of projects user is allowed to access
and flag whether there is any filtering active. and flag whether there is any filtering active.
""" """
projects = self.all() projects = self.all()
...@@ -166,17 +163,12 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -166,17 +163,12 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
verbose_name_plural = ugettext_lazy('Projects') verbose_name_plural = ugettext_lazy('Projects')
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
""" """Constructor to initialize some cache properties."""
Constructor to initialize some cache properties.
"""
super(Project, self).__init__(*args, **kwargs) super(Project, self).__init__(*args, **kwargs)
self.permissions_cache = {} self.permissions_cache = {}
def has_acl(self, user): def has_acl(self, user):
""" """Checks whether current user is allowed to access this object"""
Checks whether current user is allowed to access this
project.
"""
if not self.enable_acl: if not self.enable_acl:
return True return True
...@@ -189,9 +181,7 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -189,9 +181,7 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
return self.owners.filter(id=user.id).exists() return self.owners.filter(id=user.id).exists()
def check_acl(self, request): def check_acl(self, request):
""" """Raises an error if user is not allowed to access this project."""
Raises an error if user is not allowed to access this project.
"""
if not self.has_acl(request.user): if not self.has_acl(request.user):
messages.error( messages.error(
request, request,
...@@ -200,25 +190,19 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -200,25 +190,19 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
raise PermissionDenied raise PermissionDenied
def all_users(self): def all_users(self):
""" """Returns all users having ACL on this project."""
Returns all users having ACL on this project.
"""
group = Group.objects.get(name=self.name) group = Group.objects.get(name=self.name)
return group.user_set.exclude( return group.user_set.exclude(
id__in=self.owners.values_list('id', flat=True) id__in=self.owners.values_list('id', flat=True)
) )
def add_user(self, user): def add_user(self, user):
""" """Adds user based on username of email."""
Adds user based on username of email.
"""
group = Group.objects.get(name=self.name) group = Group.objects.get(name=self.name)
user.groups.add(group) user.groups.add(group)
def remove_user(self, user): def remove_user(self, user):
""" """Adds user based on username of email."""
Adds user based on username of email.
"""
group = Group.objects.get(name=self.name) group = Group.objects.get(name=self.name)
user.groups.remove(group) user.groups.remove(group)
...@@ -231,31 +215,23 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -231,31 +215,23 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
) )
def _reverse_url_name(self): def _reverse_url_name(self):
""" """Returns base name for URL reversing."""
Returns base name for URL reversing.
"""
return 'project' return 'project'
def _reverse_url_kwargs(self): def _reverse_url_kwargs(self):
""" """Returns kwargs for URL reversing."""
Returns kwargs for URL reversing.
"""
return { return {
'project': self.slug 'project': self.slug
} }
def get_widgets_url(self): def get_widgets_url(self):
""" """Returns absolute URL for widgets."""
Returns absolute URL for widgets.
"""
return get_site_url( return get_site_url(
reverse('widgets', kwargs={'project': self.slug}) reverse('widgets', kwargs={'project': self.slug})
) )
def get_share_url(self): def get_share_url(self):
""" """Returns absolute URL usable for sharing."""
Returns absolute URL usable for sharing.
"""
return get_site_url( return get_site_url(
reverse('engage', kwargs={'project': self.slug}) reverse('engage', kwargs={'project': self.slug})
) )
...@@ -316,9 +292,7 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -316,9 +292,7 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
# pylint: disable=W0221 # pylint: disable=W0221
def _get_percents(self, lang=None): def _get_percents(self, lang=None):
""" """Returns percentages of translation status."""
Returns percentages of translation status.
"""
# Import translations # Import translations
from weblate.trans.models.translation import Translation from weblate.trans.models.translation import Translation
...@@ -329,17 +303,16 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -329,17 +303,16 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
# pylint: disable=W0221 # pylint: disable=W0221
def get_translated_percent(self, lang=None): def get_translated_percent(self, lang=None):
""" """Returns percent of translated strings."""
Returns percent of translated strings.
"""
if lang is None: if lang is None:
return super(Project, self).get_translated_percent() return super(Project, self).get_translated_percent()
return self._get_percents(lang)[0] return self._get_percents(lang)[0]
def get_total(self): def get_total(self):
""" """Calculates total number of strings to translate.
Calculates total number of strings to translate. This is done based on
assumption that all languages have same number of strings. This is done based on assumption that all languages have same number
of strings.
""" """
totals = [] totals = []
for component in self.subproject_set.all(): for component in self.subproject_set.all():
...@@ -350,9 +323,10 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -350,9 +323,10 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
return sum(totals) return sum(totals)
def get_total_words(self): def get_total_words(self):
""" """Calculates total number of words to translate.
Calculates total number of words to translate. This is done based on
assumption that all languages have same number of strings. This is done based on assumption that all languages have same number
of strings.
""" """
totals = [] totals = []
for component in self.subproject_set.all(): for component in self.subproject_set.all():
...@@ -363,23 +337,17 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -363,23 +337,17 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
return sum(totals) return sum(totals)
def get_languages(self): def get_languages(self):
""" """Returns list of all languages used in project."""
Returns list of all languages used in project.
"""
return Language.objects.filter( return Language.objects.filter(
translation__subproject__project=self translation__subproject__project=self
).distinct() ).distinct()
def get_language_count(self): def get_language_count(self):
""" """Returns number of languages used in this project."""
Returns number of languages used in this project.
"""
return self.get_languages().count() return self.get_languages().count()
def repo_needs_commit(self): def repo_needs_commit(self):
""" """Checks whether there are some not committed changes."""
Checks whether there are some not committed changes.
"""
for component in self.subproject_set.all(): for component in self.subproject_set.all():
if component.repo_needs_commit(): if component.repo_needs_commit():
return True return True
...@@ -398,9 +366,7 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -398,9 +366,7 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
return False return False
def commit_pending(self, request, on_commit=True): def commit_pending(self, request, on_commit=True):
""" """Commits any pending changes."""
Commits any pending changes.
"""
ret = False ret = False
components = self.all_repo_components() components = self.all_repo_components()
...@@ -417,33 +383,25 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -417,33 +383,25 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
return ret return ret
def do_update(self, request=None, method=None): def do_update(self, request=None, method=None):
""" """Updates all git repos."""
Updates all git repos.
"""
ret = True ret = True
for component in self.all_repo_components(): for component in self.all_repo_components():
ret &= component.do_update(request, method=method) ret &= component.do_update(request, method=method)
return ret return ret
def do_push(self, request=None): def do_push(self, request=None):
""" """Pushes all git repos."""
Pushes all git repos.
"""
return self.commit_pending(request, on_commit=False) return self.commit_pending(request, on_commit=False)
def do_reset(self, request=None): def do_reset(self, request=None):
""" """Pushes all git repos."""
Pushes all git repos.
"""
ret = False ret = False
for component in self.all_repo_components(): for component in self.all_repo_components():
ret |= component.do_reset(request) ret |= component.do_reset(request)
return ret return ret
def can_push(self): def can_push(self):
""" """Checks whether any suprojects can push."""
Checks whether any suprojects can push.
"""
ret = False ret = False
for component in self.subproject_set.all(): for component in self.subproject_set.all():
ret |= component.can_push() ret |= component.can_push()
...@@ -451,9 +409,7 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -451,9 +409,7 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
@property @property
def last_change(self): def last_change(self):
""" """Returns date of last change done in Weblate."""
Returns date of last change done in Weblate.
"""
components = self.subproject_set.all() components = self.subproject_set.all()
changes = [component.last_change for component in components] changes = [component.last_change for component in components]
changes = [c for c in changes if c is not None] changes = [c for c in changes if c is not None]
......
...@@ -91,9 +91,7 @@ class SubProjectManager(models.Manager): ...@@ -91,9 +91,7 @@ class SubProjectManager(models.Manager):
# pylint: disable=W0232 # pylint: disable=W0232
def get_linked(self, val): def get_linked(self, val):
''' """Returns subproject for linked repo."""
Returns subproject for linked repo.
'''
if not is_repo_link(val): if not is_repo_link(val):
return None return None
project, subproject = val[10:].split('/', 1) project, subproject = val[10:].split('/', 1)
...@@ -445,9 +443,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -445,9 +443,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
verbose_name_plural = ugettext_lazy('Components') verbose_name_plural = ugettext_lazy('Components')
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
''' """Constructor to initialize some cache properties."""
Constructor to initialize some cache properties.
'''
super(SubProject, self).__init__(*args, **kwargs) super(SubProject, self).__init__(*args, **kwargs)
self._repository_lock = None self._repository_lock = None
self._file_format = None self._file_format = None
...@@ -467,45 +463,32 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -467,45 +463,32 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
return '{0}/{1}: '.format(self.project.slug, self.slug) return '{0}/{1}: '.format(self.project.slug, self.slug)
def has_acl(self, user): def has_acl(self, user):
''' """Checks whether current user is allowed to access this object"""
Checks whether current user is allowed to access this
subproject.
'''
return self.project.has_acl(user) return self.project.has_acl(user)
def check_acl(self, request): def check_acl(self, request):
''' """Raises an error if user is not allowed to access this project."""
Raises an error if user is not allowed to access this project.
'''
self.project.check_acl(request) self.project.check_acl(request)
def _reverse_url_name(self): def _reverse_url_name(self):
''' """Returns base name for URL reversing."""
Returns base name for URL reversing.
'''
return 'subproject' return 'subproject'
def _reverse_url_kwargs(self): def _reverse_url_kwargs(self):
''' """Returns kwargs for URL reversing."""
Returns kwargs for URL reversing.
'''
return { return {
'project': self.project.slug, 'project': self.project.slug,
'subproject': self.slug 'subproject': self.slug
} }
def get_widgets_url(self): def get_widgets_url(self):
''' """Returns absolute URL for widgets."""
Returns absolute URL for widgets.
'''
return get_site_url( return get_site_url(
reverse('widgets', kwargs={'project': self.project.slug}) reverse('widgets', kwargs={'project': self.project.slug})
) )
def get_share_url(self): def get_share_url(self):
''' """Returns absolute URL usable for sharing."""
Returns absolute URL usable for sharing.
'''
return get_site_url( return get_site_url(
reverse('engage', kwargs={'project': self.project.slug}) reverse('engage', kwargs={'project': self.project.slug})
) )
...@@ -517,9 +500,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -517,9 +500,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
return '%s__%s' % (self.project.slug, self.slug) return '%s__%s' % (self.project.slug, self.slug)
def _get_path(self): def _get_path(self):
''' """Returns full path to subproject VCS repository."""
Returns full path to subproject VCS repository.
'''
if self.is_repo_link: if self.is_repo_link:
return self.linked_subproject.get_path() return self.linked_subproject.get_path()
else: else:
...@@ -527,9 +508,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -527,9 +508,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
@property @property
def repository_lock(self): def repository_lock(self):
''' """Returns lock object for current translation instance."""
Returns lock object for current translation instance.
'''
if self.is_repo_link: if self.is_repo_link:
return self.linked_subproject.repository_lock return self.linked_subproject.repository_lock
...@@ -545,40 +524,30 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -545,40 +524,30 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
return self._repository_lock return self._repository_lock
def can_push(self): def can_push(self):
''' """Returns true if push is possible for this subproject."""
Returns true if push is possible for this subproject.
'''
if self.is_repo_link: if self.is_repo_link:
return self.linked_subproject.can_push() return self.linked_subproject.can_push()
return self.push != '' and self.push is not None return self.push != '' and self.push is not None
@property @property
def is_repo_link(self): def is_repo_link(self):
''' """Checks whether repository is just a link for other one."""
Checks whether repository is just a link for other one.
'''
return is_repo_link(self.repo) return is_repo_link(self.repo)
def can_add_language(self): def can_add_language(self):
''' """Returns true if new languages can be added."""
Returns true if new languages can be added.
'''
return self.new_lang != 'none' return self.new_lang != 'none'
@property @property
def linked_subproject(self): def linked_subproject(self):
''' """Returns subproject for linked repo."""
Returns subproject for linked repo.
'''
if self._linked_subproject is None: if self._linked_subproject is None:
self._linked_subproject = SubProject.objects.get_linked(self.repo) self._linked_subproject = SubProject.objects.get_linked(self.repo)
return self._linked_subproject return self._linked_subproject
@property @property
def repository(self): def repository(self):
""" """VCS repository object."""
VCS repository object.
"""
if self.is_repo_link: if self.is_repo_link:
return self.linked_subproject.repository return self.linked_subproject.repository
...@@ -594,9 +563,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -594,9 +563,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
return self._repository return self._repository
def get_last_remote_commit(self): def get_last_remote_commit(self):
''' """Returns latest remote commit we know."""
Returns latest remote commit we know.
'''
cache_key = '{0}-last-commit'.format(self.get_full_slug()) cache_key = '{0}-last-commit'.format(self.get_full_slug())
result = cache.get(cache_key) result = cache.get(cache_key)
...@@ -609,9 +576,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -609,9 +576,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
return result return result
def get_repo_url(self): def get_repo_url(self):
''' """Returns link to repository."""
Returns link to repository.
'''
if self.is_repo_link: if self.is_repo_link:
return self.linked_subproject.get_repo_url() return self.linked_subproject.get_repo_url()
if not HIDE_REPO_CREDENTIALS: if not HIDE_REPO_CREDENTIALS:
...@@ -619,28 +584,23 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -619,28 +584,23 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
return cleanup_repo_url(self.repo) return cleanup_repo_url(self.repo)
def get_repo_branch(self): def get_repo_branch(self):
''' """Returns branch in repository."""
Returns branch in repository.
'''
if self.is_repo_link: if self.is_repo_link:
return self.linked_subproject.branch return self.linked_subproject.branch
return self.branch return self.branch
def get_export_url(self): def get_export_url(self):
''' """Returns URL of exported VCS repository."""
Returns URL of exported VCS repository.
'''
if self.is_repo_link: if self.is_repo_link:
return self.linked_subproject.git_export return self.linked_subproject.git_export
return self.git_export return self.git_export
def get_repoweb_link(self, filename, line): def get_repoweb_link(self, filename, line):
''' """Generates link to source code browser for given file and line
Generates link to source code browser for given file and line.
For linked repositories, it is possible to override linked For linked repositories, it is possible to override linked
repository path here. repository path here.
''' """
if len(self.repoweb) == 0: if len(self.repoweb) == 0:
if self.is_repo_link: if self.is_repo_link:
return self.linked_subproject.get_repoweb_link(filename, line) return self.linked_subproject.get_repoweb_link(filename, line)
...@@ -653,9 +613,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -653,9 +613,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
} }
def update_remote_branch(self, validate=False): def update_remote_branch(self, validate=False):
''' """Pulls from remote repository."""
Pulls from remote repository.
'''
if self.is_repo_link: if self.is_repo_link:
return self.linked_subproject.update_remote_branch(validate) return self.linked_subproject.update_remote_branch(validate)
...@@ -685,10 +643,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -685,10 +643,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
return False return False
def configure_repo(self, validate=False): def configure_repo(self, validate=False):
''' """Ensures repository is correctly configured"""
Ensures repository is correctly configured and points to current
remote.
'''
if self.is_repo_link: if self.is_repo_link:
return return
...@@ -702,9 +657,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -702,9 +657,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
self.update_remote_branch(validate) self.update_remote_branch(validate)
def configure_branch(self): def configure_branch(self):
''' """Ensures local tracking branch exists and is checkouted."""
Ensures local tracking branch exists and is checkouted.
'''
if self.is_repo_link: if self.is_repo_link:
return return
...@@ -712,9 +665,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -712,9 +665,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
self.repository.configure_branch(self.branch) self.repository.configure_branch(self.branch)
def do_update(self, request=None, method=None): def do_update(self, request=None, method=None):
''' """Wrapper for doing repository update"""
Wrapper for doing repository update and pushing them to translations.
'''
if self.is_repo_link: if self.is_repo_link:
return self.linked_subproject.do_update(request, method=method) return self.linked_subproject.do_update(request, method=method)
...@@ -764,9 +715,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -764,9 +715,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
) )
def do_push(self, request, force_commit=True, do_update=True): def do_push(self, request, force_commit=True, do_update=True):
''' """Wrapper for pushing changes to remote repo."""
Wrapper for pushing changes to remote repo.
'''
if self.is_repo_link: if self.is_repo_link:
return self.linked_subproject.do_push( return self.linked_subproject.do_push(
request, force_commit=force_commit, do_update=do_update request, force_commit=force_commit, do_update=do_update
...@@ -832,9 +781,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -832,9 +781,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
return False return False
def do_reset(self, request=None): def do_reset(self, request=None):
''' """Wrapper for reseting repo to same sources as remote."""
Wrapper for reseting repo to same sources as remote.
'''
if self.is_repo_link: if self.is_repo_link:
return self.linked_subproject.do_reset(request) return self.linked_subproject.do_reset(request)
...@@ -876,17 +823,13 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -876,17 +823,13 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
return 'weblate://%s/%s' % (self.project.slug, self.slug) return 'weblate://%s/%s' % (self.project.slug, self.slug)
def get_linked_childs(self): def get_linked_childs(self):
''' """Returns list of subprojects which link repository to us."""
Returns list of subprojects which link repository to us.
'''
return SubProject.objects.filter( return SubProject.objects.filter(
repo=self.get_repo_link_url() repo=self.get_repo_link_url()
) )
def commit_pending(self, request, from_link=False, skip_push=False): def commit_pending(self, request, from_link=False, skip_push=False):
''' """Checks whether there is any translation which needs commit."""
Checks whether there is any translation which needs commit.
'''
if not from_link and self.is_repo_link: if not from_link and self.is_repo_link:
return self.linked_subproject.commit_pending( return self.linked_subproject.commit_pending(
request, True, skip_push=skip_push request, True, skip_push=skip_push
...@@ -913,9 +856,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -913,9 +856,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
raise ParseError(str(error)) raise ParseError(str(error))
def update_branch(self, request=None, method=None): def update_branch(self, request=None, method=None):
''' """Updates current branch to match remote (if possible)."""
Updates current branch to match remote (if possible).
'''
if self.is_repo_link: if self.is_repo_link:
return self.linked_subproject.update_branch(request, method=method) return self.linked_subproject.update_branch(request, method=method)
...@@ -992,9 +933,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -992,9 +933,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
return False return False
def get_mask_matches(self): def get_mask_matches(self):
''' """Returns files matching current mask."""
Returns files matching current mask.
'''
prefix = os.path.join(self.get_path(), '') prefix = os.path.join(self.get_path(), '')
matches = set([ matches = set([
f.replace(prefix, '') f.replace(prefix, '')
...@@ -1015,9 +954,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1015,9 +954,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
def create_translations(self, force=False, langs=None, request=None, def create_translations(self, force=False, langs=None, request=None,
changed_template=False): changed_template=False):
''' """Loads translations from VCS."""
Loads translations from VCS.
'''
translations = set() translations = set()
languages = set() languages = set()
matches = self.get_mask_matches() matches = self.get_mask_matches()
...@@ -1074,9 +1011,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1074,9 +1011,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
self.log_info('updating completed') self.log_info('updating completed')
def get_lang_code(self, path): def get_lang_code(self, path):
''' """Parses language code from path."""
Parses language code from path.
'''
# Parse filename # Parse filename
matches = self.filemask_re.match(path) matches = self.filemask_re.match(path)
...@@ -1093,9 +1028,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1093,9 +1028,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
return code return code
def sync_git_repo(self, validate=False): def sync_git_repo(self, validate=False):
''' """Brings VCS repo in sync with current model."""
Brings VCS repo in sync with current model.
'''
if self.is_repo_link: if self.is_repo_link:
return return
self.configure_repo(validate) self.configure_repo(validate)
...@@ -1104,16 +1037,12 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1104,16 +1037,12 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
self.update_branch() self.update_branch()
def set_default_branch(self): def set_default_branch(self):
''' """Set default VCS branch if empty"""
Set default VCS branch if empty
'''
if self.branch == '': if self.branch == '':
self.branch = VCS_REGISTRY[self.vcs].default_branch self.branch = VCS_REGISTRY[self.vcs].default_branch
def clean_repo_link(self): def clean_repo_link(self):
''' """Validates repository link."""
Validates repository link.
'''
try: try:
repo = SubProject.objects.get_linked(self.repo) repo = SubProject.objects.get_linked(self.repo)
if repo is not None and repo.is_repo_link: if repo is not None and repo.is_repo_link:
...@@ -1147,9 +1076,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1147,9 +1076,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
) )
def clean_lang_codes(self, matches): def clean_lang_codes(self, matches):
''' """Validates that there are no double language codes"""
Validates that there are no double language codes found in the files.
'''
if len(matches) == 0 and not self.can_add_new_language(): if len(matches) == 0 and not self.can_add_new_language():
raise ValidationError(_('The mask did not match any files!')) raise ValidationError(_('The mask did not match any files!'))
langs = set() langs = set()
...@@ -1177,9 +1104,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1177,9 +1104,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
translated_langs.add(lang.code) translated_langs.add(lang.code)
def clean_files(self, matches): def clean_files(self, matches):
''' """Validates whether we can parse translation files."""
Validates whether we can parse translation files.
'''
notrecognized = [] notrecognized = []
errors = [] errors = []
dir_path = self.get_path() dir_path = self.get_path()
...@@ -1212,9 +1137,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1212,9 +1137,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
)) ))
def clean_new_lang(self): def clean_new_lang(self):
''' """Validates new language choices."""
Validates new language choices.
'''
if self.new_lang == 'add': if self.new_lang == 'add':
if not self.file_format_cls.supports_new_language(): if not self.file_format_cls.supports_new_language():
raise ValidationError(_( raise ValidationError(_(
...@@ -1236,9 +1159,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1236,9 +1159,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
)) ))
def clean_template(self): def clean_template(self):
""" """Validates template value."""
Validates template value.
"""
# Test for unexpected template usage # Test for unexpected template usage
if self.template != '' and self.file_format_cls.monolingual is False: if self.template != '' and self.file_format_cls.monolingual is False:
raise ValidationError( raise ValidationError(
...@@ -1270,10 +1191,10 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1270,10 +1191,10 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
) )
def clean(self): def clean(self):
''' """Validator fetches repository
Validator fetches repository and tries to find translation files.
Then it checks them for validity. It tries to find translation files and it checks them for validity.
''' """
if self.new_lang == 'url' and self.project.instructions == '': if self.new_lang == 'url' and self.project.instructions == '':
raise ValidationError(_( raise ValidationError(_(
'Please either fill in instructions URL ' 'Please either fill in instructions URL '
...@@ -1343,24 +1264,20 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1343,24 +1264,20 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
)) ))
def get_template_filename(self): def get_template_filename(self):
''' """Creates absolute filename for template."""
Creates absolute filename for template.
'''
return os.path.join(self.get_path(), self.template) return os.path.join(self.get_path(), self.template)
def get_new_base_filename(self): def get_new_base_filename(self):
''' """Creates absolute filename for base file for new translations."""
Creates absolute filename for base file for new translations.
'''
if not self.new_base: if not self.new_base:
return None return None
return os.path.join(self.get_path(), self.new_base) return os.path.join(self.get_path(), self.new_base)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
''' """Save wrapper
Save wrapper which updates backend repository and regenerates
translation data. It updates backend repository and regenerates translation data.
''' """
self.set_default_branch() self.set_default_branch()
# Detect if VCS config has changed (so that we have to pull the repo) # Detect if VCS config has changed (so that we have to pull the repo)
...@@ -1418,43 +1335,31 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1418,43 +1335,31 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
old.project.suggestion_set.copy(self.project) old.project.suggestion_set.copy(self.project)
def _get_percents(self): def _get_percents(self):
''' """Returns percentages of translation status"""
Returns percentages of translation status.
'''
return self.translation_set.get_percents() return self.translation_set.get_percents()
def repo_needs_commit(self): def repo_needs_commit(self):
''' """Checks whether there are some not committed changes"""
Checks whether there are some not committed changes.
'''
return self.repository.needs_commit() return self.repository.needs_commit()
def repo_needs_merge(self): def repo_needs_merge(self):
''' """Checks whether there is something to merge from remote repository"""
Checks whether there is something to merge from remote repository.
'''
return self.repository.needs_merge() return self.repository.needs_merge()
def repo_needs_push(self): def repo_needs_push(self):
''' """Checks whether there is something to push to remote repository"""
Checks whether there is something to push to remote repository.
'''
return self.repository.needs_push() return self.repository.needs_push()
@property @property
def file_format_cls(self): def file_format_cls(self):
''' """Returns file format object """
Returns file format object.
'''
if (self._file_format is None or if (self._file_format is None or
self._file_format.name != self.file_format): self._file_format.name != self.file_format):
self._file_format = FILE_FORMATS[self.file_format] self._file_format = FILE_FORMATS[self.file_format]
return self._file_format return self._file_format
def has_template(self): def has_template(self):
''' """Returns true if subproject is using template for translation"""
Returns true if subproject is using template for translation
'''
monolingual = self.file_format_cls.monolingual monolingual = self.file_format_cls.monolingual
return ( return (
(monolingual or monolingual is None) and (monolingual or monolingual is None) and
...@@ -1463,18 +1368,14 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1463,18 +1368,14 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
) )
def load_template_store(self): def load_template_store(self):
''' """Loads translate-toolkit store for template."""
Loads translate-toolkit store for template.
'''
return self.file_format_cls.load( return self.file_format_cls.load(
self.get_template_filename(), self.get_template_filename(),
) )
@property @property
def template_store(self): def template_store(self):
''' """Gets translate-toolkit store for template."""
Gets translate-toolkit store for template.
'''
# Do we need template? # Do we need template?
if not self.has_template(): if not self.has_template():
return None return None
...@@ -1489,9 +1390,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1489,9 +1390,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
@property @property
def last_change(self): def last_change(self):
''' """Returns date of last change done in Weblate."""
Returns date of last change done in Weblate.
'''
try: try:
change = Change.objects.content().filter( change = Change.objects.content().filter(
translation__subproject=self translation__subproject=self
...@@ -1502,9 +1401,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1502,9 +1401,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
@property @property
def all_flags(self): def all_flags(self):
''' """Returns parsed list of flags."""
Returns parsed list of flags.
'''
if self._all_flags is None: if self._all_flags is None:
self._all_flags = ( self._all_flags = (
self.check_flags.split(',') + self.check_flags.split(',') +
...@@ -1527,9 +1424,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1527,9 +1424,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
return True return True
def add_new_language(self, language, request): def add_new_language(self, language, request):
''' """Creates new language file."""
Creates new language file.
'''
if not self.can_add_new_language(): if not self.can_add_new_language():
raise ValueError('Not supported operation!') raise ValueError('Not supported operation!')
......
...@@ -55,9 +55,7 @@ class TranslationManager(models.Manager): ...@@ -55,9 +55,7 @@ class TranslationManager(models.Manager):
def check_sync(self, subproject, lang, code, path, force=False, def check_sync(self, subproject, lang, code, path, force=False,
request=None): request=None):
''' """Parses translation meta info and updates translation object"""
Parses translation meta info and creates/updates translation object.
'''
translation, dummy = self.get_or_create( translation, dummy = self.get_or_create(
language=lang, language=lang,
language_code=code, language_code=code,
...@@ -72,16 +70,14 @@ class TranslationManager(models.Manager): ...@@ -72,16 +70,14 @@ class TranslationManager(models.Manager):
return translation return translation
def enabled(self): def enabled(self):
''' """Filters enabled translations."""
Filters enabled translations.
'''
return self.filter(enabled=True).select_related() return self.filter(enabled=True).select_related()
def get_percents(self, project=None, subproject=None, language=None): def get_percents(self, project=None, subproject=None, language=None):
''' """Returns tuple consting of status percents:
Returns tuple consting of status percents -
(translated, fuzzy, failing checks) (translated, fuzzy, failing checks)
''' """
# Filter translations # Filter translations
translations = self translations = self
if project is not None: if project is not None:
...@@ -166,9 +162,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -166,9 +162,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
app_label = 'trans' app_label = 'trans'
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
''' """Constructor to initialize some cache properties."""
Constructor to initialize some cache properties.
'''
super(Translation, self).__init__(*args, **kwargs) super(Translation, self).__init__(*args, **kwargs)
self._store = None self._store = None
self._last_change_obj = None self._last_change_obj = None
...@@ -184,16 +178,11 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -184,16 +178,11 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
) )
def has_acl(self, user): def has_acl(self, user):
''' """Checks whether current user is allowed to access this object"""
Checks whether current user is allowed to access this
subproject.
'''
return self.subproject.project.has_acl(user) return self.subproject.project.has_acl(user)
def check_acl(self, request): def check_acl(self, request):
''' """Raises an error if user is not allowed to access this project."""
Raises an error if user is not allowed to access this project.
'''
self.subproject.project.check_acl(request) self.subproject.project.check_acl(request)
def is_template(self): def is_template(self):
...@@ -204,10 +193,10 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -204,10 +193,10 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
return self.filename == self.subproject.template return self.filename == self.subproject.template
def clean(self): def clean(self):
''' """
Validates that filename exists and can be opened using Validates that filename exists and can be opened using
translate-toolkit. translate-toolkit.
''' """
if not os.path.exists(self.get_filename()): if not os.path.exists(self.get_filename()):
raise ValidationError( raise ValidationError(
_( _(
...@@ -227,9 +216,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -227,9 +216,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
) )
def _get_percents(self): def _get_percents(self):
''' """Returns percentages of translation status."""
Returns percentages of translation status.
'''
# No units? # No units?
if self.total == 0: if self.total == 0:
return (100, 0, 0) return (100, 0, 0)
...@@ -264,9 +251,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -264,9 +251,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
return self.total - self.translated return self.total - self.translated
def get_lock_user_display(self): def get_lock_user_display(self):
''' """Returns formatted lock user."""
Returns formatted lock user.
'''
return get_user_display(self.lock_user) return get_user_display(self.lock_user)
def get_lock_display(self): def get_lock_display(self):
...@@ -277,20 +262,17 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -277,20 +262,17 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
) )
def is_locked(self, user=None): def is_locked(self, user=None):
''' """Check whether the translation is locked
Check whether the translation is locked and
possibly emits messages if request object is Possibly emits messages if request object is provided.
provided. """
'''
return ( return (
self.is_user_locked(user) or self.is_user_locked(user) or
self.subproject.locked self.subproject.locked
) )
def is_user_locked(self, user=None): def is_user_locked(self, user=None):
''' """Checks whether there is valid user lock on this translation."""
Checks whether there is valid user lock on this translation.
'''
# Any user? # Any user?
if self.lock_user is None: if self.lock_user is None:
return False return False
...@@ -309,9 +291,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -309,9 +291,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
return True return True
def create_lock(self, user, explicit=False): def create_lock(self, user, explicit=False):
''' """Creates lock on translation."""
Creates lock on translation.
'''
is_new = self.lock_user is None is_new = self.lock_user is None
self.lock_user = user self.lock_user = user
...@@ -324,9 +304,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -324,9 +304,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
self.update_lock_time(explicit, is_new) self.update_lock_time(explicit, is_new)
def update_lock_time(self, explicit=False, is_new=True): def update_lock_time(self, explicit=False, is_new=True):
''' """Sets lock timestamp."""
Sets lock timestamp.
'''
if explicit: if explicit:
seconds = appsettings.LOCK_TIME seconds = appsettings.LOCK_TIME
else: else:
...@@ -340,9 +318,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -340,9 +318,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
self.save() self.save()
def update_lock(self, user, create=True): def update_lock(self, user, create=True):
''' """Updates lock timestamp."""
Updates lock timestamp.
'''
# Check if we can lock # Check if we can lock
if self.is_user_locked(user): if self.is_user_locked(user):
return False return False
...@@ -360,15 +336,11 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -360,15 +336,11 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
return False return False
def _reverse_url_name(self): def _reverse_url_name(self):
''' """Returns base name for URL reversing."""
Returns base name for URL reversing.
'''
return 'translation' return 'translation'
def _reverse_url_kwargs(self): def _reverse_url_kwargs(self):
''' """Returns kwargs for URL reversing."""
Returns kwargs for URL reversing.
'''
return { return {
'project': self.subproject.project.slug, 'project': self.subproject.project.slug,
'subproject': self.subproject.slug, 'subproject': self.subproject.slug,
...@@ -376,9 +348,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -376,9 +348,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
} }
def get_widgets_url(self): def get_widgets_url(self):
''' """Returns absolute URL for widgets."""
Returns absolute URL for widgets.
'''
return get_site_url( return get_site_url(
'%s?lang=%s' % ( '%s?lang=%s' % (
reverse( reverse(
...@@ -391,9 +361,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -391,9 +361,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
) )
def get_share_url(self): def get_share_url(self):
''' """Returns absolute URL usable for sharing."""
Returns absolute URL usable for sharing.
'''
return get_site_url( return get_site_url(
reverse( reverse(
'engage-lang', 'engage-lang',
...@@ -419,15 +387,11 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -419,15 +387,11 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
) )
def get_filename(self): def get_filename(self):
''' """Returns absolute filename."""
Returns absolute filename.
'''
return os.path.join(self.subproject.get_path(), self.filename) return os.path.join(self.subproject.get_path(), self.filename)
def load_store(self): def load_store(self):
''' """Loads translate-toolkit storage from disk."""
Loads translate-toolkit storage from disk.
'''
return self.subproject.file_format_cls.parse( return self.subproject.file_format_cls.parse(
self.get_filename(), self.get_filename(),
self.subproject.template_store, self.subproject.template_store,
...@@ -435,16 +399,12 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -435,16 +399,12 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
) )
def supports_language_pack(self): def supports_language_pack(self):
''' """Checks whether we support language pack download."""
Checks whether we support language pack download.
'''
return self.subproject.file_format_cls.supports_language_pack() return self.subproject.file_format_cls.supports_language_pack()
@property @property
def store(self): def store(self):
''' """Returns translate-toolkit storage object for a translation."""
Returns translate-toolkit storage object for a translation.
'''
if self._store is None: if self._store is None:
try: try:
self._store = self.load_store() self._store = self.load_store()
...@@ -455,9 +415,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -455,9 +415,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
return self._store return self._store
def check_sync(self, force=False, request=None, change=None): def check_sync(self, force=False, request=None, change=None):
''' """Checks whether database is in sync with git and possibly updates"""
Checks whether database is in sync with git and possibly does update.
'''
if change is None: if change is None:
change = Change.ACTION_UPDATE change = Change.ACTION_UPDATE
...@@ -579,9 +537,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -579,9 +537,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
return self.subproject.can_push() return self.subproject.can_push()
def get_git_blob_hash(self): def get_git_blob_hash(self):
''' """Returns current VCS blob hash for file."""
Returns current VCS blob hash for file.
'''
ret = self.subproject.repository.get_object_hash(self.get_filename()) ret = self.subproject.repository.get_object_hash(self.get_filename())
if not self.subproject.has_template(): if not self.subproject.has_template():
...@@ -595,9 +551,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -595,9 +551,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
]) ])
def update_stats(self): def update_stats(self):
''' """Updates translation statistics."""
Updates translation statistics.
'''
# Grab stats # Grab stats
stats = self.unit_set.aggregate( stats = self.unit_set.aggregate(
Sum('num_words'), Sum('num_words'),
...@@ -661,17 +615,13 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -661,17 +615,13 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
self.store_hash() self.store_hash()
def store_hash(self): def store_hash(self):
''' """Stores current hash in database."""
Stores current hash in database.
'''
blob_hash = self.get_git_blob_hash() blob_hash = self.get_git_blob_hash()
self.revision = blob_hash self.revision = blob_hash
self.save() self.save()
def get_last_author(self, email=False): def get_last_author(self, email=False):
''' """Returns last autor of change done in Weblate."""
Returns last autor of change done in Weblate.
'''
if self.last_change_obj is None: if self.last_change_obj is None:
return None return None
return get_author_name( return get_author_name(
...@@ -696,17 +646,13 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -696,17 +646,13 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
@property @property
def last_change(self): def last_change(self):
''' """Returns date of last change done in Weblate."""
Returns date of last change done in Weblate.
'''
if self.last_change_obj is None: if self.last_change_obj is None:
return None return None
return self.last_change_obj.timestamp return self.last_change_obj.timestamp
def commit_pending(self, request, author=None, skip_push=False): def commit_pending(self, request, author=None, skip_push=False):
''' """Commits any pending changes."""
Commits any pending changes.
'''
# Get author of last changes # Get author of last changes
last = self.get_last_author(True) last = self.get_last_author(True)
...@@ -720,9 +666,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -720,9 +666,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
) )
def get_commit_message(self): def get_commit_message(self):
''' """Formats commit message based on project configuration."""
Formats commit message based on project configuration.
'''
msg = self.subproject.commit_message % { msg = self.subproject.commit_message % {
'language': self.language_code, 'language': self.language_code,
'language_name': self.language.name, 'language_name': self.language.name,
...@@ -744,9 +688,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -744,9 +688,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
return msg return msg
def __git_commit(self, author, timestamp, sync=False): def __git_commit(self, author, timestamp, sync=False):
''' """Commits translation to git."""
Commits translation to git.
'''
# Format commit message # Format commit message
msg = self.get_commit_message() msg = self.get_commit_message()
...@@ -781,9 +723,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -781,9 +723,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
self.store_hash() self.store_hash()
def repo_needs_commit(self): def repo_needs_commit(self):
''' """Checks whether there are some not committed changes."""
Checks whether there are some not committed changes.
'''
return self.subproject.repository.needs_commit(self.filename) return self.subproject.repository.needs_commit(self.filename)
def repo_needs_merge(self): def repo_needs_merge(self):
...@@ -794,14 +734,13 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -794,14 +734,13 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
def git_commit(self, request, author, timestamp, force_commit=False, def git_commit(self, request, author, timestamp, force_commit=False,
sync=False, skip_push=False, force_new=False): sync=False, skip_push=False, force_new=False):
''' """Wrapper for commiting translation to git.
Wrapper for commiting translation to git.
force_commit forces commit with lazy commits enabled force_commit forces commit with lazy commits enabled
sync updates git hash stored within the translation (otherwise sync updates git hash stored within the translation (otherwise
translation rescan will be needed) translation rescan will be needed)
''' """
# Is there something for commit? # Is there something for commit?
if not force_new and not self.repo_needs_commit(): if not force_new and not self.repo_needs_commit():
return False return False
...@@ -837,9 +776,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -837,9 +776,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
return True return True
def update_unit(self, unit, request, user=None): def update_unit(self, unit, request, user=None):
''' """Updates backend file and unit."""
Updates backend file and unit.
'''
if user is None: if user is None:
user = request.user user = request.user
# Save with lock acquired # Save with lock acquired
...@@ -917,9 +854,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -917,9 +854,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
return True, pounit return True, pounit
def get_source_checks(self): def get_source_checks(self):
''' """Returns list of failing source checks on current subproject."""
Returns list of failing source checks on current subproject.
'''
result = TranslationChecklist() result = TranslationChecklist()
result.add( result.add(
'all', 'all',
...@@ -959,9 +894,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -959,9 +894,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
return result return result
def get_translation_checks(self): def get_translation_checks(self):
''' """Returns list of failing checks on current translation."""
Returns list of failing checks on current translation.
'''
result = TranslationChecklist() result = TranslationChecklist()
# All strings # All strings
...@@ -1048,9 +981,9 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -1048,9 +981,9 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
return result return result
def merge_translations(self, request, store2, overwrite, add_fuzzy, fuzzy): def merge_translations(self, request, store2, overwrite, add_fuzzy, fuzzy):
""" """Merges translation unit wise
Merges translation unit wise, needed for template based translations to
add new strings. Needed for template based translations to add new strings.
""" """
ret = False ret = False
...@@ -1078,9 +1011,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -1078,9 +1011,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
def merge_store(self, request, author, store2, overwrite, merge_header, def merge_store(self, request, author, store2, overwrite, merge_header,
add_fuzzy, fuzzy, merge_comments): add_fuzzy, fuzzy, merge_comments):
''' """Merges translate-toolkit store into current translation."""
Merges translate-toolkit store into current translation.
'''
# Merge with lock acquired # Merge with lock acquired
with self.subproject.repository_lock: with self.subproject.repository_lock:
...@@ -1127,9 +1058,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -1127,9 +1058,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
return ret return ret
def merge_suggestions(self, request, store, fuzzy): def merge_suggestions(self, request, store, fuzzy):
''' """Merges content of translate-toolkit store as a suggestions."""
Merges content of translate-toolkit store as a suggestions.
'''
ret = False ret = False
for dummy, unit in store.iterate_merge(fuzzy): for dummy, unit in store.iterate_merge(fuzzy):
# Calculate unit checksum # Calculate unit checksum
...@@ -1157,9 +1086,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -1157,9 +1086,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
def merge_upload(self, request, fileobj, overwrite, author=None, def merge_upload(self, request, fileobj, overwrite, author=None,
merge_header=True, method='', fuzzy='', merge_header=True, method='', fuzzy='',
merge_comments=False): merge_comments=False):
''' """Top level handler for file uploads."""
Top level handler for file uploads.
'''
filecopy = fileobj.read() filecopy = fileobj.read()
fileobj.close() fileobj.close()
...@@ -1233,9 +1160,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -1233,9 +1160,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
return ret, store.count_units() return ret, store.count_units()
def invalidate_cache(self, cache_type=None): def invalidate_cache(self, cache_type=None):
''' """Invalidates any cached stats."""
Invalidates any cached stats.
'''
# Get parts of key cache # Get parts of key cache
slug = self.subproject.get_full_slug() slug = self.subproject.get_full_slug()
code = self.language.code code = self.language.code
...@@ -1259,7 +1184,5 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -1259,7 +1184,5 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
} }
def get_export_url(self): def get_export_url(self):
''' """Returns URL of exported git repository."""
Returns URL of exported git repository.
'''
return self.subproject.get_export_url() return self.subproject.get_export_url()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment