def _test_queryJobs(self):

        # http: // localhost:5000 / plugin / PrintJobHistory / loadPrintJobHistoryByQuery?from=0 & to = 25 & sortColumn = printStartDateTime & sortOrder = desc & filterName = all & startDate = & endDate =
        tableQuery = {
            "from": 0,
            "to": 250,
            "sortColumn": "fileName",
            "sortOrder": "desc",
            "filterName": "all",
            "startDate": "",
            "endDate": "",
        }

        allJobsModels = self.databaseManager.loadPrintJobsByQuery(tableQuery)
        print(allJobsModels)
        allJobsAsList = TransformPrintJob2JSON.transformAllPrintJobModels(
            allJobsModels)

        pp = pprint.PrettyPrinter(indent=2)
        # pp.pprint(allJobsAsDict)
        jobCount = 0
        for jobItem in allJobsAsList:
            jobCount = jobCount + 1

            print(
                str(jobCount) + " " + jobItem["fileName"] + " " +
                str(jobItem["databaseId"]) + "  " +
                str(jobItem["printStartDateTimeFormatted"]) + "  " +
                str(jobItem["printEndDateTimeFormatted"]))

        pass
    def _test_queryJobs(self):
        tableQuery = {
            "from": 0,
            "to": 10,
            "sortColumn": "filename",
            "sortOrder": "asc",
            "filterName": "all",
            "startDate": "20.08.2020",
            "endDate": "20.08.2020",
        }

        allJobsModels = self.databaseManager.loadPrintJobsByQuery(tableQuery)
        print(allJobsModels)
        allJobsAsList = TransformPrintJob2JSON.transformAllPrintJobModels(
            allJobsModels)

        pp = pprint.PrettyPrinter(indent=2)
        # pp.pprint(allJobsAsDict)
        for jobItem in allJobsAsList:
            print(
                str(jobItem["databaseId"]) + "  " +
                str(jobItem["printStartDateTimeFormatted"]) + "  " +
                str(jobItem["printEndDateTimeFormatted"]))

        pass
Ejemplo n.º 3
0
    def get_printjobhistory(self):
        allJobsModels = self._databaseManager.loadAllPrintJobs()
        # allJobsAsDict = self._convertPrintJobHistoryModelsToDict(allJobsModels)
        allJobsAsDict = TransformPrintJob2JSON.transformAllPrintJobModels(
            allJobsModels)

        return flask.jsonify(allJobsAsDict)
Ejemplo n.º 4
0
    def get_createMultiPrintJobReport(self):

        tableQuery = flask.request.values.to_dict()
        allPrintJobModels = []
        if ("sample" in tableQuery):
            allPrintJobModels = self._createSamplePrintModels()
        else:
            # tableQuery or muliple databaseIds
            if ("databaseIds" in tableQuery):
                selectedDatabaseIds = tableQuery["databaseIds"]
                # selectedDatabaseIds = "21, 17"
                allPrintJobModels = self._databaseManager.loadSelectedPrintJobs(
                    selectedDatabaseIds)
            else:
                # always load all print jobs
                tableQuery["from"] = 0
                tableQuery["to"] = 99999
                allPrintJobModels = self._databaseManager.loadPrintJobsByQuery(
                    tableQuery)

        if (len(allPrintJobModels) == 0):
            # PrintJob was deleted
            message = "PrintJobs not in database anymore! PrintReport not possible."
            self._logger.error(message)
            self._sendDataToClient(
                dict(action="errorPopUp",
                     title="Print selection not possible",
                     message=message))
            return flask.jsonify()

        # build mulit-page report
        reportHtmlTemplate = self._loadPrintJobReportTemplateContent("multi")

        allJobsAsDict = TransformPrintJob2JSON.transformAllPrintJobModels(
            allPrintJobModels, self._file_manager, False)

        # allPrintJobModelAsJson = TransformPrintJob2JSON.transformPrintJobModel(printJobModel, self._file_manager, False)
        # printJobModelAsJson = {
        # 	"Hallo": "du"
        # }
        printJobModelAsJsonString = json.dumps(allJobsAsDict,
                                               indent=1,
                                               sort_keys=True,
                                               default=str)
        printJobModelAsJsonDict = json.loads(printJobModelAsJsonString)
        # print(printJobModelAsJsonString)
        # send rendered report to browser
        return Response(
            # flask.render_template("singlePrintJobReport.jinja2"),
            flask.render_template_string(
                reportHtmlTemplate,
                reportCreationTime=datetime.now(),
                allPrintJobModels=allPrintJobModels,
                hallo="welt",
                printJobModelAsJson=printJobModelAsJsonDict),
            mimetype='text/html'
            # headers={'Content-Disposition': 'attachment; filename=PrintJobHistory-SAMPLE.csv'}
        )
	def get_printjobhistoryByQuery(self):

		tableQuery = flask.request.values
		allJobsModels = self._databaseManager.loadPrintJobsByQuery(tableQuery)
		# allJobsAsDict = self._convertPrintJobHistoryModelsToDict(allJobsModels)
		allJobsAsDict = TransformPrintJob2JSON.transformAllPrintJobModels(allJobsModels)

		totalItemCount = self._databaseManager.countPrintJobsByQuery(tableQuery)
		return flask.jsonify({
								"totalItemCount": totalItemCount,
								"allPrintJobs": allJobsAsDict
							})
	def _test_loadSelected(self):
		selectedDatabaseIds = "17,3,21,23,20"
		allJobsModels = self.databaseManager.loadSelectedPrintJobs(selectedDatabaseIds)
		print(allJobsModels)
		allJobsAsList = TransformPrintJob2JSON.transformAllPrintJobModels(allJobsModels)

		pp = pprint.PrettyPrinter(indent=2)
		# pp.pprint(allJobsAsDict)
		for jobItem in allJobsAsList:
			print(str(jobItem["databaseId"]) + "  " + str(jobItem["printStartDateTimeFormatted"]) + "  " + str(jobItem["printEndDateTimeFormatted"]))

		pass
