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)]