From 817060f517bc881aa3704c25e19889c5d580eb10 Mon Sep 17 00:00:00 2001
From: Samuel Gaist <samuel.gaist@idiap.ch>
Date: Fri, 11 Sep 2020 09:06:50 +0200
Subject: [PATCH] [search][migrations] Pre-commit cleanup

---
 beat/web/search/migrations/0001_initial.py    | 227 ++++++++++++++----
 .../migrations/0002_scheduler_addons.py       |  31 ++-
 2 files changed, 203 insertions(+), 55 deletions(-)

diff --git a/beat/web/search/migrations/0001_initial.py b/beat/web/search/migrations/0001_initial.py
index 53124f63a..f749eccc3 100644
--- a/beat/web/search/migrations/0001_initial.py
+++ b/beat/web/search/migrations/0001_initial.py
@@ -27,77 +27,216 @@
 
 from __future__ import unicode_literals
 
-from django.db import migrations, models
 import datetime
+
 from django.conf import settings
+from django.db import migrations
+from django.db import models
 
 
 class Migration(migrations.Migration):
 
     dependencies = [
-        ('experiments', '0001_initial'),
-        ('algorithms', '0001_initial'),
+        ("experiments", "0001_initial"),
+        ("algorithms", "0001_initial"),
         migrations.swappable_dependency(settings.AUTH_USER_MODEL),
-        ('team', '0001_initial'),
+        ("team", "0001_initial"),
     ]
 
     operations = [
         migrations.CreateModel(
-            name='Leaderboard',
+            name="Leaderboard",
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('created', models.DateTimeField(auto_now_add=True)),
-                ('updated', models.DateTimeField(auto_now=True)),
-                ('changed', models.DateTimeField(default=datetime.datetime.now)),
+                (
+                    "id",
+                    models.AutoField(
+                        verbose_name="ID",
+                        serialize=False,
+                        auto_created=True,
+                        primary_key=True,
+                    ),
+                ),
+                ("created", models.DateTimeField(auto_now_add=True)),
+                ("updated", models.DateTimeField(auto_now=True)),
+                ("changed", models.DateTimeField(default=datetime.datetime.now)),
             ],
         ),
         migrations.CreateModel(
-            name='Rank',
+            name="Rank",
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('order', models.PositiveIntegerField()),
-                ('algorithm', models.ForeignKey(to='algorithms.Algorithm', on_delete=models.CASCADE)),
-                ('experiment', models.ForeignKey(to='experiments.Experiment', on_delete=models.CASCADE)),
-                ('leaderboard', models.ForeignKey(to='search.Leaderboard', on_delete=models.CASCADE)),
-                ('result', models.ManyToManyField(to='experiments.Result')),
+                (
+                    "id",
+                    models.AutoField(
+                        verbose_name="ID",
+                        serialize=False,
+                        auto_created=True,
+                        primary_key=True,
+                    ),
+                ),
+                ("order", models.PositiveIntegerField()),
+                (
+                    "algorithm",
+                    models.ForeignKey(
+                        to="algorithms.Algorithm", on_delete=models.CASCADE
+                    ),
+                ),
+                (
+                    "experiment",
+                    models.ForeignKey(
+                        to="experiments.Experiment", on_delete=models.CASCADE
+                    ),
+                ),
+                (
+                    "leaderboard",
+                    models.ForeignKey(
+                        to="search.Leaderboard", on_delete=models.CASCADE
+                    ),
+                ),
+                ("result", models.ManyToManyField(to="experiments.Result")),
             ],
         ),
         migrations.CreateModel(
-            name='Search',
+            name="Search",
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('sharing', models.CharField(default=b'P', max_length=1, choices=[(b'P', b'Private'), (b'S', b'Shared'), (b'A', b'Public'), (b'U', b'Usable')])),
-                ('name', models.CharField(help_text=b'The name for this object (space-like characters will be automatically replaced by dashes)', max_length=200)),
-                ('version', models.PositiveIntegerField(default=1, help_text=b'The version of this object (an integer starting from 1)')),
-                ('short_description', models.CharField(default=b'', help_text=b'Describe the object succinctly (try to keep it under 80 characters)', max_length=100, blank=True)),
-                ('creation_date', models.DateTimeField(auto_now_add=True, verbose_name=b'Creation date')),
-                ('hash', models.CharField(help_text=b'Hashed value of the object contents (<a href="https://docs.python.org/2/library/hashlib.html">SHA256, hexadecimal digest</a>). This field is auto-generated and managed by the platform.', max_length=64, editable=False)),
-                ('filters', models.TextField(default=b'', blank=True)),
-                ('settings', models.TextField(default=b'', blank=True)),
-                ('description', models.TextField(default=b'', help_text=b'Describe the object thoroughly using <a href="http://docutils.sourceforge.net/rst.html">reStructuredText mark-up</a><br/><i class="fa fa-thumbs-up"></i> The ruler at 80 columns indicate suggested <a href="https://en.wikipedia.org/wiki/POSIX">POSIX line breaks</a> (for readability).<br/><i class="fa fa-thumbs-up"></i> The editor will automatically enlarge to accomodate the entirety of your input<br/><i class="fa fa-thumbs-up"></i> Use <a href="http://codemirror.net/doc/manual.html#commands">keyboard shortcuts</a> for search/replace and faster editing. For example, use Ctrl-F (PC) or Cmd-F (Mac) to search through this box', blank=True)),
-                ('author', models.ForeignKey(related_name='searchs', to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
-                ('fork_of', models.ForeignKey(related_name='forks', blank=True, to='search.Search', null=True, on_delete=models.SET_NULL)),
-                ('previous_version', models.ForeignKey(related_name='next_versions', blank=True, to='search.Search', null=True, on_delete=models.SET_NULL)),
-                ('shared_with', models.ManyToManyField(related_name='shared_searchs', to=settings.AUTH_USER_MODEL, blank=True)),
-                ('shared_with_team', models.ManyToManyField(related_name='shared_searchs', to='team.Team', blank=True)),
+                (
+                    "id",
+                    models.AutoField(
+                        verbose_name="ID",
+                        serialize=False,
+                        auto_created=True,
+                        primary_key=True,
+                    ),
+                ),
+                (
+                    "sharing",
+                    models.CharField(
+                        default=b"P",
+                        max_length=1,
+                        choices=[
+                            (b"P", b"Private"),
+                            (b"S", b"Shared"),
+                            (b"A", b"Public"),
+                            (b"U", b"Usable"),
+                        ],
+                    ),
+                ),
+                (
+                    "name",
+                    models.CharField(
+                        help_text=b"The name for this object (space-like characters will be automatically replaced by dashes)",
+                        max_length=200,
+                    ),
+                ),
+                (
+                    "version",
+                    models.PositiveIntegerField(
+                        default=1,
+                        help_text=b"The version of this object (an integer starting from 1)",
+                    ),
+                ),
+                (
+                    "short_description",
+                    models.CharField(
+                        default=b"",
+                        help_text=b"Describe the object succinctly (try to keep it under 80 characters)",
+                        max_length=100,
+                        blank=True,
+                    ),
+                ),
+                (
+                    "creation_date",
+                    models.DateTimeField(
+                        auto_now_add=True, verbose_name=b"Creation date"
+                    ),
+                ),
+                (
+                    "hash",
+                    models.CharField(
+                        help_text=b'Hashed value of the object contents (<a href="https://docs.python.org/2/library/hashlib.html">SHA256, hexadecimal digest</a>). This field is auto-generated and managed by the platform.',
+                        max_length=64,
+                        editable=False,
+                    ),
+                ),
+                ("filters", models.TextField(default=b"", blank=True)),
+                ("settings", models.TextField(default=b"", blank=True)),
+                (
+                    "description",
+                    models.TextField(
+                        default=b"",
+                        help_text=b'Describe the object thoroughly using <a href="http://docutils.sourceforge.net/rst.html">reStructuredText mark-up</a><br/><i class="fa fa-thumbs-up"></i> The ruler at 80 columns indicate suggested <a href="https://en.wikipedia.org/wiki/POSIX">POSIX line breaks</a> (for readability).<br/><i class="fa fa-thumbs-up"></i> The editor will automatically enlarge to accomodate the entirety of your input<br/><i class="fa fa-thumbs-up"></i> Use <a href="http://codemirror.net/doc/manual.html#commands">keyboard shortcuts</a> for search/replace and faster editing. For example, use Ctrl-F (PC) or Cmd-F (Mac) to search through this box',
+                        blank=True,
+                    ),
+                ),
+                (
+                    "author",
+                    models.ForeignKey(
+                        related_name="searchs",
+                        to=settings.AUTH_USER_MODEL,
+                        on_delete=models.CASCADE,
+                    ),
+                ),
+                (
+                    "fork_of",
+                    models.ForeignKey(
+                        related_name="forks",
+                        blank=True,
+                        to="search.Search",
+                        null=True,
+                        on_delete=models.SET_NULL,
+                    ),
+                ),
+                (
+                    "previous_version",
+                    models.ForeignKey(
+                        related_name="next_versions",
+                        blank=True,
+                        to="search.Search",
+                        null=True,
+                        on_delete=models.SET_NULL,
+                    ),
+                ),
+                (
+                    "shared_with",
+                    models.ManyToManyField(
+                        related_name="shared_searchs",
+                        to=settings.AUTH_USER_MODEL,
+                        blank=True,
+                    ),
+                ),
+                (
+                    "shared_with_team",
+                    models.ManyToManyField(
+                        related_name="shared_searchs", to="team.Team", blank=True
+                    ),
+                ),
             ],
-            options={
-                'verbose_name_plural': 'searches',
-            },
+            options={"verbose_name_plural": "searches"},
         ),
         migrations.AddField(
-            model_name='leaderboard',
-            name='experiments',
-            field=models.ManyToManyField(help_text=b'Experiments currently set on the leaderboard', related_name='leaderboards', through='search.Rank', to='experiments.Experiment', blank=True),
+            model_name="leaderboard",
+            name="experiments",
+            field=models.ManyToManyField(
+                help_text=b"Experiments currently set on the leaderboard",
+                related_name="leaderboards",
+                through="search.Rank",
+                to="experiments.Experiment",
+                blank=True,
+            ),
         ),
         migrations.AddField(
-            model_name='leaderboard',
-            name='notify',
-            field=models.ManyToManyField(help_text=b'If set, and the leader board changes, an e-mail notification will be sent to people on this list, every time it changes.', to=settings.AUTH_USER_MODEL, blank=True),
+            model_name="leaderboard",
+            name="notify",
+            field=models.ManyToManyField(
+                help_text=b"If set, and the leader board changes, an e-mail notification will be sent to people on this list, every time it changes.",
+                to=settings.AUTH_USER_MODEL,
+                blank=True,
+            ),
         ),
         migrations.AddField(
-            model_name='leaderboard',
-            name='search',
-            field=models.OneToOneField(related_name='leaderboard', to='search.Search', on_delete=models.CASCADE),
+            model_name="leaderboard",
+            name="search",
+            field=models.OneToOneField(
+                related_name="leaderboard", to="search.Search", on_delete=models.CASCADE
+            ),
         ),
     ]
