diff --git a/series_tiempo_ar_api/apps/dump/generator/dta.py b/series_tiempo_ar_api/apps/dump/generator/dta.py index e9fbe055..14a6850c 100644 --- a/series_tiempo_ar_api/apps/dump/generator/dta.py +++ b/series_tiempo_ar_api/apps/dump/generator/dta.py @@ -6,7 +6,7 @@ from django_datajsonar.models import Node from series_tiempo_ar_api.apps.dump.generator import constants -from series_tiempo_ar_api.apps.dump.models import DumpFile, GenerateDumpTask +from series_tiempo_ar_api.apps.dump.models import DumpFile, GenerateDumpTask, ZipDumpFile class DtaGenerator: @@ -25,15 +25,17 @@ def generate_dump(self, dump_name): file_name=dump_name, node=self.node).last() df = pd.read_csv(dump_file.file) - if dump_file.file_name == DumpFile.FILENAME_VALUES: + if dump_name == DumpFile.FILENAME_VALUES: df = df[constants.STATA_VALUES_COLS] with FileWrapper(self.file_name(dump_file)) as f: save_to_dta(df, f.filepath) - self.task.dumpfile_set.create(file_type=DumpFile.TYPE_DTA, - file_name=dump_name, - node=dump_file.node, - file=File(open(f.filepath, 'rb'))) + dump = self.task.dumpfile_set.create(file_type=DumpFile.TYPE_DTA, + file_name=dump_name, + node=dump_file.node, + file=File(open(f.filepath, 'rb'))) + if (dump_name, DumpFile.TYPE_DTA) in DumpFile.ZIP_FILES: + ZipDumpFile.create_from_dump_file(dump, f.filepath) def file_name(self, dump_file: DumpFile): return f'{dump_file.node}-{dump_file.file_name}-{dump_file.id}.dta' diff --git a/series_tiempo_ar_api/apps/dump/models.py b/series_tiempo_ar_api/apps/dump/models.py index b780541e..2966ac0e 100644 --- a/series_tiempo_ar_api/apps/dump/models.py +++ b/series_tiempo_ar_api/apps/dump/models.py @@ -70,6 +70,7 @@ class DumpFile(models.Model): (FILENAME_FULL, TYPE_CSV), (FILENAME_VALUES, TYPE_CSV), (FILENAME_FULL, TYPE_SQL), + (FILENAME_VALUES, TYPE_DTA), ) file_type = models.CharField(max_length=12, choices=TYPE_CHOICES, default=TYPE_CSV)