class CommentAction(StrEnum): edit = "EDIT" delete = "DEL" class…
- User
class CommentAction(StrEnum): edit = "EDIT" delete = "DEL"
class CommentFields(BaseSchema): id: int = Field(..., alias="ID") task_id: int = Field(..., alias="TASK_ID") action: CommentAction|None = Field(None, alias="ACTION")
class CommentChange(BaseSchema): fields_before: CommentFields|None = Field(..., alias="FIELDS_BEFORE") fields_after : CommentFields|None=Field(...,alias="FIELDS_AFTER") is_accessible_before: Acceptable=Field(..., alias="IS_ACCESSIBLE_BEFORE") is_accessible_after: Acceptable=Field(...,alias="IS_ACCESSIBLE_AFTER")
@field_validator(fields_after, fields_before, mode="before") @classmethod def validate_fields(cls, v) -> CommentFields|None: if not isinstance(v, dict): return None return CommentFields(**v) - Assistant
- User
array( 'event' => 'ONTASKUPDATE', 'data' => array( 'FIELDS_BEFORE' => array('ID' => 123), 'FIELDS_AFTER' => array('ID' => 123), 'IS_ACCESSIBLE_BEFORE' => 'undefined', 'IS_ACCESSIBLE_AFTER' => 'undefined', ), 'ts' => '1466439714', 'auth' => array( 'access_token' => 's6p6eclrvim6da22ft9ch94ekreb52lv', 'expires_in' => '3600', 'scope' => 'crm', 'domain' => 'some-domain.bitrix24.com', 'server_endpoint' => 'https://oauth.bitrix.info/rest/', 'status' => 'F', 'client_endpoint' => 'https://some-domain.bitrix24.com/rest/', 'member_id' => 'a223c6b3710f85df22e9377d6c4f7553', 'refresh_token' => '4s386p3q0tr8dy89xvmt96234v3dljg8', 'application_token' => '51856fefc120afa4b628cc82d3935cce', ), )
- Assistant
- User
convert name in dict to uppercase
- Assistant
To convert all the dictionary keys to uppercase in Python, you can use a dictionary comprehension. Here's how you can do it for a nested dictionary like the one you provided:
event_data = { 'event': 'ONTASKUPDATE', 'data': { 'FIELDS_BEFORE': {'ID': 123}, 'FIELDS_AFTER': {'ID': 123}, 'IS_ACCESSIBLE_BEFORE': 'undefined', 'IS_ACCESSIBLE_AFTER': 'undefined', }, 'ts': '1466439714', 'auth': { 'access_token': 's6p6eclrvim6da22ft9ch94ekreb52lv', 'expires_in': '3600', 'scope': 'crm', 'domain': 'some-domain.bitrix24.com', 'server_endpoint': 'https://oauth.bitrix.info/rest/', 'status': 'F', 'client_endpoint': 'https://some-domain.bitrix24.com/rest/', 'member_id': 'a223c6b3710f85df22e9377d6c4f7553', 'refresh_token': '4s386p3q0tr8dy89xvmt96234v3dljg8', 'application_token': '51856fefc120afa4b628cc82d3935cce', } } def dict_keys_to_upper(d): new_dict = {} for k, v in d.items(): if isinstance(v, dict): v = dict_keys_to_upper(v) new_dict[k.upper()] = v return new_dict uppercased_event_data = dict_keys_to_upper(event_data) print(uppercased_event_data) - User
convert to python dict with same names array( 'event' => 'ONTASKCOMMENUPDATE', 'data' => array( 'FIELDS_BEFORE' => array('ID' => 123, 'TASK_ID' => 555), 'FIELDS_AFTER' => array('ID' => 123, 'TASK_ID' => 555, 'ACTION' => 'EDIT'), 'IS_ACCESSIBLE_BEFORE' => 'undefined', 'IS_ACCESSIBLE_AFTER' => 'undefined', ), 'ts' => '1466439714', 'auth' => array( 'access_token' => 's6p6eclrvim6da22ft9ch94ekreb52lv', 'expires_in' => '3600', 'scope' => 'crm', 'domain' => 'some-domain.bitrix24.com', 'server_endpoint' => 'https://oauth.bitrix.info/rest/', 'status' => 'F', 'client_endpoint' => 'https://some-domain.bitrix24.com/rest/', 'member_id' => 'a223c6b3710f85df22e9377d6c4f7553', 'refresh_token' => '4s386p3q0tr8dy89xvmt96234v3dljg8', 'application_token' => '51856fefc120afa4b628cc82d3935cce', ), )
- Assistant
To convert the given PHP array to a Python dictionary while maintaining the same structure and key names, you can perform a direct translation of the PHP syntax into Python syntax. Below is the converted Python dictionary:
event_data = { 'event': 'ONTASKCOMMENUPDATE', 'data': { 'FIELDS_BEFORE': {'ID': 123, 'TASK_ID': 555}, 'FIELDS_AFTER': {'ID': 123, 'TASK_ID': 555, 'ACTION': 'EDIT'}, 'IS_ACCESSIBLE_BEFORE': 'undefined', 'IS_ACCESSIBLE_AFTER': 'undefined', }, 'ts': '1466439714', 'auth': { 'access_token': 's6p6eclrvim6da22ft9ch94ekreb52lv', 'expires_in': '3600', 'scope': 'crm', 'domain': 'some-domain.bitrix24.com', 'server_endpoint': 'https://oauth.bitrix.info/rest/', 'status': 'F', 'client_endpoint': 'https://some-domain.bitrix24.com/rest/', 'member_id': 'a223c6b3710f85df22e9377d6c4f7553', 'refresh_token': '4s386p3q0tr8dy89xvmt96234v3dljg8', 'application_token': '51856fefc120afa4b628cc82d3935cce', } } print(event_data) - User
class TaskCommentDelete(BaseSchema): method: str = Field("task.commentitem.delete", exclude=True) task_id: int comment_id: int
- Assistant
The class
TaskCommentDeleteis defined as a Pydantic model that outlines the schema for what looks like a request to delete a comment associated with a specific task. Let's break down its components and provide insights on its formulation: - User
add serialization model to array
- Assistant