def create_new_advertisement(self): """ 确认创建新的广告 """ ad_params = self.get_new_advertisement_params() if not all([ad_params["image"], ad_params["title"]]): p = InformationPopup("标题和图片不能为空!", self) p.exec_() return self.create_button.setEnabled(False) image_file = QFile(ad_params["image"]) image_file.open(QFile.ReadOnly) file_dict = {"image": image_file} if ad_params["filepath"]: pdf_file = QFile(ad_params["filepath"]) pdf_file.open(QFile.ReadOnly) file_dict["pdf_file"] = pdf_file text_dict = ad_params.copy() multipart_data = generate_multipart_data(text_dict, file_dict) # close后便无法生成multipartData # image_file.close() # if pdf_file: # pdf_file.close() url = SERVER_API + 'advertisement/' request = QNetworkRequest(QUrl(url)) request.setRawHeader("Authorization".encode("utf-8"), get_user_token().encode("utf-8")) network_manager = getattr(qApp, "_network") reply = network_manager.post(request, multipart_data) reply.finished.connect(self.create_advertisement_reply) multipart_data.setParent(reply)
def create_report_reply(): if reply.error(): message = "创建报告失败!" else: message = "创建报告成功!" self.file_table.removeRow(self.file_table.currentRow()) self.clear_relative_variety() reply.deleteLater() p = InformationPopup(message, self) p.exec_()
def create_report_reply(): if reply.error(): message = "创建报告失败!" else: message = "创建报告成功!" self.local_file_edit.clear() self.clear_relative_variety() reply.deleteLater() p = InformationPopup(message, self) p.exec_()
def create_advertisement_reply(self): """ 创建广告返回 """ reply = self.sender() reply.deleteLater() if reply.error(): print(reply.readAll().data()) message = "创建新广告失败!" else: message = "创建新广告成功!" p = InformationPopup(message, self) p.exec_() self.create_button.setEnabled(True)
def manager_advertisement(self, row, col): """ 管理广告 """ advertisement_id = self.ad_table.item(row, 0).text() advertisement_type = self.ad_table.item(row, 2).data(Qt.UserRole) if col == 3: # 查看图片 image_url = self.ad_table.item(row, col).data(Qt.UserRole) p = ImagePopup(STATIC_URL + image_url, self) p.setWindowTitle("广告图片") p.exec_() elif col == 4: # 查看文件 if advertisement_type != "file": p = InformationPopup("此广告类型非文件显示", self) p.exec_() return file_url = STATIC_URL + self.ad_table.item(row, col).data( Qt.UserRole) p = PDFContentPopup(file=file_url, title="广告文件") p.exec_() elif col in [5, 6, 7]: # 5查看网址,6查看内容,7查看备注 titles = [None, None, None, None, None, "查看网址", "查看内容", "查看备注"] message = self.ad_table.item(row, col).data(Qt.UserRole) p = TextPopup(message, self) p.setWindowTitle(titles[col]) p.exec_() elif col == 8: # 设置启用与不启用 self.change_advertisement_active(advertisement_id)
def exit_for_updating(self): """ 退出当前程序,启动更新更新 """ # script_file = os.path.join(BASE_DIR, "AutoUpdate.exe") script_file = os.path.join(BASE_DIR, "Update.exe") is_close = True if os.path.exists(script_file): try: Popen(script_file, shell=False) except OSError as e: self.run_message.setText(str(e)) is_close = False else: p = InformationPopup("更新程序丢失...", self) p.exec_() is_close = False if is_close: sys.exit()
def delete_wechat_file_reply(): """ 删除网络保存的文件返回 """ if reply.error(): p = InformationPopup("删除失败!", self) p.exec_() else: p = InformationPopup("删除成功!", self) p.exec_() self.file_table.removeRow(current_row) reply.deleteLater()
def modify_finished(): f_reply = self.sender() if f_reply.error(): p_info = InformationPopup("修改失败了!\n只能修改自己发送的短信通", popup) p_info.exec_() else: p_info = InformationPopup("修改成功!", popup) p_info.exec_() popup.close() self.content_label.setText( popup.text_edit.toHtml()) # 设置修改后的内容
def modify_advertisement_reply(self): """ 修改广告启用返回 """ reply = self.sender() if reply.error(): p = InformationPopup("修改启用失败", self) p.exec_() else: p = InformationPopup("修改启用成功", self) p.exec_() self.read_all_advertisements() reply.deleteLater()
def delete_message_reply(self): """ 删除本条短信通返回 """ reply = self.sender() if reply.error(): logger.error("删除短信通错误:{}".format(reply.error())) p = InformationPopup("删除失败!\n您不能对他人的短信通进行这个操作!", self) p.exec_() else: p = InformationPopup("删除成功!", self) p.exec_() self.deleteLater() reply.deleteLater()
def delete_report_reply(): if reply.error(): p = InformationPopup("删除失败", self) else: p = InformationPopup("删除成功", self) self.manager_table.removeRow(current_row) p.exec_() reply.deleteLater()
def change_report_reply(): if reply.error(): p = InformationPopup("修改失败", self) else: p = InformationPopup("修改成功", self) text = "否" if self.manager_table.item(current_row, 5).text() == "是" else "是" self.manager_table.item(current_row, 5).setText(text) p.exec_() reply.deleteLater()
def create_report_file(self): """ 从网络文件创建报告 """ # 验证是否能发送请求 if not self.selected_varieties: p = InformationPopup("未选择关联品种", self) p.exec_() return # 公共body_data body_data = { "date": self.date_edit.text(), "relative_varieties": ";".join(self.selected_varieties), "report_type": self.report_type.currentData(), "rename_text": self.rename_edit.text().strip() } if self.local_file_path: # 上传本地文件 self.send_local_report(body_data) elif self.selected_file_path: # 选择网络文件 self.send_network_report(body_data.copy()) else: p = InformationPopup("未选择相关报告文件", self) p.exec_()
def file_table_operation(self, row, col): """ 表格操作 """ current_file_path = self.file_table.item(row, 0).data(Qt.UserRole) if col == 4: # 查看 filename = self.file_table.item(row, 1).text() url = SERVER_API + "wechat-files/{}".format(current_file_path) p = PDFContentPopup(title=filename, file=url) p.exec_() elif col == 5: # 选择 if self.local_file_path is not None: p = InformationPopup( "您已选择本地文件,无法再选择网络文件。\n如需取消本地文件,请点击选框后直接取消。", self) p.exec_() return filename = self.file_table.item(row, 1).text() self.filename.setText(filename) self.selected_file_path = current_file_path self.has_selected_file() elif col == 6: # 删除 self.delete_wechat_file(row, current_file_path) else: pass