from argparse import _SubParsersAction
from functools import partial
from typing import List
from lxml.objectify import IntElement, StringElement, BoolElement
from .db_object import DbObject
from .representation_row_base import RepresentationRowBase
[docs]
class UiSelectionRow(RepresentationRowBase):
UiSelectionID: IntElement = "UiSelectionID"
ShortName: StringElement = "ShortName"
Description: StringElement = "Description"
UiLanguageID: IntElement = "UiLanguageID"
UiStyleSetID: IntElement = "UiStyleSetID"
UuxThemeID: IntElement = "UuxThemeID"
IsCentralTheme: BoolElement = "IsCentralTheme"
NavigationID: IntElement = "NavigationID"
[docs]
class UiSelection(DbObject):
GET_BY_NAME_KEY = "ShortName"
NAME = "UiSelection ShortName"
REPRESENTATION_ROW_CLASS = UiSelectionRow
[docs]
def add_arguments(self, parser: _SubParsersAction):
subparser = parser.add_parser("get_ui_selection")
subparser.set_defaults(parser="get")
subparser.set_defaults(func=partial(self.get, serialize_for_cli=True))
subparser = parser.add_parser("get_ui_selection_by_name")
subparser.set_defaults(parser="get_by_name")
subparser.set_defaults(func=partial(self.get_by_name, serialize_for_cli=True))
subparser.add_argument("name", help="Q2_UiSelection.ShortName")
[docs]
async def get(self, serialize_for_cli=False) -> List[UiSelectionRow]:
response = await self.call_hq("sdk_GetUiSelection")
if serialize_for_cli:
response = self._serialize_get(response)
return response
[docs]
async def get_by_name(self, name, **kwargs) -> UiSelectionRow:
serialize_for_cli = kwargs.get("serialize_for_cli", False)
response = await super().get_by_name(name)
if serialize_for_cli:
response = self._serialize_get([response])
return response
def _serialize_get(self, results):
columns = [
"UiSelectionID",
"ShortName",
"Description",
"UiLanguageID",
"IsCentralTheme",
"NavigationID",
]
response = self.serialize_for_cli(results, columns)
return response