Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
prozorro-sale
Schematics
Commits
dcaac921
Commit
dcaac921
authored
Sep 30, 2022
by
Viacheslav Sukhovieiev
Browse files
feat: add to export_loop skip_fields arg
parent
49637ef0
Changes
2
Hide whitespace changes
Inline
Side-by-side
schematics/models.py
View file @
dcaac921
...
...
@@ -173,14 +173,16 @@ class Model(metaclass=ModelMeta):
return
convert
(
self
.
__class__
,
self
,
raw_data
,
role
=
role
,
**
kwargs
)
def
to_native
(
self
,
role
=
None
,
app_data
=
None
,
**
kwargs
):
data
=
app_data
.
get
(
'data'
)
if
not
data
:
if
app_data
and
'data'
in
app_data
:
data
=
app_data
[
'data'
]
else
:
data
=
self
return
to_native
(
self
.
__class__
,
data
,
role
=
role
,
app_data
=
app_data
,
export_level
=
NOT_NONE
,
**
kwargs
)
def
to_primitive
(
self
,
role
=
None
,
app_data
=
None
,
**
kwargs
):
data
=
app_data
.
get
(
'data'
)
if
not
data
:
if
app_data
and
'data'
in
app_data
:
data
=
app_data
[
'data'
]
else
:
data
=
self
return
to_primitive
(
self
.
__class__
,
data
,
role
=
role
,
app_data
=
app_data
,
export_level
=
NOT_NONE
,
**
kwargs
)
...
...
schematics/transforms.py
View file @
dcaac921
...
...
@@ -234,7 +234,7 @@ def _mutate(schema, mutable, raw_data, context):
def
export_loop
(
schema
,
instance_or_dict
,
field_converter
=
None
,
role
=
None
,
raise_error_on_role
=
True
,
export_level
=
None
,
app_data
=
None
,
context
=
None
):
export_level
=
None
,
app_data
=
None
,
context
=
None
,
skip_fields
=
None
):
"""
The export_loop function is intended to be a general loop definition that
can be used for any form of data shaping, such as application of roles or
...
...
@@ -292,10 +292,15 @@ def export_loop(schema, instance_or_dict, field_converter=None, role=None, raise
if
isinstance
(
instance_or_dict
,
models
.
Model
):
instance_or_dict
=
instance_or_dict
.
_Model__data
fields_to_skip
=
skip_fields
if
skip_fields
is
not
None
else
[]
for
field_name
,
field
,
value
in
atoms
(
schema
,
instance_or_dict
):
serialized_name
=
field
.
serialized_name
or
field_name
if
serialized_name
in
fields_to_skip
:
continue
if
filter_func
is
not
None
:
value
=
filter_func
(
field_name
,
value
,
context
)
if
value
is
ForbiddenRole
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment