# This is an autogenerated file from the command "q2 generate_hq_api" and will be overwritten if run again
"""
DataSet models for UpdateUserLogon.
These typed dataclass models represent the tables and columns within the
DataSet parameters for the UpdateUserLogon 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 UpdateUserLogon
q2_user_logon = UpdateUserLogon.Q2UserLogon(
user_id=1,
login_name="...",
user_password="...",
ui_source_id=1,
status=1,
create_date="...",
auto_generated=True,
password_change_required=True,
password_has_never_changed=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 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: int = 0
status_reason: Optional[str] = None
last_failed: Optional[str] = None
create_date: str = ""
num_invalid_attempts: Optional[int] = None
auto_generated: bool = False
deleted_date: Optional[str] = None
sync_pwd_user_logon_id: Optional[int] = None
csr_assist_policy_id: Optional[int] = None
csr_assist_admin_user_id: Optional[int] = None
mla_challenge_code: Optional[str] = None
password_change_required: bool = False
password_has_never_changed: bool = False
num_invalid_oob_attempts: Optional[int] = None
one_time_auth_code: Optional[str] = None
one_time_auth_code_expiration_date: Optional[str] = None
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"],
["CreateDate", "create_date"],
["NumInvalidAttempts", "num_invalid_attempts"],
["AutoGenerated", "auto_generated"],
["DeletedDate", "deleted_date"],
["SyncPwdUserLogonID", "sync_pwd_user_logon_id"],
["CsrAssistPolicyID", "csr_assist_policy_id"],
["CsrAssistAdminUserID", "csr_assist_admin_user_id"],
["MlaChallengeCode", "mla_challenge_code"],
["PasswordChangeRequired", "password_change_required"],
["PasswordHasNeverChanged", "password_has_never_changed"],
["NumInvalidOobAttempts", "num_invalid_oob_attempts"],
["OneTimeAuthCode", "one_time_auth_code"],
["OneTimeAuthCodeExpirationDate", "one_time_auth_code_expiration_date"],
]
[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.create_date,
self.num_invalid_attempts,
self.auto_generated,
self.deleted_date,
self.sync_pwd_user_logon_id,
self.csr_assist_policy_id,
self.csr_assist_admin_user_id,
self.mla_challenge_code,
self.password_change_required,
self.password_has_never_changed,
self.num_invalid_oob_attempts,
self.one_time_auth_code,
self.one_time_auth_code_expiration_date,
]
_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,
"create_date": str,
"num_invalid_attempts": int,
"auto_generated": bool,
"deleted_date": str,
"sync_pwd_user_logon_id": int,
"csr_assist_policy_id": int,
"csr_assist_admin_user_id": int,
"mla_challenge_code": str,
"password_change_required": bool,
"password_has_never_changed": bool,
"num_invalid_oob_attempts": int,
"one_time_auth_code": str,
"one_time_auth_code_expiration_date": str,
}
[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]
def build_dal_user_logon_dataset(
q2_user_logon: Optional[Q2UserLogon | list[Q2UserLogon]] = None,
) -> DataSetBuilder:
"""
Build the dal_user_logon DataSet parameter for UpdateUserLogon.
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 'dal_user_logon' parameter
"""
dataset = DataSetBuilder("DalUserLogon")
# 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)
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)