From 599db7296fd8db25e90b249b45151f308882b18b Mon Sep 17 00:00:00 2001 From: Mary Hipp Date: Thu, 15 Aug 2024 16:07:32 -0400 Subject: [PATCH] export only user style presets --- invokeai/app/api/routers/style_presets.py | 2 +- .../style_preset_records_base.py | 3 ++- .../style_preset_records_sqlite.py | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/invokeai/app/api/routers/style_presets.py b/invokeai/app/api/routers/style_presets.py index 5c1759d73b..aa0296507c 100644 --- a/invokeai/app/api/routers/style_presets.py +++ b/invokeai/app/api/routers/style_presets.py @@ -245,7 +245,7 @@ async def export_style_presets(): # Write the header writer.writerow(["name", "prompt", "negative_prompt"]) - style_presets = ApiDependencies.invoker.services.style_preset_records.get_many() + style_presets = ApiDependencies.invoker.services.style_preset_records.get_many(type=PresetType.User) for preset in style_presets: writer.writerow([preset.name, preset.preset_data.positive_prompt, preset.preset_data.negative_prompt]) diff --git a/invokeai/app/services/style_preset_records/style_preset_records_base.py b/invokeai/app/services/style_preset_records/style_preset_records_base.py index 282388c7e4..a4dee2fbbd 100644 --- a/invokeai/app/services/style_preset_records/style_preset_records_base.py +++ b/invokeai/app/services/style_preset_records/style_preset_records_base.py @@ -1,6 +1,7 @@ from abc import ABC, abstractmethod from invokeai.app.services.style_preset_records.style_preset_records_common import ( + PresetType, StylePresetChanges, StylePresetRecordDTO, StylePresetWithoutId, @@ -36,6 +37,6 @@ class StylePresetRecordsStorageBase(ABC): pass @abstractmethod - def get_many(self) -> list[StylePresetRecordDTO]: + def get_many(self, type: PresetType | None = None) -> list[StylePresetRecordDTO]: """Gets many workflows.""" pass diff --git a/invokeai/app/services/style_preset_records/style_preset_records_sqlite.py b/invokeai/app/services/style_preset_records/style_preset_records_sqlite.py index 952cf35ba9..657d73b3bd 100644 --- a/invokeai/app/services/style_preset_records/style_preset_records_sqlite.py +++ b/invokeai/app/services/style_preset_records/style_preset_records_sqlite.py @@ -5,6 +5,7 @@ from invokeai.app.services.invoker import Invoker from invokeai.app.services.shared.sqlite.sqlite_database import SqliteDatabase from invokeai.app.services.style_preset_records.style_preset_records_base import StylePresetRecordsStorageBase from invokeai.app.services.style_preset_records.style_preset_records_common import ( + PresetType, StylePresetChanges, StylePresetNotFoundError, StylePresetRecordDTO, @@ -159,19 +160,25 @@ class SqliteStylePresetRecordsStorage(StylePresetRecordsStorageBase): self._lock.release() return None - def get_many( - self, - ) -> list[StylePresetRecordDTO]: + def get_many(self, type: PresetType | None = None) -> list[StylePresetRecordDTO]: try: self._lock.acquire() main_query = """ SELECT * FROM style_presets - ORDER BY LOWER(name) ASC """ - self._cursor.execute(main_query) + if type is not None: + main_query += "WHERE type = ? " + + main_query += "ORDER BY LOWER(name) ASC" + + if type is not None: + self._cursor.execute(main_query, (type,)) + else: + self._cursor.execute(main_query) + rows = self._cursor.fetchall() style_presets = [StylePresetRecordDTO.from_dict(dict(row)) for row in rows]