[damned-lies] Fixed flake8 warnings in vertimus app



commit 237dc5129a1a4f6ec49d5d67379eec63c38a313f
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat Apr 24 10:54:26 2021 +0200

    Fixed flake8 warnings in vertimus app

 vertimus/feeds.py                                | 13 +++---
 vertimus/forms.py                                |  7 ++--
 vertimus/migrations/0001_initial.py              | 10 ++++-
 vertimus/migrations/0005_action_proxy_pofile.py  |  8 +++-
 vertimus/migrations/0006_pofile_path_relative.py |  4 +-
 vertimus/models.py                               | 37 +++++++++++-------
 vertimus/views.py                                | 50 +++++++++++++++---------
 7 files changed, 81 insertions(+), 48 deletions(-)
---
diff --git a/vertimus/feeds.py b/vertimus/feeds.py
index ba848fa2..910574ac 100644
--- a/vertimus/feeds.py
+++ b/vertimus/feeds.py
@@ -17,7 +17,8 @@ class LatestActionsByLanguage(Feed):
 
     def title(self, obj):
         return _("%(site)s — Workflow actions for the %(lang)s language") % {
-                  'site': settings.SITE_DOMAIN, 'lang': obj.name }
+            'site': settings.SITE_DOMAIN, 'lang': obj.name
+        }
 
     def link(self, obj):
         if not obj:
@@ -28,8 +29,9 @@ class LatestActionsByLanguage(Feed):
         return _("Latest actions of the GNOME Translation Project for the %s language") % obj.name
 
     def items(self, obj):
-        actions = Action.objects.filter(state_db__language=obj.id).select_related('state_db'
-            ).union(
+        actions = Action.objects.filter(state_db__language=obj.id).select_related(
+            'state_db'
+        ).union(
             
ActionArchived.objects.filter(state_db__language=obj.id).defer('sequence').select_related('state_db')
         )
         return actions.order_by('-created')[:20]
@@ -70,8 +72,9 @@ class LatestActionsByTeam(Feed):
         return _("Latest actions made by the %s team of the GNOME Translation Project") % obj
 
     def items(self, obj):
-        actions = Action.objects.filter(state_db__language__team=obj.id).select_related('state_db'
-            ).union(
+        actions = Action.objects.filter(state_db__language__team=obj.id).select_related(
+            'state_db'
+        ).union(
             
ActionArchived.objects.filter(state_db__language__team=obj.id).defer('sequence').select_related('state_db')
         )
         return actions.order_by('-created')[:20]
diff --git a/vertimus/forms.py b/vertimus/forms.py
index 9f8f5d31..2f98fb79 100644
--- a/vertimus/forms.py
+++ b/vertimus/forms.py
@@ -47,7 +47,7 @@ class ActionForm(forms.Form):
         label=_("Comment"),
         max_length=5000,
         required=False,
-        widget=forms.Textarea(attrs={'rows':8, 'cols':70, 'class': 'form-control'})
+        widget=forms.Textarea(attrs={'rows': 8, 'cols': 70, 'class': 'form-control'})
     )
     author = AuthorChoiceField(label=_("Commit author"), queryset=Person.objects.none(), required=False)
     sync_master = forms.BooleanField(
@@ -69,8 +69,9 @@ class ActionForm(forms.Form):
         ) for act in actions]
         self.fields['action'].help_link = reverse('help', args=['vertimus_workflow', 1])
         if state and ActionCI in map(type, self.actions):
-            self.fields['author'].queryset = state.involved_persons(extra_user=current_user
-                ).order_by('last_name', 'username')
+            self.fields['author'].queryset = state.involved_persons(
+                extra_user=current_user
+            ).order_by('last_name', 'username')
             self.fields['author'].initial = state.get_latest_po_file_action().person
         if not has_mailing_list:
             del self.fields['send_to_ml']
