QualityDatabaseHandler.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from UM.Settings.SQLQueryFactory import SQLQueryFactory, metadata_type
  2. from UM.Settings.DatabaseContainerMetadataController import DatabaseMetadataContainerController
  3. from UM.Settings.InstanceContainer import InstanceContainer
  4. class QualityDatabaseHandler(DatabaseMetadataContainerController):
  5. """The Database handler for Quality containers"""
  6. def __init__(self):
  7. super().__init__(SQLQueryFactory(table = "qualities",
  8. fields = {
  9. "id": "text",
  10. "name": "text",
  11. "quality_type": "text",
  12. "material": "text",
  13. "variant": "text",
  14. "global_quality": "bool",
  15. "definition": "text",
  16. "version": "text",
  17. "setting_version": "text"
  18. }))
  19. self.container_type = InstanceContainer
  20. def groomMetadata(self, metadata: metadata_type) -> metadata_type:
  21. """
  22. Ensures that the metadata is in the order of the field keys and has the right size.
  23. if the metadata doesn't contains a key which is stored in the DB it will add it as
  24. an empty string. Key, value pairs that are not stored in the DB are dropped.
  25. If the `global_quality` isn't set it well default to 'False'
  26. :param metadata: The container metadata
  27. """
  28. if "global_quality" not in metadata:
  29. metadata["global_quality"] = "False"
  30. return super().groomMetadata(metadata)