dflango 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dflango-0.2.2/dflango.egg-info → dflango-0.2.4}/PKG-INFO +1 -1
- {dflango-0.2.2 → dflango-0.2.4}/dflango/__init__.py +1 -1
- {dflango-0.2.2 → dflango-0.2.4}/dflango/commands/load_fixtures.py +44 -5
- {dflango-0.2.2 → dflango-0.2.4}/dflango/schemas/fields.py +14 -8
- {dflango-0.2.2 → dflango-0.2.4/dflango.egg-info}/PKG-INFO +1 -1
- {dflango-0.2.2 → dflango-0.2.4}/pyproject.toml +1 -1
- {dflango-0.2.2 → dflango-0.2.4}/LICENSE +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/MANIFEST.in +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/README.md +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/commands/__init__.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/commands/command_registration.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/commands/start_app.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/config.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/core.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/db.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/encoders.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/enum.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/exports/__init__.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/exports/csv/__init__.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/exports/csv/fields.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/exports/csv/registry.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/exports/csv/schemas.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/logging.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/mixin/__init__.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/mixin/permission_mixin.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/permissions.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/providers.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/routes/__init__.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/routes/route_registry.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/schemas/__init__.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/schemas/model_schemas.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/schemas/schemas.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/services/__init__.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/services/auth.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/templates/app_template/__init__.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/templates/app_template/config.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/templates/app_template/constants.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/templates/app_template/models/__init__.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/templates/app_template/models/models.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/templates/app_template/schemas/__init__.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/templates/app_template/schemas/schemas.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/templates/app_template/urls.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/templates/app_template/views/__init__.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/templates/app_template/views/views.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/views/__init__.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/views/base_export_view.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/views/base_view.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/views/config_view.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/views/detail_view.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/views/general_list_view.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/views/internal_view.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/views/list_view.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/views/search_view.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango/views/statistic_view.py +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango.egg-info/SOURCES.txt +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango.egg-info/dependency_links.txt +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango.egg-info/requires.txt +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/dflango.egg-info/top_level.txt +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/setup.cfg +0 -0
- {dflango-0.2.2 → dflango-0.2.4}/setup.py +0 -0
|
@@ -31,8 +31,42 @@ def get_model_by_name(name):
|
|
|
31
31
|
return None
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
def
|
|
35
|
-
"""
|
|
34
|
+
def _get_models_from_file(filepath):
|
|
35
|
+
"""Extract unique model classes referenced in a fixture file."""
|
|
36
|
+
try:
|
|
37
|
+
with open(filepath, "r") as f:
|
|
38
|
+
data = json.load(f)
|
|
39
|
+
except Exception:
|
|
40
|
+
return set()
|
|
41
|
+
|
|
42
|
+
models = set()
|
|
43
|
+
for entry in data:
|
|
44
|
+
model_name = entry.get("model")
|
|
45
|
+
model_class = get_model_by_name(model_name)
|
|
46
|
+
if model_class:
|
|
47
|
+
models.add(model_class)
|
|
48
|
+
return models
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _model_has_data(model_class):
|
|
52
|
+
"""Check if a model table already has at least one record."""
|
|
53
|
+
db = get_db()
|
|
54
|
+
return db.session.query(model_class).first() is not None
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def load_fixtures_from_file(filepath, force=False):
|
|
58
|
+
"""Loads fixtures from a single JSON file.
|
|
59
|
+
|
|
60
|
+
If force=False (default), skips the file if all models referenced
|
|
61
|
+
in it already have data in the database.
|
|
62
|
+
"""
|
|
63
|
+
if not force:
|
|
64
|
+
models = _get_models_from_file(filepath)
|
|
65
|
+
if models and all(_model_has_data(m) for m in models):
|
|
66
|
+
filename = os.path.basename(filepath)
|
|
67
|
+
logging.info(f"Skipping {filename}: all models already have data.")
|
|
68
|
+
return
|
|
69
|
+
|
|
36
70
|
try:
|
|
37
71
|
with open(filepath, "r") as f:
|
|
38
72
|
data = json.load(f)
|
|
@@ -110,15 +144,20 @@ def load_fixtures_from_file(filepath):
|
|
|
110
144
|
|
|
111
145
|
@click.command(name="load-fixtures")
|
|
112
146
|
@click.argument("filename", required=False)
|
|
147
|
+
@click.option("--force", is_flag=True, default=False,
|
|
148
|
+
help="Force loading even if models already have data.")
|
|
113
149
|
@with_appcontext
|
|
114
|
-
def load_fixtures_command(filename=None):
|
|
150
|
+
def load_fixtures_command(filename=None, force=False):
|
|
115
151
|
"""
|
|
116
152
|
Loads fixtures from a JSON file or from all JSON files in the 'fixtures' directory.
|
|
153
|
+
|
|
154
|
+
By default, skips fixture files whose models already have data in the database.
|
|
155
|
+
Use --force to load regardless (upsert by primary key).
|
|
117
156
|
"""
|
|
118
157
|
logging.info(f"Loading fixtures from {FIXTURES_DIR}")
|
|
119
158
|
|
|
120
159
|
if filename:
|
|
121
|
-
load_fixtures_from_file(filename)
|
|
160
|
+
load_fixtures_from_file(filename, force=force)
|
|
122
161
|
else:
|
|
123
162
|
if not os.path.exists(FIXTURES_DIR) or not os.path.isdir(FIXTURES_DIR):
|
|
124
163
|
logging.error(f"Fixtures directory '{FIXTURES_DIR}' not found!")
|
|
@@ -135,4 +174,4 @@ def load_fixtures_command(filename=None):
|
|
|
135
174
|
logging.info(f"files: {json_files}")
|
|
136
175
|
|
|
137
176
|
for json_file in json_files:
|
|
138
|
-
load_fixtures_from_file(os.path.join(FIXTURES_DIR, json_file))
|
|
177
|
+
load_fixtures_from_file(os.path.join(FIXTURES_DIR, json_file), force=force)
|
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
# Built-in
|
|
2
|
-
from datetime import timezone
|
|
2
|
+
from datetime import datetime, timezone
|
|
3
3
|
|
|
4
4
|
# Third-party
|
|
5
5
|
from marshmallow import fields
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class UtcDateTimeField(fields.DateTime):
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
|
|
10
|
+
def _serialize(self, value, attr, obj, **kwargs):
|
|
11
|
+
if value is None:
|
|
12
|
+
return None
|
|
13
|
+
if value.tzinfo is None:
|
|
14
|
+
value = value.replace(tzinfo=timezone.utc)
|
|
15
|
+
return value.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
15
16
|
|
|
16
17
|
def _deserialize(self, value, attr, data, **kwargs):
|
|
17
|
-
|
|
18
|
+
if not value:
|
|
19
|
+
raise self.make_error("invalid", input=value, obj_type=datetime)
|
|
20
|
+
try:
|
|
21
|
+
dt = datetime.fromisoformat(str(value).replace("Z", "+00:00"))
|
|
22
|
+
except (ValueError, AttributeError, TypeError) as error:
|
|
23
|
+
raise self.make_error("invalid", input=value, obj_type=datetime) from error
|
|
18
24
|
if dt.tzinfo is None:
|
|
19
25
|
return dt.replace(tzinfo=timezone.utc)
|
|
20
26
|
return dt.astimezone(timezone.utc)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|