From ee92c48b23f4358f408fe1777d8a390f76fd1674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B4natas=20Gomes?= Date: Mon, 19 Sep 2022 10:57:16 -0300 Subject: [PATCH] refact migration --- .../0028_candidatepage_show_convergency.py | 18 +++++++++++ .../0029_set_convergency_visibility.py | 31 ------------------- 2 files changed, 18 insertions(+), 31 deletions(-) delete mode 100644 landing/candidate/migrations/0029_set_convergency_visibility.py diff --git a/landing/candidate/migrations/0028_candidatepage_show_convergency.py b/landing/candidate/migrations/0028_candidatepage_show_convergency.py index cf53a53a..9265c42e 100644 --- a/landing/candidate/migrations/0028_candidatepage_show_convergency.py +++ b/landing/candidate/migrations/0028_candidatepage_show_convergency.py @@ -1,7 +1,24 @@ # Generated by Django 3.2.12 on 2022-09-19 11:15 from django.db import migrations, models +from candidate.models import CandidatePage +hide_convergency = [90, 878, 4610, 90842, 105534, 123756, 141401, 141480, 141552, + 160517, 204433, 207309, 214865, 219585, 219592, + 204563, 122466, None] + +def set_convergency(apps, schema_editor): + live_candidates = CandidatePage.objects.all().live() + for candidate in live_candidates: + is_show = candidate.id_autor not in hide_convergency + candidate.show_convergency = is_show + candidate.save() + +def unset_convergency(apps, schema_editor): + live_candidates = CandidatePage.objects.all().live() + for candidate in live_candidates: + candidate.show_convergency = None + candidate.save() class Migration(migrations.Migration): @@ -15,4 +32,5 @@ class Migration(migrations.Migration): name='show_convergency', field=models.BooleanField(default=True), ), + migrations.RunPython(set_convergency, unset_convergency), ] diff --git a/landing/candidate/migrations/0029_set_convergency_visibility.py b/landing/candidate/migrations/0029_set_convergency_visibility.py deleted file mode 100644 index 98f1b100..00000000 --- a/landing/candidate/migrations/0029_set_convergency_visibility.py +++ /dev/null @@ -1,31 +0,0 @@ -# Generated by Django 3.2.12 on 2022-09-19 11:15 - -from django.db import migrations, models -from candidate.models import CandidatePage - -hide_convergency = [90, 878, 4610, 90842, 105534, 123756, 141401, 141480, 141552, - 160517, 204433, 207309, 214865, 219585, 219592, - 204563, 122466, None] - -def set_convergency(apps, schema_editor): - live_candidates = CandidatePage.objects.all().live() - for candidate in live_candidates: - is_show = candidate.id_autor not in hide_convergency - candidate.show_convergency = is_show - candidate.save() - -def unset_convergency(apps, schema_editor): - live_candidates = CandidatePage.objects.all().live() - for candidate in live_candidates: - candidate.show_convergency = None - candidate.save() - -class Migration(migrations.Migration): - - dependencies = [ - ('candidate', '0028_candidatepage_show_convergency'), - ] - - operations = [ - migrations.RunPython(set_convergency, unset_convergency), - ]