from typing import Unpack
from q2_sdk.core.install_steps.base import (
InstallStep,
InstallStepAttribute,
InstallStepArguments,
)
from q2_sdk.hq.db.ui_text import UiText as UiTextDbObj
[docs]
class UiTextElement(InstallStep):
"""Interacts with the Q2_UiText and Q2_UiTextElement tables"""
def __init__(
self,
short_name: str,
description: str,
text_value: str,
device_id=1,
language="USEnglish",
**kwargs: Unpack[InstallStepArguments],
):
super().__init__(**kwargs)
self.short_name = InstallStepAttribute(short_name)
self.description = InstallStepAttribute(description)
self.text_value = InstallStepAttribute(
text_value, is_editable=True, use_textarea=True
)
self.device_id = InstallStepAttribute(device_id, is_hidden=True)
self.language = InstallStepAttribute(language, is_hidden=True)
self.prefix = None
[docs]
async def install(self):
await super().install()
assert self.prefix is not None, (
"DBPlans must set a ui_text_prefix to install UiTextElements"
)
prefixed_short_name = f"{self.prefix}/{self.short_name.value}"
await UiTextDbObj(self.logger, hq_credentials=self.hq_credentials).create(
prefixed_short_name,
self.description.value,
self.text_value.value,
self.device_id.value,
self.language.value,
)
[docs]
async def uninstall(self):
assert self.prefix is not None, (
"DBPlans must set a ui_text_prefix to uninstall UiTextElements"
)
prefixed_short_name = f"{self.prefix}/{self.short_name.value}"
await UiTextDbObj(self.logger, hq_credentials=self.hq_credentials).delete(
prefixed_short_name
)