Revision c25f5ed0 snf-astakos-app/astakos/im/management/commands/resource-import.py
b/snf-astakos-app/astakos/im/management/commands/resource-import.py | ||
---|---|---|
40 | 40 |
from snf_django.lib.db.transaction import commit_on_success_strict |
41 | 41 |
from astakos.im.register import add_resource, ResourceException |
42 | 42 |
from astakos.im.models import Service |
43 |
from ._common import read_from_file |
|
43 | 44 |
|
44 | 45 |
|
45 | 46 |
class Command(BaseCommand): |
... | ... | |
60 | 61 |
raise CommandError(m) |
61 | 62 |
|
62 | 63 |
else: |
63 |
with open(json_file) as file_data:
|
|
64 |
m = 'Input should be a JSON list.'
|
|
65 |
try:
|
|
66 |
data = json.load(file_data)
|
|
67 |
except json.JSONDecodeError:
|
|
68 |
raise CommandError(m)
|
|
69 |
if not isinstance(data, list):
|
|
70 |
raise CommandError(m)
|
|
64 |
data = read_from_file(json_file)
|
|
65 |
m = 'Input should be a JSON list.' |
|
66 |
try: |
|
67 |
data = json.loads(data)
|
|
68 |
except json.JSONDecodeError: |
|
69 |
raise CommandError(m) |
|
70 |
if not isinstance(data, list): |
|
71 |
raise CommandError(m) |
|
71 | 72 |
self.add_resources(data) |
72 | 73 |
|
73 |
|
|
74 | 74 |
@commit_on_success_strict() |
75 | 75 |
def add_resources(self, resources): |
76 | 76 |
output = [] |
Also available in: Unified diff