# This is an autogenerated file from the command "q2 generate_hq_api" and will be overwritten if run again
"""
DataSet models for UpdateAdminUser.
These typed dataclass models represent the tables and columns within the
DataSet parameters for the UpdateAdminUser HQ operation.
IMPORTANT: Update operations require a GET first to populate the original_record
field. HQ uses the unchanged row for optimistic concurrency checking.
Usage::
from q2_sdk.hq.hq_api.backoffice import UpdateAdminUser
q2_user = UpdateAdminUser.Q2User(
create_date="...",
)
q2_address = UpdateAdminUser.Q2Address(
street_address1="...",
city="...",
state="...",
postal_code="...",
address_type=1,
)
q2_email = UpdateAdminUser.Q2Email(
email_address="...",
user_id=1,
)
q2_phone = UpdateAdminUser.Q2Phone(
country_id=1,
city_or_area_code="...",
local_number="...",
phone_type="...",
)
q2_user_logon = UpdateAdminUser.Q2UserLogon(
user_id=1,
login_name="...",
user_password="...",
ui_source_id=1,
create_date="...",
group_id=1,
authentication_type_id=1,
)
q2_user_fi = UpdateAdminUser.Q2UserFI(
fiid=1,
user_id=1,
)
q2_admin_auth_token = UpdateAdminUser.Q2AdminAuthToken(
user_id=1,
create_date="...",
serial="...",
)
q2_admin_user_property_view = UpdateAdminUser.Q2AdminUserPropertyView(
user_property_data_id=1,
property_name="...",
property_long_name="...",
property_data_type="...",
is_group_property=True,
is_user_property=True,
)
"""
from __future__ import annotations
import copy
from dataclasses import dataclass, field
from typing import Any, ClassVar, Optional
from q2_sdk.hq.models.dataset_builder import DataSetBuilder, DataSetTable, RowState
[docs]
@dataclass
class Q2User:
"""
Represents a row in the Q2_User table.
"""
user_id: int = -1
first_name: Optional[str] = None
middle_name: Optional[str] = None
last_name: Optional[str] = None
salutation: Optional[str] = None
suffix: Optional[str] = None
ssn: Optional[str] = None
create_date: str = ""
deleted_date: Optional[str] = None
default_email_id: Optional[int] = None
employee_id: Optional[str] = None
default_address_id: Optional[int] = None
original_record: Optional["Q2User"] = field(default=None, repr=False)
[docs]
@staticmethod
def get_columns() -> list[list[str]]:
"""Returns [[HqColumnName, pythonAttrName], ...] mapping."""
return [
["UserID", "user_id"],
["FirstName", "first_name"],
["MiddleName", "middle_name"],
["LastName", "last_name"],
["Salutation", "salutation"],
["Suffix", "suffix"],
["SSN", "ssn"],
["CreateDate", "create_date"],
["DeletedDate", "deleted_date"],
["DefaultEmailID", "default_email_id"],
["EmployeeID", "employee_id"],
["DefaultAddressID", "default_address_id"],
]
[docs]
def to_row_values(self) -> list[Any]:
"""Returns column values in get_columns() order."""
return [
self.user_id,
self.first_name,
self.middle_name,
self.last_name,
self.salutation,
self.suffix,
self.ssn,
self.create_date,
self.deleted_date,
self.default_email_id,
self.employee_id,
self.default_address_id,
]
_COLUMN_TYPES: ClassVar[dict[str, type]] = {
"user_id": int,
"first_name": str,
"middle_name": str,
"last_name": str,
"salutation": str,
"suffix": str,
"ssn": str,
"create_date": str,
"deleted_date": str,
"default_email_id": int,
"employee_id": str,
"default_address_id": int,
}
[docs]
@classmethod
def from_hq_response(cls, row_elem) -> "Q2User":
"""Parse an lxml row element into this model with original_record set."""
kwargs: dict[str, Any] = {}
for hq_name, python_name in cls.get_columns():
child = row_elem.find(hq_name)
if child is not None and child.text is not None:
target_type = cls._COLUMN_TYPES.get(python_name, str)
if target_type is bool:
kwargs[python_name] = child.text.lower() in ("true", "1")
elif target_type in (int, float):
try:
kwargs[python_name] = target_type(child.text)
except (ValueError, TypeError):
kwargs[python_name] = child.text
else:
kwargs[python_name] = child.text
instance = cls(**kwargs)
instance.original_record = copy.deepcopy(instance)
return instance
[docs]
@dataclass
class Q2Address:
"""
Represents a row in the Q2_Address table.
"""
address_id: int = -1
street_address1: str = ""
street_address2: Optional[str] = None
city: str = ""
state: str = ""
postal_code: str = ""
address_type: int = 0
user_id: Optional[int] = None
original_record: Optional["Q2Address"] = field(default=None, repr=False)
[docs]
@staticmethod
def get_columns() -> list[list[str]]:
"""Returns [[HqColumnName, pythonAttrName], ...] mapping."""
return [
["AddressID", "address_id"],
["StreetAddress1", "street_address1"],
["StreetAddress2", "street_address2"],
["City", "city"],
["State", "state"],
["PostalCode", "postal_code"],
["AddressType", "address_type"],
["UserID", "user_id"],
]
[docs]
def to_row_values(self) -> list[Any]:
"""Returns column values in get_columns() order."""
return [
self.address_id,
self.street_address1,
self.street_address2,
self.city,
self.state,
self.postal_code,
self.address_type,
self.user_id,
]
_COLUMN_TYPES: ClassVar[dict[str, type]] = {
"address_id": int,
"street_address1": str,
"street_address2": str,
"city": str,
"state": str,
"postal_code": str,
"address_type": int,
"user_id": int,
}
[docs]
@classmethod
def from_hq_response(cls, row_elem) -> "Q2Address":
"""Parse an lxml row element into this model with original_record set."""
kwargs: dict[str, Any] = {}
for hq_name, python_name in cls.get_columns():
child = row_elem.find(hq_name)
if child is not None and child.text is not None:
target_type = cls._COLUMN_TYPES.get(python_name, str)
if target_type is bool:
kwargs[python_name] = child.text.lower() in ("true", "1")
elif target_type in (int, float):
try:
kwargs[python_name] = target_type(child.text)
except (ValueError, TypeError):
kwargs[python_name] = child.text
else:
kwargs[python_name] = child.text
instance = cls(**kwargs)
instance.original_record = copy.deepcopy(instance)
return instance
[docs]
@dataclass
class Q2Email:
"""
Represents a row in the Q2_Email table.
"""
email_id: int = -1
email_address: str = ""
user_id: int = 0
original_record: Optional["Q2Email"] = field(default=None, repr=False)
[docs]
@staticmethod
def get_columns() -> list[list[str]]:
"""Returns [[HqColumnName, pythonAttrName], ...] mapping."""
return [
["EmailID", "email_id"],
["EmailAddress", "email_address"],
["UserID", "user_id"],
]
[docs]
def to_row_values(self) -> list[Any]:
"""Returns column values in get_columns() order."""
return [
self.email_id,
self.email_address,
self.user_id,
]
_COLUMN_TYPES: ClassVar[dict[str, type]] = {
"email_id": int,
"email_address": str,
"user_id": int,
}
[docs]
@classmethod
def from_hq_response(cls, row_elem) -> "Q2Email":
"""Parse an lxml row element into this model with original_record set."""
kwargs: dict[str, Any] = {}
for hq_name, python_name in cls.get_columns():
child = row_elem.find(hq_name)
if child is not None and child.text is not None:
target_type = cls._COLUMN_TYPES.get(python_name, str)
if target_type is bool:
kwargs[python_name] = child.text.lower() in ("true", "1")
elif target_type in (int, float):
try:
kwargs[python_name] = target_type(child.text)
except (ValueError, TypeError):
kwargs[python_name] = child.text
else:
kwargs[python_name] = child.text
instance = cls(**kwargs)
instance.original_record = copy.deepcopy(instance)
return instance
[docs]
@dataclass
class Q2Phone:
"""
Represents a row in the Q2_Phone table.
"""
phone_id: int = -1
country_id: int = 0
city_or_area_code: str = ""
local_number: str = ""
extension: Optional[str] = None
phone_type: str = ""
user_id: Optional[int] = None
address_id: Optional[int] = None
original_record: Optional["Q2Phone"] = field(default=None, repr=False)
[docs]
@staticmethod
def get_columns() -> list[list[str]]:
"""Returns [[HqColumnName, pythonAttrName], ...] mapping."""
return [
["PhoneID", "phone_id"],
["CountryID", "country_id"],
["CityOrAreaCode", "city_or_area_code"],
["LocalNumber", "local_number"],
["Extension", "extension"],
["PhoneType", "phone_type"],
["UserID", "user_id"],
["AddressID", "address_id"],
]
[docs]
def to_row_values(self) -> list[Any]:
"""Returns column values in get_columns() order."""
return [
self.phone_id,
self.country_id,
self.city_or_area_code,
self.local_number,
self.extension,
self.phone_type,
self.user_id,
self.address_id,
]
_COLUMN_TYPES: ClassVar[dict[str, type]] = {
"phone_id": int,
"country_id": int,
"city_or_area_code": str,
"local_number": str,
"extension": str,
"phone_type": str,
"user_id": int,
"address_id": int,
}
[docs]
@classmethod
def from_hq_response(cls, row_elem) -> "Q2Phone":
"""Parse an lxml row element into this model with original_record set."""
kwargs: dict[str, Any] = {}
for hq_name, python_name in cls.get_columns():
child = row_elem.find(hq_name)
if child is not None and child.text is not None:
target_type = cls._COLUMN_TYPES.get(python_name, str)
if target_type is bool:
kwargs[python_name] = child.text.lower() in ("true", "1")
elif target_type in (int, float):
try:
kwargs[python_name] = target_type(child.text)
except (ValueError, TypeError):
kwargs[python_name] = child.text
else:
kwargs[python_name] = child.text
instance = cls(**kwargs)
instance.original_record = copy.deepcopy(instance)
return instance
[docs]
@dataclass
class Q2UserLogon:
"""
Represents a row in the Q2_UserLogon table.
"""
user_logon_id: int = -1
user_id: int = 0
login_name: str = ""
user_password: str = ""
ui_source_id: int = 0
last_change: Optional[str] = None
last_logon: Optional[str] = None
status: Optional[int] = None
status_reason: Optional[str] = None
last_failed: Optional[str] = None
host_user: Optional[str] = None
host_pwd: Optional[str] = None
create_date: str = ""
num_invalid_attempts: Optional[int] = None
group_id: int = 0
deleted_date: Optional[str] = None
authentication_type_id: int = 0
original_record: Optional["Q2UserLogon"] = field(default=None, repr=False)
[docs]
@staticmethod
def get_columns() -> list[list[str]]:
"""Returns [[HqColumnName, pythonAttrName], ...] mapping."""
return [
["UserLogonID", "user_logon_id"],
["UserID", "user_id"],
["LoginName", "login_name"],
["UserPassword", "user_password"],
["UISourceID", "ui_source_id"],
["LastChange", "last_change"],
["LastLogon", "last_logon"],
["Status", "status"],
["StatusReason", "status_reason"],
["LastFailed", "last_failed"],
["HostUser", "host_user"],
["HostPwd", "host_pwd"],
["CreateDate", "create_date"],
["NumInvalidAttempts", "num_invalid_attempts"],
["GroupID", "group_id"],
["DeletedDate", "deleted_date"],
["AuthenticationTypeID", "authentication_type_id"],
]
[docs]
def to_row_values(self) -> list[Any]:
"""Returns column values in get_columns() order."""
return [
self.user_logon_id,
self.user_id,
self.login_name,
self.user_password,
self.ui_source_id,
self.last_change,
self.last_logon,
self.status,
self.status_reason,
self.last_failed,
self.host_user,
self.host_pwd,
self.create_date,
self.num_invalid_attempts,
self.group_id,
self.deleted_date,
self.authentication_type_id,
]
_COLUMN_TYPES: ClassVar[dict[str, type]] = {
"user_logon_id": int,
"user_id": int,
"login_name": str,
"user_password": str,
"ui_source_id": int,
"last_change": str,
"last_logon": str,
"status": int,
"status_reason": str,
"last_failed": str,
"host_user": str,
"host_pwd": str,
"create_date": str,
"num_invalid_attempts": int,
"group_id": int,
"deleted_date": str,
"authentication_type_id": int,
}
[docs]
@classmethod
def from_hq_response(cls, row_elem) -> "Q2UserLogon":
"""Parse an lxml row element into this model with original_record set."""
kwargs: dict[str, Any] = {}
for hq_name, python_name in cls.get_columns():
child = row_elem.find(hq_name)
if child is not None and child.text is not None:
target_type = cls._COLUMN_TYPES.get(python_name, str)
if target_type is bool:
kwargs[python_name] = child.text.lower() in ("true", "1")
elif target_type in (int, float):
try:
kwargs[python_name] = target_type(child.text)
except (ValueError, TypeError):
kwargs[python_name] = child.text
else:
kwargs[python_name] = child.text
instance = cls(**kwargs)
instance.original_record = copy.deepcopy(instance)
return instance
[docs]
@dataclass
class Q2UserFI:
"""
Represents a row in the Q2_UserFI table.
"""
user_fiid: int = -1
fiid: int = 0
user_id: int = 0
original_record: Optional["Q2UserFI"] = field(default=None, repr=False)
[docs]
@staticmethod
def get_columns() -> list[list[str]]:
"""Returns [[HqColumnName, pythonAttrName], ...] mapping."""
return [
["UserFIID", "user_fiid"],
["FIID", "fiid"],
["UserID", "user_id"],
]
[docs]
def to_row_values(self) -> list[Any]:
"""Returns column values in get_columns() order."""
return [
self.user_fiid,
self.fiid,
self.user_id,
]
_COLUMN_TYPES: ClassVar[dict[str, type]] = {
"user_fiid": int,
"fiid": int,
"user_id": int,
}
[docs]
@classmethod
def from_hq_response(cls, row_elem) -> "Q2UserFI":
"""Parse an lxml row element into this model with original_record set."""
kwargs: dict[str, Any] = {}
for hq_name, python_name in cls.get_columns():
child = row_elem.find(hq_name)
if child is not None and child.text is not None:
target_type = cls._COLUMN_TYPES.get(python_name, str)
if target_type is bool:
kwargs[python_name] = child.text.lower() in ("true", "1")
elif target_type in (int, float):
try:
kwargs[python_name] = target_type(child.text)
except (ValueError, TypeError):
kwargs[python_name] = child.text
else:
kwargs[python_name] = child.text
instance = cls(**kwargs)
instance.original_record = copy.deepcopy(instance)
return instance
[docs]
@dataclass
class Q2AdminAuthToken:
"""
Represents a row in the Q2_AdminAuthToken table.
"""
admin_auth_token_id: int = -1
user_id: int = 0
create_date: str = ""
deleted_date: Optional[str] = None
serial: str = ""
first_use: Optional[str] = None
original_record: Optional["Q2AdminAuthToken"] = field(default=None, repr=False)
[docs]
@staticmethod
def get_columns() -> list[list[str]]:
"""Returns [[HqColumnName, pythonAttrName], ...] mapping."""
return [
["AdminAuthTokenID", "admin_auth_token_id"],
["UserID", "user_id"],
["CreateDate", "create_date"],
["DeletedDate", "deleted_date"],
["Serial", "serial"],
["FirstUse", "first_use"],
]
[docs]
def to_row_values(self) -> list[Any]:
"""Returns column values in get_columns() order."""
return [
self.admin_auth_token_id,
self.user_id,
self.create_date,
self.deleted_date,
self.serial,
self.first_use,
]
_COLUMN_TYPES: ClassVar[dict[str, type]] = {
"admin_auth_token_id": int,
"user_id": int,
"create_date": str,
"deleted_date": str,
"serial": str,
"first_use": str,
}
[docs]
@classmethod
def from_hq_response(cls, row_elem) -> "Q2AdminAuthToken":
"""Parse an lxml row element into this model with original_record set."""
kwargs: dict[str, Any] = {}
for hq_name, python_name in cls.get_columns():
child = row_elem.find(hq_name)
if child is not None and child.text is not None:
target_type = cls._COLUMN_TYPES.get(python_name, str)
if target_type is bool:
kwargs[python_name] = child.text.lower() in ("true", "1")
elif target_type in (int, float):
try:
kwargs[python_name] = target_type(child.text)
except (ValueError, TypeError):
kwargs[python_name] = child.text
else:
kwargs[python_name] = child.text
instance = cls(**kwargs)
instance.original_record = copy.deepcopy(instance)
return instance
[docs]
@dataclass
class Q2AdminUserPropertyView:
"""
Represents a row in the Q2_AdminUserPropertyView table.
"""
user_property_data_id: int = 0
group_id: Optional[int] = None
fiid: Optional[int] = None
ui_source_id: Optional[int] = None
user_id: Optional[int] = None
property_id: Optional[int] = None
property_name: str = ""
property_long_name: str = ""
property_data_type: str = ""
property_value: Optional[str] = None
weight: Optional[int] = None
is_group_property: bool = False
is_user_property: bool = False
original_record: Optional["Q2AdminUserPropertyView"] = field(
default=None, repr=False
)
[docs]
@staticmethod
def get_columns() -> list[list[str]]:
"""Returns [[HqColumnName, pythonAttrName], ...] mapping."""
return [
["UserPropertyDataID", "user_property_data_id"],
["GroupID", "group_id"],
["FIID", "fiid"],
["UISourceID", "ui_source_id"],
["UserID", "user_id"],
["PropertyID", "property_id"],
["PropertyName", "property_name"],
["PropertyLongName", "property_long_name"],
["PropertyDataType", "property_data_type"],
["PropertyValue", "property_value"],
["Weight", "weight"],
["IsGroupProperty", "is_group_property"],
["IsUserProperty", "is_user_property"],
]
[docs]
def to_row_values(self) -> list[Any]:
"""Returns column values in get_columns() order."""
return [
self.user_property_data_id,
self.group_id,
self.fiid,
self.ui_source_id,
self.user_id,
self.property_id,
self.property_name,
self.property_long_name,
self.property_data_type,
self.property_value,
self.weight,
self.is_group_property,
self.is_user_property,
]
_COLUMN_TYPES: ClassVar[dict[str, type]] = {
"user_property_data_id": int,
"group_id": int,
"fiid": int,
"ui_source_id": int,
"user_id": int,
"property_id": int,
"property_name": str,
"property_long_name": str,
"property_data_type": str,
"property_value": str,
"weight": int,
"is_group_property": bool,
"is_user_property": bool,
}
[docs]
@classmethod
def from_hq_response(cls, row_elem) -> "Q2AdminUserPropertyView":
"""Parse an lxml row element into this model with original_record set."""
kwargs: dict[str, Any] = {}
for hq_name, python_name in cls.get_columns():
child = row_elem.find(hq_name)
if child is not None and child.text is not None:
target_type = cls._COLUMN_TYPES.get(python_name, str)
if target_type is bool:
kwargs[python_name] = child.text.lower() in ("true", "1")
elif target_type in (int, float):
try:
kwargs[python_name] = target_type(child.text)
except (ValueError, TypeError):
kwargs[python_name] = child.text
else:
kwargs[python_name] = child.text
instance = cls(**kwargs)
instance.original_record = copy.deepcopy(instance)
return instance
[docs]
def build_daue_dataset(
q2_user: Optional[Q2User | list[Q2User]] = None,
q2_address: Optional[Q2Address | list[Q2Address]] = None,
q2_email: Optional[Q2Email | list[Q2Email]] = None,
q2_phone: Optional[Q2Phone | list[Q2Phone]] = None,
q2_user_logon: Optional[Q2UserLogon | list[Q2UserLogon]] = None,
q2_user_fi: Optional[Q2UserFI | list[Q2UserFI]] = None,
q2_admin_auth_token: Optional[Q2AdminAuthToken | list[Q2AdminAuthToken]] = None,
) -> DataSetBuilder:
"""
Build the daue DataSet parameter for UpdateAdminUser.
For update operations, each model instance should have its original_record
set to the pre-modification state (from a prior GET call).
For add operations, set auto-increment ID fields to negative values.
:returns: DataSetBuilder ready to pass as the 'daue' parameter
"""
dataset = DataSetBuilder("DalAdmin_UserEdit")
# Q2_User
q2_user_cols = [col[0] for col in Q2User.get_columns()]
q2_user_table = dataset.add_table("Q2_User", q2_user_cols)
_add_rows_to_table(q2_user_table, q2_user)
# Q2_Address
q2_address_cols = [col[0] for col in Q2Address.get_columns()]
q2_address_table = dataset.add_table("Q2_Address", q2_address_cols)
_add_rows_to_table(q2_address_table, q2_address)
# Q2_Email
q2_email_cols = [col[0] for col in Q2Email.get_columns()]
q2_email_table = dataset.add_table("Q2_Email", q2_email_cols)
_add_rows_to_table(q2_email_table, q2_email)
# Q2_Phone
q2_phone_cols = [col[0] for col in Q2Phone.get_columns()]
q2_phone_table = dataset.add_table("Q2_Phone", q2_phone_cols)
_add_rows_to_table(q2_phone_table, q2_phone)
# Q2_UserLogon
q2_user_logon_cols = [col[0] for col in Q2UserLogon.get_columns()]
q2_user_logon_table = dataset.add_table("Q2_UserLogon", q2_user_logon_cols)
_add_rows_to_table(q2_user_logon_table, q2_user_logon)
# Q2_UserFI
q2_user_fi_cols = [col[0] for col in Q2UserFI.get_columns()]
q2_user_fi_table = dataset.add_table("Q2_UserFI", q2_user_fi_cols)
_add_rows_to_table(q2_user_fi_table, q2_user_fi)
# Q2_AdminAuthToken
q2_admin_auth_token_cols = [col[0] for col in Q2AdminAuthToken.get_columns()]
q2_admin_auth_token_table = dataset.add_table(
"Q2_AdminAuthToken", q2_admin_auth_token_cols
)
_add_rows_to_table(q2_admin_auth_token_table, q2_admin_auth_token)
return dataset
[docs]
def build_admin_user_properties_dataset(
q2_admin_user_property_view: Optional[
Q2AdminUserPropertyView | list[Q2AdminUserPropertyView]
] = None,
) -> DataSetBuilder:
"""
Build the admin_user_properties DataSet parameter for UpdateAdminUser.
For update operations, each model instance should have its original_record
set to the pre-modification state (from a prior GET call).
For add operations, set auto-increment ID fields to negative values.
:returns: DataSetBuilder ready to pass as the 'admin_user_properties' parameter
"""
dataset = DataSetBuilder("DalAdmin_AdminUserPropertyView")
# Q2_AdminUserPropertyView
q2_admin_user_property_view_cols = [
col[0] for col in Q2AdminUserPropertyView.get_columns()
]
q2_admin_user_property_view_table = dataset.add_table(
"Q2_AdminUserPropertyView", q2_admin_user_property_view_cols
)
_add_rows_to_table(q2_admin_user_property_view_table, q2_admin_user_property_view)
return dataset
def _add_rows_to_table(
table: DataSetTable,
records: Optional[Any | list],
) -> None:
"""
Add rows to a DataSetTable from one or more model instances.
Handles Modified+Unchanged pairs (for updates), Added rows (for inserts),
and Deleted rows automatically based on each record's original_record field.
"""
if records is None:
return
if not isinstance(records, list):
records = [records]
for record in records:
values = record.to_row_values()
if record.original_record is not None:
# Update: emit Modified row (new values) + Unchanged row (original)
table.add_row(RowState.MODIFIED, values)
table.add_row(RowState.UNCHANGED, record.original_record.to_row_values())
else:
# Add: emit Added row (new record)
table.add_row(RowState.ADDED, values)