def saveModel(self, model): databaseId = None with self._database.atomic() as transaction: # Opens new transaction. try: if (model.isTemplate == True): # remove template flag from last templateSpool SpoolModel.update({ SpoolModel.isTemplate: False }).where(SpoolModel.isTemplate == True).execute() model.save() databaseId = model.get_id() # do expicit commit transaction.commit() except Exception as e: # Because this block of code is wrapped with "atomic", a # new transaction will begin automatically after the call # to rollback(). transaction.rollback() self._logger.exception( "Could not insert printJob into database:" + str(e)) self.sendErrorMessageToClient( "error", "DatabaseManager", "Could not insert the printjob into the database. See OctoPrint.log for details!" ) pass return databaseId
def loadAllSpoolsByQuery(self, tableQuery): if (tableQuery == None): return SpoolModel.select().order_by(SpoolModel.created.desc()) offset = int(tableQuery["from"]) limit = int(tableQuery["to"]) sortColumn = tableQuery["sortColumn"] sortOrder = tableQuery["sortOrder"] # not needed at the moment filterName = tableQuery["filterName"] myQuery = SpoolModel.select().offset(offset).limit(limit) # if (filterName == "onlySuccess"): # myQuery = myQuery.where(PrintJobModel.printStatusResult == "success") # elif (filterName == "onlyFailed"): # myQuery = myQuery.where(PrintJobModel.printStatusResult != "success") if ("displayName" == sortColumn): if ("desc" == sortOrder): myQuery = myQuery.order_by(SpoolModel.displayName.desc()) else: myQuery = myQuery.order_by(SpoolModel.displayName) if ("lastUse" == sortColumn): if ("desc" == sortOrder): myQuery = myQuery.order_by(SpoolModel.lastUse.desc()) else: myQuery = myQuery.order_by(SpoolModel.lastUse) if ("firstUse" == sortColumn): if ("desc" == sortOrder): myQuery = myQuery.order_by(SpoolModel.firstUse.desc()) else: myQuery = myQuery.order_by(SpoolModel.firstUse) return myQuery
def deleteSpool(self, databaseId): with self._database.atomic() as transaction: # Opens new transaction. try: # first delete relations # n = FilamentModel.delete().where(FilamentModel.printJob == databaseId).execute() # n = TemperatureModel.delete().where(TemperatureModel.printJob == databaseId).execute() SpoolModel.delete_by_id(databaseId) except Exception as e: # Because this block of code is wrapped with "atomic", a # new transaction will begin automatically after the call # to rollback(). transaction.rollback() self._logger.exception("Could not delete spool from database:" + str(e)) self.sendErrorMessageToClient("Spool-DatabaseManager", "Could not delete the spool ('"+ str(databaseId) +"') from the database. See OctoPrint.log for details!") pass
def loadCatalogMaterials(self, tableQuery): result = set() result.add("") myQuery = SpoolModel.select(SpoolModel.material).distinct() for spool in myQuery: value = spool.material if (value != None): result.add(value) return result
def loadCatalogVendors(self, tableQuery): result = set() result.add("") myQuery = SpoolModel.select(SpoolModel.vendor).distinct() for spool in myQuery: value = spool.vendor if (value != None): result.add(value) return result
def loadAllSpoolsByQuery(self, tableQuery): if (tableQuery == None): return SpoolModel.select().order_by(SpoolModel.created.desc()) offset = int(tableQuery["from"]) limit = int(tableQuery["to"]) sortColumn = tableQuery["sortColumn"] sortOrder = tableQuery["sortOrder"] filterName = tableQuery["filterName"] myQuery = SpoolModel.select().offset(offset).limit(limit) if (filterName == "hideEmptySpools"): myQuery = myQuery.where((SpoolModel.remainingWeight > 0) | (SpoolModel.remainingWeight == None)) # elif (filterName == "onlyFailed"): # myQuery = myQuery.where(PrintJobModel.printStatusResult != "success") if ("displayName" == sortColumn): if ("desc" == sortOrder): myQuery = myQuery.order_by(SpoolModel.displayName.desc()) else: myQuery = myQuery.order_by(SpoolModel.displayName) if ("lastUse" == sortColumn): if ("desc" == sortOrder): myQuery = myQuery.order_by(SpoolModel.lastUse.desc()) else: myQuery = myQuery.order_by(SpoolModel.lastUse) if ("firstUse" == sortColumn): if ("desc" == sortOrder): myQuery = myQuery.order_by(SpoolModel.firstUse.desc()) else: myQuery = myQuery.order_by(SpoolModel.firstUse) if ("remaining" == sortColumn): if ("desc" == sortOrder): myQuery = myQuery.order_by(SpoolModel.remainingWeight.desc()) else: myQuery = myQuery.order_by(SpoolModel.remainingWeight) if ("material" == sortColumn): if ("desc" == sortOrder): myQuery = myQuery.order_by(SpoolModel.material.desc()) else: myQuery = myQuery.order_by(SpoolModel.material) return myQuery
def countSpoolsByQuery(self, tableQuery): filterName = tableQuery["filterName"] myQuery = SpoolModel.select() # if (filterName == "onlySuccess"): # myQuery = myQuery.where(PrintJobModel.printStatusResult == "success") # elif (filterName == "onlyFailed"): # myQuery = myQuery.where(PrintJobModel.printStatusResult != "success") return myQuery.count()
def loadCatalogLabels(self, tableQuery): result = set() result.add("") myQuery = SpoolModel.select(SpoolModel.labels).distinct() for spool in myQuery: value = spool.labels if (value != None): spoolLabels = json.loads(value) for singleLabel in spoolLabels: result.add(singleLabel) return result
def loadSpoolTemplateSpool(self): return SpoolModel.select().where(SpoolModel.isTemplate == True)
def loadSpool(self, databaseId): try: return SpoolModel.get_by_id(databaseId) except Exception as e: return None pass