Source code for q2_sdk.hq.hq_api.backoffice.SetCsrNotifications_models

# This is an autogenerated file from the command "q2 generate_hq_api" and will be overwritten if run again
"""
DataSet models for SetCsrNotifications.

These typed dataclass models represent the tables and columns within the
DataSet parameters for the SetCsrNotifications 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 SetCsrNotifications

    q2_system_alert_view = SetCsrNotifications.Q2SystemAlertView(
        system_alert_id=1,
        action_id=1,
        target_address="...",
        enabled=True,
        error_return_code=1,
        error_return_code_short_name="...",
        error_return_code_description="...",
        audit_action_short_name="...",
        audit_action_description="...",
        audit_category_short_name="...",
        audit_category_description="...",
    )
"""

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 Q2SystemAlertView: """ Represents a row in the Q2_SystemAlertView table. """ system_alert_id: int = 0 action_id: int = 0 target_address: str = "" enabled: bool = False error_return_code: int = 0 error_return_code_short_name: str = "" error_return_code_description: str = "" audit_action_short_name: str = "" audit_action_description: str = "" audit_category_short_name: str = "" audit_category_description: str = "" original_record: Optional["Q2SystemAlertView"] = field(default=None, repr=False)
[docs] @staticmethod def get_columns() -> list[list[str]]: """Returns [[HqColumnName, pythonAttrName], ...] mapping.""" return [ ["SystemAlertID", "system_alert_id"], ["ActionID", "action_id"], ["TargetAddress", "target_address"], ["Enabled", "enabled"], ["ErrorReturnCode", "error_return_code"], ["ErrorReturnCodeShortName", "error_return_code_short_name"], ["ErrorReturnCodeDescription", "error_return_code_description"], ["AuditActionShortName", "audit_action_short_name"], ["AuditActionDescription", "audit_action_description"], ["AuditCategoryShortName", "audit_category_short_name"], ["AuditCategoryDescription", "audit_category_description"], ]
[docs] def to_row_values(self) -> list[Any]: """Returns column values in get_columns() order.""" return [ self.system_alert_id, self.action_id, self.target_address, self.enabled, self.error_return_code, self.error_return_code_short_name, self.error_return_code_description, self.audit_action_short_name, self.audit_action_description, self.audit_category_short_name, self.audit_category_description, ]
_COLUMN_TYPES: ClassVar[dict[str, type]] = { "system_alert_id": int, "action_id": int, "target_address": str, "enabled": bool, "error_return_code": int, "error_return_code_short_name": str, "error_return_code_description": str, "audit_action_short_name": str, "audit_action_description": str, "audit_category_short_name": str, "audit_category_description": str, }
[docs] @classmethod def from_hq_response(cls, row_elem) -> "Q2SystemAlertView": """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_csr_notifications_dataset( q2_system_alert_view: Optional[Q2SystemAlertView | list[Q2SystemAlertView]] = None, ) -> DataSetBuilder: """ Build the csr_notifications DataSet parameter for SetCsrNotifications. 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 'csr_notifications' parameter """ dataset = DataSetBuilder("DalSystemAlertView") # Q2_SystemAlertView q2_system_alert_view_cols = [col[0] for col in Q2SystemAlertView.get_columns()] q2_system_alert_view_table = dataset.add_table( "Q2_SystemAlertView", q2_system_alert_view_cols ) _add_rows_to_table(q2_system_alert_view_table, q2_system_alert_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)