Browse Source

Carga inicial de participantes como admin-command, para evitar migrate muito demorado

dependabot/pip/requirements/djangorestframework-3.15.2 3.0.87
Sesóstris Vieira 7 months ago
parent
commit
b95b2a6d41
  1. 0
      sigi/apps/eventos/management/__init__.py
  2. 0
      sigi/apps/eventos/management/commands/__init__.py
  3. 21
      sigi/apps/eventos/management/commands/carga_participantes.py
  4. 25
      sigi/apps/eventos/migrations/0064_participantes_evento_carga_inicial.py

0
sigi/apps/eventos/management/__init__.py

0
sigi/apps/eventos/management/commands/__init__.py

21
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}")
)

25
sigi/apps/eventos/migrations/0064_participantes_evento_carga_inicial.py

@ -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)]
Loading…
Cancel
Save