def try_update_realm_custom_profile_field( realm: Realm, field: CustomProfileField, name: str, hint: str = "", field_data: Optional[ProfileFieldData] = None, ) -> None: field.name = name field.hint = hint if (field.field_type == CustomProfileField.SELECT or field.field_type == CustomProfileField.EXTERNAL_ACCOUNT): field.field_data = orjson.dumps(field_data or {}).decode() field.save() notify_realm_custom_profile_fields(realm)
def try_add_realm_custom_profile_field( realm: Realm, name: str, field_type: int, hint: str = "", field_data: Optional[ProfileFieldData] = None, ) -> CustomProfileField: custom_profile_field = CustomProfileField(realm=realm, name=name, field_type=field_type) custom_profile_field.hint = hint if ( custom_profile_field.field_type == CustomProfileField.SELECT or custom_profile_field.field_type == CustomProfileField.EXTERNAL_ACCOUNT ): custom_profile_field.field_data = orjson.dumps(field_data or {}).decode() custom_profile_field.save() custom_profile_field.order = custom_profile_field.id custom_profile_field.save(update_fields=["order"]) notify_realm_custom_profile_fields(realm) return custom_profile_field