diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py index 20a7dcc17c..e8afe5a0ba 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudApiClient.py @@ -190,9 +190,9 @@ class CloudApiClient: Logger.logException("e", "Could not parse the stardust response: %s", error.toDict()) return status_code, {"errors": [error.toDict()]} - def _parseModels(self, response: Dict[str, Any], on_finished: Union[Callable[[CloudApiClientModel], Any], - Callable[[List[CloudApiClientModel]], Any]], model_class: Type[CloudApiClientModel]) -> None: - """Parses the given models and calls the correct callback depending on the result. + def _parseResponse(self, response: Dict[str, Any], on_finished: Union[Callable[[CloudApiClientModel], Any], + Callable[[List[CloudApiClientModel]], Any]], model_class: Type[CloudApiClientModel]) -> None: + """Parses the given response and calls the correct callback depending on the result. :param response: The response from the server, after being converted to a dict. :param on_finished: The callback in case the response is successful. @@ -201,7 +201,11 @@ class CloudApiClient: if "data" in response: data = response["data"] - if isinstance(data, list): + if "status" in data and data["status"] == "wait_approval": + PrintJobPendingApprovalMessage().show() + on_finished_empty = cast(Callable[[List], Any], on_finished) + on_finished_empty([]) + elif isinstance(data, list): results = [model_class(**c) for c in data] # type: List[CloudApiClientModel] on_finished_list = cast(Callable[[List[CloudApiClientModel]], Any], on_finished) on_finished_list(results) @@ -242,10 +246,8 @@ class CloudApiClient: status_code, response = self._parseReply(reply) if status_code >= 300 and on_error is not None: on_error() - elif "data" in response and "status" in response["data"] and response["data"]["status"] == "wait_approval": - PrintJobPendingApprovalMessage().show() else: - self._parseModels(response, on_finished, model) + self._parseResponse(response, on_finished, model) self._anti_gc_callbacks.append(parse) return parse diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py index e3eac7da02..86f3bc0ffc 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py @@ -259,16 +259,19 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice): """ self._uploaded_print_job = self._pre_upload_print_job self._progress.hide() - message = PrintJobUploadSuccessMessage() - message.addAction("monitor print", - name=I18N_CATALOG.i18nc("@action:button", "Monitor print"), - icon="", - description=I18N_CATALOG.i18nc("@action:tooltip", "Track the print in Ultimaker Digital Factory"), - button_align=message.ActionButtonAlignment.ALIGN_RIGHT) - df_url = f"https://digitalfactory.ultimaker.com/app/jobs/{self._cluster.cluster_id}?utm_source=cura&utm_medium=software&utm_campaign=message-printjob-sent" - message.pyQtActionTriggered.connect(lambda message, action: (QDesktopServices.openUrl(QUrl(df_url)), message.hide())) - message.show() + if response: + message = PrintJobUploadSuccessMessage() + message.addAction("monitor print", + name=I18N_CATALOG.i18nc("@action:button", "Monitor print"), + icon="", + description=I18N_CATALOG.i18nc("@action:tooltip", "Track the print in Ultimaker Digital Factory"), + button_align=message.ActionButtonAlignment.ALIGN_RIGHT) + df_url = f"https://digitalfactory.ultimaker.com/app/jobs/{self._cluster.cluster_id}?utm_source=cura&utm_medium=software&utm_campaign=message-printjob-sent" + message.pyQtActionTriggered.connect(lambda message, action: (QDesktopServices.openUrl(QUrl(df_url)), message.hide())) + + message.show() + self.writeFinished.emit() def _onPrintUploadSpecificError(self, reply: "QNetworkReply", _: "QNetworkReply.NetworkError"):