-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move all import function calls to management, leave only El…
…ementImportHelper Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
- Loading branch information
Showing
8 changed files
with
103 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,18 @@ | ||
import logging | ||
from typing import Callable, Tuple | ||
|
||
from rdmo.core.imports import ( | ||
ElementImportHelper, | ||
validate_instance, | ||
) | ||
|
||
from .models import Attribute | ||
from .serializers.v1 import BaseAttributeSerializer | ||
from .validators import AttributeLockedValidator, AttributeParentValidator, AttributeUniqueURIValidator | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def import_attribute( | ||
instance: Attribute, element: dict, | ||
validators: Tuple[Callable], | ||
save: bool = False) -> Attribute: | ||
|
||
# set_foreign_field are already set in management/import.py | ||
# check_permissions already done in management/import.py | ||
instance.path = instance.build_path(instance.key, instance.parent) | ||
validate_instance(instance, element, *validators) | ||
|
||
if element.get('errors'): | ||
return instance | ||
|
||
if save: | ||
instance.save() | ||
# sites and editors are added in management/import.py | ||
|
||
return instance | ||
|
||
|
||
import_helper_attribute = ElementImportHelper( | ||
model="domain.attribute", | ||
import_func=import_attribute, | ||
validators=(AttributeLockedValidator, AttributeParentValidator, AttributeUniqueURIValidator), | ||
foreign_fields=('parent',), | ||
extra_fields=('path',), | ||
serializer=BaseAttributeSerializer, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.