From d2738039f34a7d4578d4410eee8f8a3d56cec0ee Mon Sep 17 00:00:00 2001 From: Aleksandr Sokolov Date: Wed, 24 May 2023 14:30:04 +0300 Subject: [PATCH] fix: filter external modules (exclude .venv packages) && fix quote replace (affect only string) --- django_typomatic/__init__.py | 3 ++- django_typomatic/management/commands/generate_ts.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/django_typomatic/__init__.py b/django_typomatic/__init__.py index 3afffa5..4e37fa8 100644 --- a/django_typomatic/__init__.py +++ b/django_typomatic/__init__.py @@ -133,7 +133,8 @@ def __map_choices_to_enum_values(enum_name, field_type, choices): choices_enum = f"export enum {enum_name} {{\n" for key, value in choices.items(): - value = value.replace("'", "\\'") + if type(value) == str: + value = value.replace("'", "\\'") if type(key) == str: choices_enum = choices_enum + f" {str(key).replace(' ', '_')} = '{value}',\n" else: diff --git a/django_typomatic/management/commands/generate_ts.py b/django_typomatic/management/commands/generate_ts.py index afdba98..17dda8e 100644 --- a/django_typomatic/management/commands/generate_ts.py +++ b/django_typomatic/management/commands/generate_ts.py @@ -129,7 +129,7 @@ def handle(self, *args, serializers, output, all, **options): if all: for app in apps.get_app_configs(): # Filter external modules - if str(settings.BASE_DIR.parent) not in app.path: + if str(settings.BASE_DIR.parent) not in app.path or '.venv' in app.path: continue serializers += self._get_app_serializers(app.name)