def download_export_view(request, mission, file_type, filename): """ Django view function to download a previously exported archive. """ collection = models.Collection.objects.get(mission=mission, file_type=file_type) if filename not in list_exports(mission, file_type): raise Http404("No such export '%s'" % filename) return StreamingHttpResponse(open( join(collection.data_dir, "exports", filename), "rb"), content_type="application/zip")
def download_export_view(request, mission, file_type, filename): """ Django view function to download a previously exported archive. """ collection = models.Collection.objects.get( mission=mission, file_type=file_type ) if filename not in list_exports(mission, file_type): raise Http404("No such export '%s'" % filename) return StreamingHttpResponse( open(join(collection.data_dir, "exports", filename), "rb"), content_type="application/zip" )
def import_view(request, mission, file_type): """ Django view function to import configuration and data. """ collection = models.Collection.objects.get(mission=mission, file_type=file_type) form = forms.ImportForm( tuple((export, export) for export in list_exports(mission, file_type))) return render( request, "inventory/collection/import.html", { "collections": models.Collection.objects.all(), "collection": collection, "form": form })
def export_view(request, mission, file_type): """ Django view function to export configuration and data. """ collection = models.Collection.objects.get( mission=mission, file_type=file_type ) if request.method == "POST": form = forms.ImportExportBaseForm(request.POST) if form.is_valid(): selection = form.cleaned_data["selection"] configuration = False data = False if selection == "full": configuration = True data = True elif selection == "config": configuration = True elif selection == "data": data = True try: filename = export_collection( mission, file_type, None, configuration, data ) messages.info(request, "Exported collection %s to file %s" % ( collection, basename(filename) ) ) except Exception: messages.error("Failed to export collection %s" % collection) else: messages.error(request, "Failed to start export for collection %s" % collection ) return redirect("inventory:collection:export", mission=mission, file_type=file_type ) form = forms.ImportExportBaseForm() return render( request, "inventory/collection/export.html", { "collections": models.Collection.objects.all(), "collection": collection, "form": form, "exports": list_exports(mission, file_type) } )
def import_view(request, mission, file_type): """ Django view function to import configuration and data. """ collection = models.Collection.objects.get( mission=mission, file_type=file_type ) form = forms.ImportForm( tuple((export, export) for export in list_exports(mission, file_type)) ) return render( request, "inventory/collection/import.html", { "collections": models.Collection.objects.all(), "collection": collection, "form": form } )
def export_view(request, mission, file_type): """ Django view function to export configuration and data. """ collection = models.Collection.objects.get(mission=mission, file_type=file_type) if request.method == "POST": form = forms.ImportExportBaseForm(request.POST) if form.is_valid(): selection = form.cleaned_data["selection"] configuration = False data = False if selection == "full": configuration = True data = True elif selection == "config": configuration = True elif selection == "data": data = True try: filename = export_collection(mission, file_type, None, configuration, data) messages.info( request, "Exported collection %s to file %s" % (collection, basename(filename))) except Exception: messages.error("Failed to export collection %s" % collection) else: messages.error( request, "Failed to start export for collection %s" % collection) return redirect("inventory:collection:export", mission=mission, file_type=file_type) form = forms.ImportExportBaseForm() return render( request, "inventory/collection/export.html", { "collections": models.Collection.objects.all(), "collection": collection, "form": form, "exports": list_exports(mission, file_type) })