38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from pathlib import Path
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
from core.importers import import_cursos
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Importa cursos de um CSV no formato de docs/cursos.csv."
|
|
|
|
def add_arguments(self, parser) -> None:
|
|
parser.add_argument("--csv", default="docs/cursos.csv")
|
|
parser.add_argument(
|
|
"--alunos",
|
|
default="docs/aluno_exportacao.txt",
|
|
help="Opcional. Usa o TXT de alunos para preencher carga horaria maxima.",
|
|
)
|
|
|
|
def handle(self, *args, **options) -> None:
|
|
alunos_path = Path(options["alunos"])
|
|
result = import_cursos(
|
|
csv_path=Path(options["csv"]),
|
|
alunos_path=alunos_path if alunos_path.exists() else None,
|
|
)
|
|
|
|
self.stdout.write(
|
|
self.style.SUCCESS(
|
|
"Cursos importados: "
|
|
f"{result.total} processados, "
|
|
f"{result.created} criados, "
|
|
f"{result.updated} atualizados, "
|
|
f"{result.without_carga_horaria} sem carga horaria de apoio, "
|
|
f"{len(result.errors)} com erro."
|
|
)
|
|
)
|
|
for error in result.errors:
|
|
self.stdout.write(self.style.WARNING(f" Linha {error.line}: {error.message}"))
|