Commit 9879ab6b authored by Michal Čihař's avatar Michal Čihař

PEP-8 fixes

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent c8bc55b3
...@@ -129,8 +129,8 @@ def performance(request): ...@@ -129,8 +129,8 @@ def performance(request):
checks.append(( checks.append((
_('Email addresses'), _('Email addresses'),
( (
settings.SERVER_EMAIL not in default_mails settings.SERVER_EMAIL not in default_mails and
and settings.DEFAULT_FROM_EMAIL not in default_mails settings.DEFAULT_FROM_EMAIL not in default_mails
), ),
'production-email', 'production-email',
)) ))
......
...@@ -90,8 +90,8 @@ class Check(object): ...@@ -90,8 +90,8 @@ class Check(object):
except IndexError: except IndexError:
return False return False
return ( return (
(src in chars and tgt not in chars) (src in chars and tgt not in chars) or
or (src not in chars and tgt in chars) (src not in chars and tgt in chars)
) )
def is_language(self, unit, vals): def is_language(self, unit, vals):
......
...@@ -1026,9 +1026,9 @@ class SameCheck(TargetCheck): ...@@ -1026,9 +1026,9 @@ class SameCheck(TargetCheck):
lower_source = source.lower() lower_source = source.lower()
# Check special things like 1:4 1/2 or copyright # Check special things like 1:4 1/2 or copyright
if (len(source.strip('0123456789:/,.')) <= 1 if (len(source.strip('0123456789:/,.')) <= 1 or
or '(c) copyright' in lower_source '(c) copyright' in lower_source or
or u'©' in source): u'©' in source):
result = True result = True
else: else:
# Strip format strings # Strip format strings
......
...@@ -34,14 +34,14 @@ class WeblateExceptionReporterFilter(SafeExceptionReporterFilter): ...@@ -34,14 +34,14 @@ class WeblateExceptionReporterFilter(SafeExceptionReporterFilter):
request request
) )
if (hasattr(request, 'session') if (hasattr(request, 'session') and
and 'django_language' in request.session): 'django_language' in request.session):
lang = request.session['django_language'] lang = request.session['django_language']
else: else:
lang = None lang = None
if (hasattr(request, 'user') if (hasattr(request, 'user') and
and request.user.is_authenticated()): request.user.is_authenticated()):
user = repr(request.user.username) user = repr(request.user.username)
else: else:
user = None user = None
......
...@@ -100,10 +100,10 @@ class FileUnit(object): ...@@ -100,10 +100,10 @@ class FileUnit(object):
''' '''
# XLIFF and PHP are special in ttkit - it uses locations for what # XLIFF and PHP are special in ttkit - it uses locations for what
# is context in other formats # is context in other formats
if (isinstance(self.mainunit, xliffunit) if (isinstance(self.mainunit, xliffunit) or
or isinstance(self.mainunit, javafile) isinstance(self.mainunit, javafile) or
or isinstance(self.mainunit, javautf8file) isinstance(self.mainunit, javautf8file) or
or isinstance(self.mainunit, phpunit)): isinstance(self.mainunit, phpunit)):
return '' return ''
result = ', '.join(self.mainunit.getlocations()) result = ', '.join(self.mainunit.getlocations())
# Do not try to handle relative locations in Qt TS, see # Do not try to handle relative locations in Qt TS, see
...@@ -165,18 +165,18 @@ class FileUnit(object): ...@@ -165,18 +165,18 @@ class FileUnit(object):
reason do not correctly set source/target attributes. reason do not correctly set source/target attributes.
''' '''
return ( return (
hasattr(self.mainunit, 'name') hasattr(self.mainunit, 'name') and
and hasattr(self.mainunit, 'value') hasattr(self.mainunit, 'value') and
and hasattr(self.mainunit, 'translation') hasattr(self.mainunit, 'translation')
) )
def get_source(self): def get_source(self):
''' '''
Returns source string from a ttkit unit. Returns source string from a ttkit unit.
''' '''
if (isinstance(self.mainunit, tsunit) if (isinstance(self.mainunit, tsunit) and
and self.template is None self.template is None and
and self.mainunit.hasplural()): self.mainunit.hasplural()):
# Need to apply special magic for plurals here # Need to apply special magic for plurals here
# as there is no singlular/plural in the source string # as there is no singlular/plural in the source string
return join_plural([ return join_plural([
...@@ -208,9 +208,9 @@ class FileUnit(object): ...@@ -208,9 +208,9 @@ class FileUnit(object):
''' '''
if self.unit is None: if self.unit is None:
return '' return ''
if (isinstance(self.unit, tsunit) if (isinstance(self.unit, tsunit) and
and not self.unit.isreview() not self.unit.isreview() and
and not self.unit.istranslated()): not self.unit.istranslated()):
# For Qt ts, empty translated string means source should be used # For Qt ts, empty translated string means source should be used
return self.get_source() return self.get_source()
if self.is_unit_key_value(): if self.is_unit_key_value():
...@@ -239,8 +239,8 @@ class FileUnit(object): ...@@ -239,8 +239,8 @@ class FileUnit(object):
return '' return ''
else: else:
return context[0] return context[0]
elif (isinstance(self.mainunit, (pounit, JsonUnit)) elif (isinstance(self.mainunit, (pounit, JsonUnit)) and
and self.template is not None): self.template is not None):
# Monolingual JSON files # Monolingual JSON files
return self.template.getid() return self.template.getid()
else: else:
...@@ -370,8 +370,8 @@ class FileFormat(object): ...@@ -370,8 +370,8 @@ class FileFormat(object):
''' '''
# Workaround for _ created by interactive interpreter and # Workaround for _ created by interactive interpreter and
# later used instead of gettext by ttkit # later used instead of gettext by ttkit
if ('_' in __builtin__.__dict__ if ('_' in __builtin__.__dict__ and
and not callable(__builtin__.__dict__['_'])): not callable(__builtin__.__dict__['_'])):
del __builtin__.__dict__['_'] del __builtin__.__dict__['_']
# Add missing mode attribute to Django file wrapper # Add missing mode attribute to Django file wrapper
...@@ -421,8 +421,8 @@ class FileFormat(object): ...@@ -421,8 +421,8 @@ class FileFormat(object):
# Remember template # Remember template
self.template_store = template_store self.template_store = template_store
# Set language (needed for some which do not include this) # Set language (needed for some which do not include this)
if (language_code is not None if (language_code is not None and
and self.store.gettargetlanguage() is None): self.store.gettargetlanguage() is None):
self.store.settargetlanguage(language_code) self.store.settargetlanguage(language_code)
@property @property
...@@ -431,8 +431,8 @@ class FileFormat(object): ...@@ -431,8 +431,8 @@ class FileFormat(object):
Checks whether class is using template. Checks whether class is using template.
''' '''
return ( return (
(self.monolingual or self.monolingual is None) (self.monolingual or self.monolingual is None) and
and self.template_store is not None self.template_store is not None
) )
def _find_unit_template(self, context): def _find_unit_template(self, context):
...@@ -518,9 +518,9 @@ class FileFormat(object): ...@@ -518,9 +518,9 @@ class FileFormat(object):
# Adjust Content-Type header if needed # Adjust Content-Type header if needed
header = self.store.parseheader() header = self.store.parseheader()
if ('Content-Type' not in header if ('Content-Type' not in header or
or 'charset=CHARSET' in header['Content-Type'] 'charset=CHARSET' in header['Content-Type'] or
or 'charset=ASCII' in header['Content-Type']): 'charset=ASCII' in header['Content-Type']):
kwargs['Content_Type'] = 'text/plain; charset=UTF-8' kwargs['Content_Type'] = 'text/plain; charset=UTF-8'
self.store.updateheader(**kwargs) self.store.updateheader(**kwargs)
......
...@@ -462,11 +462,11 @@ class SearchForm(forms.Form): ...@@ -462,11 +462,11 @@ class SearchForm(forms.Form):
cleaned_data['type'] = 'all' cleaned_data['type'] = 'all'
# Default to source and target search # Default to source and target search
if (not cleaned_data['source'] if (not cleaned_data['source'] and
and not cleaned_data['target'] not cleaned_data['target'] and
and not cleaned_data['location'] not cleaned_data['location'] and
and not cleaned_data['comment'] not cleaned_data['comment'] and
and not cleaned_data['context']): not cleaned_data['context']):
cleaned_data['source'] = True cleaned_data['source'] = True
cleaned_data['target'] = True cleaned_data['target'] = True
......
...@@ -35,8 +35,8 @@ def microsoft_translation_supported(): ...@@ -35,8 +35,8 @@ def microsoft_translation_supported():
Checks whether service is supported. Checks whether service is supported.
''' '''
return ( return (
appsettings.MT_MICROSOFT_ID is not None appsettings.MT_MICROSOFT_ID is not None and
and appsettings.MT_MICROSOFT_SECRET is not None appsettings.MT_MICROSOFT_SECRET is not None
) )
......
...@@ -629,10 +629,10 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -629,10 +629,10 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
self.create_translations(request=request) self.create_translations(request=request)
# Push after possible merge # Push after possible merge
if (self.git_needs_push() if (self.git_needs_push() and
and ret ret and
and self.project.push_on_commit self.project.push_on_commit and
and self.can_push()): self.can_push()):
self.do_push(request, force_commit=False, do_update=False) self.do_push(request, force_commit=False, do_update=False)
return ret return ret
...@@ -874,8 +874,8 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -874,8 +874,8 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
if len(parts) == 1: if len(parts) == 1:
return 'INVALID' return 'INVALID'
# Assume English language for template if we can not parse it # Assume English language for template if we can not parse it
if ((not path.startswith(parts[0]) or not path.endswith(parts[1])) if ((not path.startswith(parts[0]) or not path.endswith(parts[1])) and
and path == self.template): path == self.template):
return 'en' return 'en'
# Get part matching to first wildcard # Get part matching to first wildcard
if len(parts[1]) == 0: if len(parts[1]) == 0:
...@@ -1151,13 +1151,13 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1151,13 +1151,13 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
if self.id: if self.id:
old = SubProject.objects.get(pk=self.id) old = SubProject.objects.get(pk=self.id)
changed_git = ( changed_git = (
(old.repo != self.repo) (old.repo != self.repo) or
or (old.branch != self.branch) (old.branch != self.branch) or
or (old.filemask != self.filemask) (old.filemask != self.filemask)
) )
changed_setup = ( changed_setup = (
(old.file_format != self.file_format) (old.file_format != self.file_format) or
or (old.template != self.template) (old.template != self.template)
) )
# Detect slug changes and rename git repo # Detect slug changes and rename git repo
self.check_rename(old) self.check_rename(old)
...@@ -1219,8 +1219,8 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1219,8 +1219,8 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
''' '''
Returns file format object. Returns file format object.
''' '''
if (self._file_format is None if (self._file_format is None or
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
...@@ -1230,9 +1230,9 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1230,9 +1230,9 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
''' '''
monolingual = self.file_format_cls.monolingual monolingual = self.file_format_cls.monolingual
return ( return (
(monolingual or monolingual is None) (monolingual or monolingual is None) and
and len(self.template) > 0 len(self.template) > 0 and
and not self.template.endswith('.pot') not self.template.endswith('.pot')
) )
def load_template_store(self): def load_template_store(self):
...@@ -1277,8 +1277,8 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1277,8 +1277,8 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
''' '''
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(',') +
+ list(self.file_format_cls.check_flags) list(self.file_format_cls.check_flags)
) )
return self._all_flags return self._all_flags
......
...@@ -495,13 +495,13 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -495,13 +495,13 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
# Check if unit is new and untranslated # Check if unit is new and untranslated
was_new = ( was_new = (
was_new was_new or
or (is_new and not newunit.translated) (is_new and not newunit.translated) or
or ( (
not newunit.translated not newunit.translated and
and newunit.translated != newunit.old_translated newunit.translated != newunit.old_translated
) ) or
or (newunit.fuzzy and newunit.fuzzy != newunit.old_fuzzy) (newunit.fuzzy and newunit.fuzzy != newunit.old_fuzzy)
) )
# Update position # Update position
...@@ -831,9 +831,9 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -831,9 +831,9 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
self.__git_commit(author, timestamp, sync) self.__git_commit(author, timestamp, sync)
# Push if we should # Push if we should
if (self.subproject.project.push_on_commit if (self.subproject.project.push_on_commit and
and not skip_push not skip_push and
and self.can_push()): self.can_push()):
self.subproject.do_push(request, force_commit=False) self.subproject.do_push(request, force_commit=False)
return True return True
...@@ -857,9 +857,9 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -857,9 +857,9 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
return False, None return False, None
# Check for changes # Check for changes
if (not add if (not add and
and unit.target == pounit.get_target() unit.target == pounit.get_target() and
and unit.fuzzy == pounit.is_fuzzy()): unit.fuzzy == pounit.is_fuzzy()):
return False, pounit return False, pounit
# Store translations # Store translations
...@@ -880,8 +880,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -880,8 +880,7 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
# Update po file header # Update po file header
po_revision_date = ( po_revision_date = (
datetime.now().strftime('%Y-%m-%d %H:%M') datetime.now().strftime('%Y-%m-%d %H:%M') + poheader.tzstring()
+ poheader.tzstring()
) )
# Prepare headers to update # Prepare headers to update
......
...@@ -385,13 +385,12 @@ class Unit(models.Model): ...@@ -385,13 +385,12 @@ class Unit(models.Model):
# Update checks on fuzzy update or on content change # Update checks on fuzzy update or on content change
same_content = ( same_content = (
target == self.target target == self.target and source == self.source
and source == self.source
) )
same_state = ( same_state = (
fuzzy == self.fuzzy fuzzy == self.fuzzy and
and translated == self.translated translated == self.translated and
and not created not created
) )
# Check if we actually need to change anything # Check if we actually need to change anything
...@@ -542,9 +541,9 @@ class Unit(models.Model): ...@@ -542,9 +541,9 @@ class Unit(models.Model):
# Return if there was no change # Return if there was no change
# We have to explicitly check for fuzzy flag change on monolingual # We have to explicitly check for fuzzy flag change on monolingual
# files, where we handle it ourselves without storing to backend # files, where we handle it ourselves without storing to backend
if (not saved if (not saved and
and oldunit.fuzzy == self.fuzzy oldunit.fuzzy == self.fuzzy and
and oldunit.target == self.target): oldunit.target == self.target):
# Propagate if we should # Propagate if we should
if propagate: if propagate:
self.propagate(request, change_action) self.propagate(request, change_action)
...@@ -576,8 +575,8 @@ class Unit(models.Model): ...@@ -576,8 +575,8 @@ class Unit(models.Model):
self.generate_change(request, user, oldunit, change_action) self.generate_change(request, user, oldunit, change_action)
# Force commiting on completing translation # Force commiting on completing translation
if (old_translated < self.translation.translated if (old_translated < self.translation.translated and
and self.translation.translated == self.translation.total): self.translation.translated == self.translation.total):
self.translation.commit_pending(request) self.translation.commit_pending(request)
Change.objects.create( Change.objects.create(
translation=self.translation, translation=self.translation,
...@@ -962,8 +961,8 @@ class Unit(models.Model): ...@@ -962,8 +961,8 @@ class Unit(models.Model):
Whether we can vote for suggestions. Whether we can vote for suggestions.
""" """
return ( return (
self.translation.subproject.suggestion_voting self.translation.subproject.suggestion_voting and
and self.translation.subproject.suggestion_autoaccept > 0 self.translation.subproject.suggestion_autoaccept > 0
) )
def translate(self, request, new_target, new_fuzzy): def translate(self, request, new_target, new_fuzzy):
...@@ -984,9 +983,9 @@ class Unit(models.Model): ...@@ -984,9 +983,9 @@ class Unit(models.Model):
""" """
if self._all_flags is None: if self._all_flags is None:
self._all_flags = set( self._all_flags = set(
self.flags.split(',') self.flags.split(',') +
+ self.source_info.check_flags.split(',') self.source_info.check_flags.split(',') +
+ self.translation.subproject.all_flags self.translation.subproject.all_flags
) )
self._all_flags.discard('') self._all_flags.discard('')
return self._all_flags return self._all_flags
......
...@@ -71,9 +71,9 @@ def is_key_line(key): ...@@ -71,9 +71,9 @@ def is_key_line(key):
if key[0] == '#': if key[0] == '#':
return False return False
return ( return (
' ssh-rsa ' in key ' ssh-rsa ' in key or
or ' ecdsa-sha2-nistp256 ' in key ' ecdsa-sha2-nistp256 ' in key or
or ' ssh-ed25519 ' in key ' ssh-ed25519 ' in key
) )
......
...@@ -55,8 +55,8 @@ class SeleniumTests(LiveServerTestCase, RegistrationTestMixin): ...@@ -55,8 +55,8 @@ class SeleniumTests(LiveServerTestCase, RegistrationTestMixin):
if DO_SELENIUM: if DO_SELENIUM:
self.set_test_status( self.set_test_status(
errors == len(result.errors) errors == len(result.errors) and
and failures == len(result.failures) failures == len(result.failures)
) )
@classmethod @classmethod
......
...@@ -360,8 +360,8 @@ class GitRepository(Repository): ...@@ -360,8 +360,8 @@ class GitRepository(Repository):
Checks whether this is a valid repository. Checks whether this is a valid repository.
''' '''
return ( return (
os.path.exists(os.path.join(self.path, '.git', 'config')) os.path.exists(os.path.join(self.path, '.git', 'config')) or
or os.path.exists(os.path.join(self.path, 'config')) os.path.exists(os.path.join(self.path, 'config'))
) )
def init(self): def init(self):
...@@ -677,8 +677,8 @@ class HgRepository(Repository): ...@@ -677,8 +677,8 @@ class HgRepository(Repository):
config.read(filename) config.read(filename)
if not config.has_section(section): if not config.has_section(section):
config.add_section(section) config.add_section(section)
if (config.has_option(section, key) if (config.has_option(section, key) and
and config.get(section, key) == value): config.get(section, key) == value):
return return
config.set(section, key, value) config.set(section, key, value)
with open(filename, 'wb') as handle: with open(filename, 'wb') as handle:
......
...@@ -285,8 +285,8 @@ def show_dictionary(request, project, lang): ...@@ -285,8 +285,8 @@ def show_dictionary(request, project, lang):
prj = get_project(request, project) prj = get_project(request, project)
lang = get_object_or_404(Language, code=lang) lang = get_object_or_404(Language, code=lang)
if (request.method == 'POST' if (request.method == 'POST' and
and request.user.has_perm('trans.add_dictionary')): request.user.has_perm('trans.add_dictionary')):
form = WordForm(request.POST) form = WordForm(request.POST)
if form.is_valid(): if form.is_valid():
Dictionary.objects.create( Dictionary.objects.create(
......
...@@ -164,8 +164,8 @@ class Widget(object): ...@@ -164,8 +164,8 @@ class Widget(object):
( (
self.progress['x'], self.progress['x'],
self.progress['y'], self.progress['y'],
self.progress['x'] self.progress['x'] +
+ self.progress['width'] / 100.0 * self.percent, self.progress['width'] / 100.0 * self.percent,
self.progress['y'] + self.progress['height'] self.progress['y'] + self.progress['height']
), ),
fill=COLOR_DATA[self.color]['bar'], fill=COLOR_DATA[self.color]['bar'],
......
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