diff --git a/vertimus/migrations/0001_initial.py b/vertimus/migrations/0001_initial.py
index 2a394c1d..b33a9a77 100644
--- a/vertimus/migrations/0001_initial.py
+++ b/vertimus/migrations/0001_initial.py
@@ -19,7 +19,10 @@ class Migration(migrations.Migration):
                 ('created', models.DateTimeField(editable=False)),
                 ('comment', models.TextField(null=True, blank=True)),
                 ('file', models.FileField(null=True, upload_to=vertimus.models.generate_upload_filename, 
blank=True)),
-                ('merged_file', models.OneToOneField(null=True, blank=True, to='stats.PoFile', 
on_delete=models.SET_NULL)),
+                (
+                    'merged_file',
+                    models.OneToOneField(null=True, blank=True, to='stats.PoFile', on_delete=models.SET_NULL)
+                ),
                 ('person', models.ForeignKey(to='people.Person', on_delete=models.CASCADE)),
             ],
             options={
@@ -36,7 +39,10 @@ class Migration(migrations.Migration):
                 ('comment', models.TextField(null=True, blank=True)),
                 ('file', models.FileField(null=True, upload_to=vertimus.models.generate_upload_filename, 
blank=True)),
                 ('sequence', models.IntegerField(null=True)),
-                ('merged_file', models.OneToOneField(null=True, blank=True, to='stats.PoFile', 
on_delete=models.SET_NULL)),
+                (
+                    'merged_file',
+                    models.OneToOneField(null=True, blank=True, to='stats.PoFile', on_delete=models.SET_NULL)
+                ),
                 ('person', models.ForeignKey(to='people.Person', on_delete=models.CASCADE)),
             ],
             options={
diff --git a/vertimus/migrations/0005_action_proxy_pofile.py b/vertimus/migrations/0005_action_proxy_pofile.py
index f1b32e93..6b7f93b6 100644
--- a/vertimus/migrations/0005_action_proxy_pofile.py
+++ b/vertimus/migrations/0005_action_proxy_pofile.py
@@ -24,11 +24,15 @@ class Migration(migrations.Migration):
         migrations.AlterField(
             model_name='action',
             name='merged_file',
-            field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, 
to='vertimus.MergedPoFile'),
+            field=models.OneToOneField(
+                blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, 
to='vertimus.MergedPoFile'
+            ),
         ),
         migrations.AlterField(
             model_name='actionarchived',
             name='merged_file',
-            field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, 
to='vertimus.MergedPoFile'),
+            field=models.OneToOneField(
+                blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, 
to='vertimus.MergedPoFile'
+            ),
         ),
     ]
diff --git a/vertimus/migrations/0006_pofile_path_relative.py 
b/vertimus/migrations/0006_pofile_path_relative.py
index a2603c14..bbf8ab51 100644
--- a/vertimus/migrations/0006_pofile_path_relative.py
+++ b/vertimus/migrations/0006_pofile_path_relative.py
@@ -12,12 +12,12 @@ def strip_path_prefix(apps, schema_editor):
         old_path = action.merged_file.path
         action.merged_file.path = old_path.split('/' + media_dir + '/')[1]
         action.merged_file.save()
-    
+
     for act in Action.objects.filter(merged_file__isnull=False):
         strip_path(act)
     for act in ActionArchived.objects.filter(merged_file__isnull=False):
         strip_path(act)
- 
+
 
 class Migration(migrations.Migration):
 
diff --git a/vertimus/models.py b/vertimus/models.py
index 4b2c0c62..71616a65 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -50,20 +50,22 @@ class State(models.Model):
         if self.name == 'None' and getattr(self.__class__, '_name', 'None') != 'None':
             self.name = self.__class__._name
         self.__class__ = {
-            'None'        : StateNone,
-            'Translating' : StateTranslating,
-            'Translated'  : StateTranslated,
+            'None': StateNone,
+            'Translating': StateTranslating,
+            'Translated': StateTranslated,
             'Proofreading': StateProofreading,
-            'Proofread'   : StateProofread,
-            'ToReview'    : StateToReview,
-            'ToCommit'    : StateToCommit,
-            'Committing'  : StateCommitting,
-            'Committed'   : StateCommitted,
+            'Proofread': StateProofread,
+            'ToReview': StateToReview,
+            'ToCommit': StateToCommit,
+            'Committing': StateCommitting,
+            'Committed': StateCommitted,
         }.get(self.name, State)
 
     def __str__(self):