diff --git a/beat/web/search/migrations/0002_scheduler_addons.py b/beat/web/search/migrations/0002_scheduler_addons.py
index e435eb523..a9d12015f 100644
--- a/beat/web/search/migrations/0002_scheduler_addons.py
+++ b/beat/web/search/migrations/0002_scheduler_addons.py
@@ -32,23 +32,32 @@ from django.db import migrations
 
 
 def reset_ranks(apps, schema_editor):
-    '''Reset ranks before older results can be deleted'''
+    """Reset ranks before older results can be deleted"""
 
     Result = apps.get_model("experiments", "Result")
     Rank = apps.get_model("search", "Rank")
 
     total = Result.objects.count()
-    if total: print('')
-    for i, r in enumerate(Result.objects.order_by('-id')):
-        older = Result.objects.filter(name=r.name, id__lt=r.id,
-                                      cache=r.block.hashes.first())
+    if total:
+        print("")
+    for i, r in enumerate(Result.objects.order_by("-id")):
+        older = Result.objects.filter(
+            name=r.name, id__lt=r.id, cache=r.block.hashes.first()
+        )
         for old in older:
             # check if any leaderboard ranks require updates
             for rank in Rank.objects.filter(result__in=(old,)):
-                print("Rank %d for search `%s/%s' uses old Result `%d' - " \
-                      "resetting to newer Result `%d'..." % \
-                      (rank.id, rank.leaderboard.search.author.username,
-                       rank.leaderboard.search.name, old.id, r.id))
+                print(
+                    "Rank %d for search `%s/%s' uses old Result `%d' - "
+                    "resetting to newer Result `%d'..."
+                    % (
+                        rank.id,
+                        rank.leaderboard.search.author.username,
+                        rank.leaderboard.search.name,
+                        old.id,
+                        r.id,
+                    )
+                )
                 rank.result.remove(old)
                 rank.result.add(r)
 
@@ -56,8 +65,8 @@ def reset_ranks(apps, schema_editor):
 class Migration(migrations.Migration):
 
     dependencies = [
-        ('search', '0001_initial'),
-        ('experiments', '0002_scheduler_addons'),
+        ("search", "0001_initial"),
+        ("experiments", "0002_scheduler_addons"),
     ]
 
     operations = [
-- 
GitLab