Browse Source

Import VRE_apps from JSON data

master
Joshua Rubingh 6 months ago
parent
commit
5593226220
  1. 30
      VRE/apps/study/management/commands/import_studies.py

30
VRE/apps/study/management/commands/import_studies.py

@ -7,6 +7,8 @@ from apps.study.models import Study, StudyRole @@ -7,6 +7,8 @@ from apps.study.models import Study, StudyRole
import json
from pathlib import Path
from apps.vre_apps.models import VRE_App, VRE_AppProfile
class Command(BaseCommand):
help = '''Import studies from external data source
@ -14,12 +16,18 @@ class Command(BaseCommand): @@ -14,12 +16,18 @@ class Command(BaseCommand):
Valid JSON schema is:
{
'email_address' :'',
'first_name': '',
'last_name' : '',
'mobile': '',
'pmunber' :''
}
"name": "",
"code": "",
"description": "",
"contributors": [
{
"uid": "",
"role": "",
"workspace": ""
}
]
},
'''
def add_arguments(self, parser):
@ -72,13 +80,21 @@ class Command(BaseCommand): @@ -72,13 +80,21 @@ class Command(BaseCommand):
# The researcher is not imported first, so we have to ignore the role here
continue
role, created = StudyRole.objects.get_or_create(study=study, researcher=researcher,
contributor, created = StudyRole.objects.get_or_create(study=study, researcher=researcher,
defaults={
'role': role['role'].upper(),
'active': True
})
self.stdout.write(self.style.SUCCESS(f'New contributor {contributor.researcher.display_name} to study {study.name} {"is added" if created else "already exists"}.'))
# Create the workspace also here (vre_app)
try:
version = VRE_AppProfile.objects.get(app__slug='windows10-vdi', title__iexact=role['workspace'])
workspace, created = VRE_App.objects.get_or_create(contributor=contributor, version=version)
self.stdout.write(self.style.SUCCESS(f'New workspace {workspace} for study {study.name} is added.'))
except VRE_AppProfile.DoesNotExist:
self.stdout.write(self.style.ERROR(f'Could not create VRE App with type: {role["workspace"]}'))
import_counter += 1
self.stdout.write(self.style.SUCCESS(f'Study {study.name} {"is created" if created else "does already exists"}'))

Loading…
Cancel
Save