Skip to content

Commit

Permalink
import_lookup_values | only queue populate indexes job when created
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Aug 21, 2020
1 parent 1c20c9f commit 8aaed24
Showing 1 changed file with 38 additions and 37 deletions.
75 changes: 38 additions & 37 deletions core/common/management/commands/import_lookup_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,45 @@ def handle(self, *args, **options):
settings.ELASTICSEARCH_DSL_AUTO_REFRESH = False
settings.ELASTICSEARCH_DSL_AUTOSYNC = False
settings.ES_SYNC = False
try:
user = UserProfile.objects.filter(username='ocladmin').get()
org = Organization.objects.get(mnemonic='OCL')
sources = self.create_sources(org, user)
user = UserProfile.objects.filter(username='ocladmin').get()
org = Organization.objects.get(mnemonic='OCL')
sources = self.create_sources(org, user)
created = False

current_path = os.path.dirname(__file__)
importer_confs = [
dict(
source=sources['Classes'],
file=os.path.join(current_path, "../../../lookup_fixtures/concept_classes.json")
),
dict(
source=sources['Locales'],
file=os.path.join(current_path, "../../../lookup_fixtures/locales.json")
),
dict(
source=sources['Datatypes'],
file=os.path.join(current_path, "../../../lookup_fixtures/datatypes_fixed.json")
),
dict(
source=sources['NameTypes'],
file=os.path.join(current_path, "../../../lookup_fixtures/nametypes_fixed.json")
),
dict(
source=sources['DescriptionTypes'],
file=os.path.join(current_path, "../../../lookup_fixtures/description_types.json")
),
dict(
source=sources['MapTypes'],
file=os.path.join(current_path, "../../../lookup_fixtures/maptypes_fixed.json")
),
]
current_path = os.path.dirname(__file__)
importer_confs = [
dict(
source=sources['Classes'],
file=os.path.join(current_path, "../../../lookup_fixtures/concept_classes.json")
),
dict(
source=sources['Locales'],
file=os.path.join(current_path, "../../../lookup_fixtures/locales.json")
),
dict(
source=sources['Datatypes'],
file=os.path.join(current_path, "../../../lookup_fixtures/datatypes_fixed.json")
),
dict(
source=sources['NameTypes'],
file=os.path.join(current_path, "../../../lookup_fixtures/nametypes_fixed.json")
),
dict(
source=sources['DescriptionTypes'],
file=os.path.join(current_path, "../../../lookup_fixtures/description_types.json")
),
dict(
source=sources['MapTypes'],
file=os.path.join(current_path, "../../../lookup_fixtures/maptypes_fixed.json")
),
]

for conf in importer_confs:
source = conf['source']
self.create_concepts(source, conf['file'], user)
except: # pylint: disable=bare-except
pass
finally:
results = []
for conf in importer_confs:
source = conf['source']
results.append(self.create_concepts(source, conf['file'], user))

if any(results):
populate_indexes.delay(['sources', 'concepts'])

@staticmethod
Expand Down Expand Up @@ -94,3 +94,4 @@ def create_concepts(source, file, user):
data['name'] = mnemonic
data['parent'] = source
Concept.persist_new(data, user, False)
return True

0 comments on commit 8aaed24

Please sign in to comment.