-        return "%s: %s %s (%s - %s)" % (self.name, self.branch.module.name,
-            self.branch.name, self.language.name, self.domain.name)
+        return "%s: %s %s (%s - %s)" % (
+            self.name, self.branch.module.name,
+            self.branch.name, self.language.name, self.domain.name
+        )
 
     def get_absolute_url(self):
         return reverse('vertimus_by_ids', args=[self.branch_id, self.domain_id, self.language_id])
@@ -316,6 +318,7 @@ ACTION_NAMES = (
     ('UNDO', _('Undo the last state change')),
 )
 
+
 def generate_upload_filename(instance, filename):
     if isinstance(instance, ActionArchived):
         return "%s/%s" % (settings.UPLOAD_ARCHIVED_DIR, os.path.basename(filename))
@@ -517,7 +520,7 @@ class Action(ActionAbstract):
                 path=os.path.relpath(merged_path, settings.MEDIA_ROOT)
             )
             self.save()
-            return # post_save will call merge_file_with_pot again
+            return  # post_save will call merge_file_with_pot again
         merged_path = self.merged_file.full_path
         command = ['msgmerge', '--previous', '-o', merged_path, self.file.path, str(pot_file)]
         run_shell_command(command)
@@ -542,7 +545,7 @@ class Action(ActionAbstract):
         url = "https://%s%s"; % (
             settings.SITE_DOMAIN, reverse(
                 'vertimus_by_names',
-                args = (
+                args=(
                     state.branch.module.name,
                     state.branch.name,
                     state.domain.name,
@@ -590,9 +593,13 @@ class ActionArchived(ActionAbstract):
     def clean_old_actions(cls, days):
         """ Delete old archived actions after some (now-days) time """
         # In each sequence, test date of the latest action, to delete whole sequences instead of individual 
actions
-        for action in ActionArchived.objects.values('sequence'
-            ).annotate(max_created=Max('created')
-            ).filter(max_created__lt=datetime.now()-timedelta(days=days)):
+        for action in ActionArchived.objects.values(
+            'sequence'
+        ).annotate(
+            max_created=Max('created')
+        ).filter(
+            max_created__lt=datetime.now()-timedelta(days=days)
+        ):
             # Call each action delete() so as file is also deleted
             for act in ActionArchived.objects.filter(sequence=action['sequence']):
                 act.delete()
diff --git a/vertimus/views.py b/vertimus/views.py
index c13e221a..d0d40a78 100644
--- a/vertimus/views.py
+++ b/vertimus/views.py
@@ -98,24 +98,31 @@ def vertimus(request, branch, domain, language, stats=None, level="0"):
                 # Process the data in form.cleaned_data
                 action = action_form.cleaned_data['action']
 
-                action = Action.new_by_name(action, person=person,
-                    file=request.FILES.get('file', None))
+                action = Action.new_by_name(
+                    action, person=person, file=request.FILES.get('file', None)
+                )
                 try:
                     msg = action.apply_on(state, action_form.cleaned_data)
                 except SendMailFailed:
-                    messages.error(request,
-                        _("A problem occurred while sending mail, no mail have been sent"))
+                    messages.error(
+                        request,
+                        _("A problem occurred while sending mail, no mail have been sent")
+                    )
                 except Exception as e:
-                    messages.error(request,
-                        _("An error occurred during applying your action: %s") % e)
+                    messages.error(
+                        request,
+                        _("An error occurred during applying your action: %s") % e
+                    )
                 else:
                     if msg:
                         messages.success(request, msg)
 
                 return HttpResponseRedirect(
-                    reverse('vertimus_by_names',
-                        args=(branch.module.name, branch.name, domain.name,
-                              language.locale)))
+                    reverse(
+                        'vertimus_by_names',
+                        args=(branch.module.name, branch.name, domain.name, language.locale)
+                    )
+                )
         elif available_actions:
             action_form = ActionForm(request.user, state, available_actions, has_ml)
 
@@ -203,7 +210,7 @@ def vertimus_diff(request, action_id_1, action_id_2, level):
                 'date': action_2.created,
             }
         else:
-             # 3) Lastly, the file should be the more recently committed file (merged)
+            # 3) Lastly, the file should be the more recently committed file (merged)
             try:
                 stats = Statistics.objects.get(branch=state.branch, domain=state.domain, 
language=state.language)
                 descr_2 = _('<a href="%(url)s">Latest committed file</a> for %(lang)s') % {
@@ -225,7 +232,8 @@ def vertimus_diff(request, action_id_1, action_id_2, level):
             open(file_path_2, encoding='utf-8', errors='replace') as fh2:
         diff_content = d.make_table(
             fh2.readlines(), fh1.readlines(),
-             descr_2, descr_1, context=True)
+            descr_2, descr_1, context=True
+        )
 
     context = {
         'diff_content': diff_content,
@@ -238,7 +246,7 @@ def latest_uploaded_po(request, module_name, branch_name, domain_name, locale_na
     """ Redirect to the latest uploaded po for a module/branch/language """
     branch = get_object_or_404(Branch, module__name=module_name, name=branch_name)
     domain = get_object_or_404(Domain, module__name=module_name, name=domain_name)
-    lang   = get_object_or_404(Language, locale=locale_name)
+    lang = get_object_or_404(Language, locale=locale_name)
     latest_upload = Action.objects.filter(state_db__branch=branch,
                                           state_db__domain=domain,
                                           state_db__language=lang,
@@ -307,7 +315,10 @@ class MsgiddiffView(PoFileActionBase):
         <style>
             body { font-family: monospace; }
             div.warning { font-size: 200%; padding: 3em; background-color: #ddd; }
-            div.diff { color: #444; background-color: #eee; padding: 4px; width: 78ch; line-height: 1.4; 
margin-left: 2.5em; }
+            div.diff {
+                color: #444; background-color: #eee; padding: 4px;
+                width: 78ch; line-height: 1.4; margin-left: 2.5em;
+            }
             div.nowrap { white-space: pre; }
             span.noline { color: #aaa; }
             del { color: red; background-color: #fed4d4; }
@@ -317,10 +328,11 @@ class MsgiddiffView(PoFileActionBase):
     </head>
 <body>
 ''' + '<div class="warning">{}</div>'.format(
-    _(
-        "WARNING: This file is <b>NOT</b> suitable as a base for completing this translation. "
-        "It contains HTML markup to highlight differential parts of changed strings."
-    ))
+        _(
+            "WARNING: This file is <b>NOT</b> suitable as a base for completing this translation. "
+            "It contains HTML markup to highlight differential parts of changed strings."
+        )
+    )
     FOOTER = '</body</html>'
 
     def streamed_file(self, po_file):
@@ -372,7 +384,7 @@ class MsgiddiffView(PoFileActionBase):
                         yield (
                             '<div class="diff%s">' % (' nowrap' if no_wrap else '') + diff_strings(
                                 html.escape(sep.join(strip(_line) for _line in prev_id)),
-                                html.escape(sep.join(strip(_linel) for _, _line in curr_id))
+                                html.escape(sep.join(strip(_line) for _, _line in curr_id))
                             ) + '</div>'
                         )
                         for no, _line in curr_id:
@@ -496,7 +508,7 @@ def diff_strings(previous, current):
         a=previous.replace('\r\n', '\n'),
         b=current.replace('\r\n', '\n'),
     )
-    output= []
+    output = []
     for opcode, a0, a1, b0, b1 in seqm.get_opcodes():
         if opcode == 'equal':
             output.append(seqm.a[a0:a1])


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]