forked from enviPath/enviPy
[Feature] Package Export/Import (#116)
Fixes #90 Fixes #91 Fixes #115 Fixes #104 Co-authored-by: Tim Lorsbach <tim@lorsba.ch> Reviewed-on: enviPath/enviPy#116
This commit is contained in:
@ -284,18 +284,21 @@ def packages(request):
|
||||
|
||||
if hidden := request.POST.get('hidden', None):
|
||||
|
||||
if hidden == 'import-legacy-package-json':
|
||||
if hidden in ['import-legacy-package-json', 'import-package-json']:
|
||||
f = request.FILES['file']
|
||||
|
||||
try:
|
||||
file_data = f.read().decode("utf-8")
|
||||
data = json.loads(file_data)
|
||||
|
||||
pack = PackageManager.import_package(data, current_user)
|
||||
if hidden == 'import-legacy-package-json':
|
||||
pack = PackageManager.import_legacy_package(data, current_user)
|
||||
else:
|
||||
pack = PackageManager.import_pacakge(data, current_user)
|
||||
|
||||
return redirect(pack.url)
|
||||
except UnicodeDecodeError:
|
||||
return error(request, 'Invalid encoding.', f'Invalid encoding, must be UTF-8')
|
||||
|
||||
else:
|
||||
return HttpResponseBadRequest()
|
||||
else:
|
||||
@ -799,6 +802,15 @@ def package(request, package_uuid):
|
||||
|
||||
if request.method == 'GET':
|
||||
|
||||
if request.GET.get("export", False) == "true":
|
||||
filename = f"{current_package.name.replace(' ', '_')}_{current_package.uuid}.json"
|
||||
pack_json = PackageManager.export_package(current_package, include_models=False,
|
||||
include_external_identifiers=False)
|
||||
response = JsonResponse(pack_json, content_type='application/json')
|
||||
response['Content-Disposition'] = f'attachment; filename="{filename}"'
|
||||
|
||||
return response
|
||||
|
||||
context = get_base_context(request)
|
||||
context['title'] = f'enviPath - {current_package.name}'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user