def exportSpoolsData(self, exportType):

		if exportType == "CSV":
			allSpoolModels = self._databaseManager.loadAllSpoolsByQuery(None)

			now = datetime.datetime.now()
			currentDate = now.strftime("%Y%m%d-%H%M")
			fileName = "SpoolManager-" + currentDate + ".csv"

			return Response(CSVExportImporter.transform2CSV(allSpoolModels),
							mimetype='text/csv',
							headers={'Content-Disposition': 'attachment; filename=' + fileName})

		else:
			if (exportType == "legacyFilamentManager"):
				print("do something")
				allSpoolLegacyList = self._filamentManagerPluginImplementation.filamentManager.get_all_spools()
				if (allSpoolLegacyList != None):

					allSpoolModelList = self._createSpoolModelFromLegacy(allSpoolLegacyList)

					now = datetime.datetime.now()
					currentDate = now.strftime("%Y%m%d-%H%M")
					fileName = "FilamentManager-" + currentDate + ".csv"

					return Response(CSVExportImporter.transform2CSV(allSpoolModelList),
									mimetype='text/csv',
									headers={'Content-Disposition': 'attachment; filename='+fileName})

				pass

			print("BOOOMM not supported type")
		pass
	def get_sampleCSV(self):

		allSpoolModels = list()

		spoolModel = self._createSampleSpoolModel()
		allSpoolModels.append(spoolModel)
		return Response(CSVExportImporter.transform2CSV(allSpoolModels),
						mimetype='text/csv',
						headers={'Content-Disposition': 'attachment; filename=SpoolManager-SAMPLE.csv'})
	def _processCSVUploadAsync(self, path, importCSVMode, databaseManager, backupFolder, sendCSVUploadStatusToClient, logger):
		errorCollection = list()

		# - parsing
		# - backup
		# - append or replace

		def updateParsingStatus(lineNumber):
			# importStatus, currenLineNumber, backupFilePath,  successMessages, errorCollection
			sendCSVUploadStatusToClient("running", lineNumber, "", "", errorCollection)


		resultOfSpools = CSVExportImporter.parseCSV(path, updateParsingStatus, errorCollection, logger)

		if (len(errorCollection) != 0):
			successMessage = "Some error(s) occurs during parsing! No spools imported!"
			# importStatus, currenLineNumber, backupFilePath,  successMessages, errorCollection
			sendCSVUploadStatusToClient("finished", "", "", successMessage, errorCollection)
			return

		importModeText = "append"
		backupDatabaseFilePath = None
		if (len(resultOfSpools) > 0):
			# we could import some jobs

			# - backup
			backupDatabaseFilePath = databaseManager.backupDatabaseFile(backupFolder)

			# - import mode append/replace
			if (SettingsKeys.KEY_IMPORTCSV_MODE_REPLACE == importCSVMode):
				# delete old database and init a clean database
				databaseManager.reCreateDatabase()
				# reset selected spool
				self._selectSpool(None)

				importModeText = "fully replaced"

			# - insert all printjobs in database
			currentSpoolNumber = 0
			for spool in resultOfSpools:
				currentSpoolNumber = currentSpoolNumber + 1
				updateParsingStatus(currentSpoolNumber)

				remainingWeight = Transformer.calculateRemainingWeight(spool.usedWeight, spool.totalWeight)
				if (remainingWeight != None):
					spool.remainingWeight = remainingWeight
					# spool.save()

				databaseManager.saveModel(spool)
			pass
		else:
			errorCollection.append("Nothing to import!")

		successMessage = ""
		if (len(errorCollection) == 0):
			successMessage = "All data is successful " + importModeText + " with '" + str(len(resultOfSpools)) + "' spools."
		else:
			successMessage = "Some error(s) occurs! Maybe you need to manually rollback the database!"
		logger.info(successMessage)
		sendCSVUploadStatusToClient("finished", "", backupDatabaseFilePath,  successMessage, errorCollection)
		pass