From b95b2a6d4166f0d62c2e3acb2060246fc40ee5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Tue, 4 Jun 2024 19:00:14 -0300 Subject: [PATCH] Carga inicial de participantes como admin-command, para evitar migrate muito demorado --- sigi/apps/eventos/management/__init__.py | 0 .../eventos/management/commands/__init__.py | 0 .../commands/carga_participantes.py | 21 ++++++++++++++++ ...0064_participantes_evento_carga_inicial.py | 25 ------------------- 4 files changed, 21 insertions(+), 25 deletions(-) create mode 100644 sigi/apps/eventos/management/__init__.py create mode 100644 sigi/apps/eventos/management/commands/__init__.py create mode 100644 sigi/apps/eventos/management/commands/carga_participantes.py delete mode 100644 sigi/apps/eventos/migrations/0064_participantes_evento_carga_inicial.py diff --git a/sigi/apps/eventos/management/__init__.py b/sigi/apps/eventos/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sigi/apps/eventos/management/commands/__init__.py b/sigi/apps/eventos/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sigi/apps/eventos/management/commands/carga_participantes.py b/sigi/apps/eventos/management/commands/carga_participantes.py new file mode 100644 index 0000000..239980c --- /dev/null +++ b/sigi/apps/eventos/management/commands/carga_participantes.py @@ -0,0 +1,21 @@ +from django.core.management.base import BaseCommand +from sigi.apps.eventos.models import Evento +from django.utils import timezone + + +class Command(BaseCommand): + help = "Carrega dados de participantes de eventos do Moodle para o SIGI" + + def handle(self, *args, **options): + for evento in Evento.objects.exclude(moodle_courseid=None).filter( + data_termino__lt=timezone.localtime() + ): + try: + evento.sincroniza_saberes() + self.stdout.write( + self.style.SUCCESS(f"✔ {evento.nome} sincronizado.") + ) + except Evento.SaberesSyncException as err: + self.stdout.write( + self.style.ERROR(f"✖ {evento.nome}: {err.message}") + ) diff --git a/sigi/apps/eventos/migrations/0064_participantes_evento_carga_inicial.py b/sigi/apps/eventos/migrations/0064_participantes_evento_carga_inicial.py deleted file mode 100644 index bd4e720..0000000 --- a/sigi/apps/eventos/migrations/0064_participantes_evento_carga_inicial.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 5.0.4 on 2024-05-28 13:41 - -from django.db import migrations -from django.utils import timezone -from sigi.apps.eventos.models import Evento - - -def carga(apps, schema_editor): - for evento in Evento.objects.exclude(moodle_courseid=None).filter( - data_termino__lt=timezone.localtime() - ): - try: - evento.sincroniza_saberes() - print(f"\t{evento.nome} sincronizado.") - except Evento.SaberesSyncException as err: - print(f"\tERRO: {evento.nome}: {err.message}") - - -class Migration(migrations.Migration): - - dependencies = [ - ("eventos", "0063_participantesevento_and_more"), - ] - - operations = [migrations.RunPython(carga, migrations.RunPython.noop)]