Ejemplo n.º 7
0
	def get_printjobhistoryByQuery(self):

		tableQuery = flask.request.values
		allJobsModels = self._databaseManager.loadPrintJobsByQuery(tableQuery)
		# allJobsAsDict = self._convertPrintJobHistoryModelsToDict(allJobsModels)
		# selectedFile = self._file_manager.path_on_disk(fileLocation, selectedFilename)
		allJobsAsDict = TransformPrintJob2JSON.transformAllPrintJobModels(allJobsModels, self._file_manager)

		totalItemCount = self._databaseManager.countPrintJobsByQuery(tableQuery)
		return flask.jsonify({
								"totalItemCount": totalItemCount,
								"allPrintJobs": allJobsAsDict
							})
Ejemplo n.º 8
0
    def get_createSinglePrintJobReport(self, databaseId):

        if (databaseId == "sample"):
            printJobModel = self._createSamplePrintModel()
        else:
            printJobModel = self._databaseManager.loadPrintJob(databaseId)

        if (printJobModel == None):
            # PrintJob was deleted
            message = "PrintJob not in database anymore! PrintReport not possible."
            self._logger.error(message)
            self._sendDataToClient(
                dict(action="errorPopUp",
                     title="Print selection not possible",
                     message=message))
            return flask.jsonify()

        reportHtmlTemplate = self._loadPrintJobReportTemplateContent("single")

        printJobModelAsJson = TransformPrintJob2JSON.transformPrintJobModel(
            printJobModel, self._file_manager, False)
        # printJobModelAsJson = {
        # 	"Hallo": "du"
        # }
        printJobModelAsJsonString = json.dumps(printJobModelAsJson,
                                               indent=1,
                                               sort_keys=True,
                                               default=str)
        printJobModelAsJsonDict = json.loads(printJobModelAsJsonString)
        # print(printJobModelAsJsonString)
        # send rendered report to browser
        return Response(
            # flask.render_template("singlePrintJobReport.jinja2"),
            flask.render_template_string(
                reportHtmlTemplate,
                reportCreationTime=datetime.now(),
                printJobModel=printJobModel,
                hallo="welt",
                printJobModelAsJson=printJobModelAsJsonDict),
            mimetype='text/html'
            # headers={'Content-Disposition': 'attachment; filename=PrintJobHistory-SAMPLE.csv'}
        )
Ejemplo n.º 9
0
    def exportPrintJobHistoryData(self, exportType):

        if exportType == "CSV":
            allJobsModels = self._databaseManager.loadAllPrintJobs()
            # allJobsDict = self._convertPrintJobHistoryEntitiesToDict(allJobsEntities)
            allJobsDict = TransformPrintJob2JSON.transformAllPrintJobModels(
                allJobsModels)

            # csvContent = self._convertPrintJobHistoryEntitiesToCSV(allJobsDict)
            csvContent = Transform2CSV.transform2CSV(allJobsDict)

            response = flask.make_response(csvContent)
            response.headers["Content-type"] = "text/csv"
            response.headers[
                "Content-Disposition"] = "attachment; filename=OctoprintPrintJobHistory.csv"  # TODO add timestamp

            return response
        else:
            print("BOOOMM not supported type")

        pass
	def _buildLengthString(self, length):
		lengthString = StringUtils.formatFloatSave("{:.02f}", TransformPrintJob2JSON.convertMM2M(length), "-")
		if (lengthString != "-"):
			lengthString = lengthString + "m"
		return lengthString