def eat_userinput(self): if sys.argv[-1] == 'main_modul.py': return print(Usage.print_usage_information(self)) elif sys.argv[1] == '-l': PrintList.print_list(self) elif sys.argv[-1] == '-a' and len(sys.argv) == 2: return print('Unable to add: no task provided') elif sys.argv[1] == '-a' and len(sys.argv) > 2: AddTask.add_task(self) elif sys.argv[-1] == '-r' and len(sys.argv) == 2: return print('Unable to remove: no index provided') elif sys.argv[1] == '-r' and len( sys.argv) > 2 and sys.argv[2].isalpha(): return print('Unable to remove: index is not a number') try: if sys.argv[1] == '-r' and len( sys.argv) > 2 and not sys.argv[2].isalpha(): RemoveTask.remove_task(self) except IndexError: return print('Unable to remove: index is out of bound') if sys.argv[-1] == '-c': return print('Completes a task')
def submit_task(): try: data = dict((key, request.form[key]) for key in request.form.keys()) add_task = AddTask(user_repo(), task_repo()) return add_task() except: return make_response(jsonify({'error': 'Could not submit task'}), 400)
def test_add_task_should_deliver_error_if_user_is_not_found(self): self.user_repo.find_one = MagicMock(return_value=None) add_task = AddTask(self.user_repo, self.task_repo) response = add_task({'user': 126}) self.assertEqual('fail', response['status'])
def showalltasktable(self): try: self.dlg_2 = Showalltask() self.dlg_2.show() except Exception as e: traceback.print_exc()
def test_should_add_new_task_to_user_task_list_and_return_scheduled_task_list( self, mock_dt): request = { 'user': 126, 'code': 'add_task', 'data': { 'title': 'New Task', } } mock_dt.now.return_value = TODAY self.user_repo.find_one = MagicMock(return_value=User(id=1)) self.task_repo.tasks_for = MagicMock( return_value=[Task(**request['data'])]) add_task = AddTask(self.user_repo, self.task_repo) response = add_task(request) self.assertEqual('success', response['status']) self.assertEqual([{ 'title': 'New Task', 'active': True, 'creation': str(TODAY) }], response['data'])
class MTGM_window(Ui_Form, Ui_Dialog_task, QtWidgets.QMainWindow, QCalendarWidget): # 从自动生成的界面类继承 """显示测量管理子窗口 1,Ui_Form 是主界面 2,Ui_Dialog_task 是 弹出的今天任务状态 """ def __init__(self, parent=None): super(MTGM_window, self).__init__() self.setupUi(self) # 在此设置界面 # 在此,可添加自定义的信号绑定 # 导入新任务 self.updatetask.clicked.connect(self.taskupdate_button) # 根据选定日期显示任务状态 self.cal = self.calendarWidget self.cal.setGridVisible(True) # 网格显示 self.cal.selectionChanged.connect(self.showselecteddatetask) # 显示全部任务 self.showalltask.clicked.connect(self.showalltasktable) # 添加删除任务 self.add_del_task.clicked.connect(self.add_delete_task) def database(self): from create_db import CreateDatabase # db = pymysql.connect('localhost', 'root', 'mysql', 'MT_TASK', charset='utf8') db_01 = CreateDatabase() db = db_01.logon_mysql() return db def taskupdate_button(self): # 更新任务总表 dlg = win32ui.CreateFileDialog(1) # 1表示打开文件对话框 dlg.SetOFNInitialDir(r'E:\01_MProject\MTGM') # 设置打开文件对话框中的初始显示目录 dlg.DoModal() path = dlg.GetPathName() # 和数据库建立连接 if path != "": # conn = pymysql.connect('localhost', 'root', 'mysql', 'MT_TASK', charset='utf8') conn = self.database() # 创建游标链接 cur = conn.cursor() cur.execute("DROP TABLE IF EXISTS VW331") sql = """CREATE TABLE IF NOT EXISTS VW331( part_name VARCHAR(100), part_num_1 CHAR(50), sent_time_1 CHAR(50), get_time_1 CHAR(50) , part_num_2 CHAR(50), sent_time_2 CHAR(50), get_time_2 CHAR(50), part_num_3 CHAR(50), sent_time_3 CHAR(50), get_time_3 CHAR(50), part_num_4 CHAR(50), sent_time_4 CHAR(50), get_time_4 CHAR(50), part_num_5 CHAR(50), sent_time_5 CHAR(50), get_time_5 CHAR(50), part_num_6 CHAR(50), sent_time_6 CHAR(50), get_time_6 CHAR(50), part_num_7 CHAR(50), sent_time_7 CHAR(50), get_time_7 CHAR(50) )ENGINE=InnoDB DEFAULT CHARSET=utf8 """ # try: # 执行sql语句 cur.execute(sql) # 提交到数据库执行 conn.commit() except: # Rollback in case there is any error conn.rollback() # # # 关闭数据库连接 conn.close() importExcelToMysql(path) # 将任务按照星期进行分布 todaytask = Showtadaytask() todaytask.create_today_db_table() todaytask.data_into_taday_task() else: return def showselecteddatetask(self): try: date = self.selecte_date() # 返回日期 aks_1 = win32api.MessageBox( 0, "您选择显示的日期为 --" + date + "-- \n\n 即将为您显示~", "提示!", win32con.MB_YESNOCANCEL) if aks_1 == 6: self.dlg_1 = Dialog_showtodaytask(date) self.dlg_1.show() except Exception as e: traceback.print_exc() def selecte_date(self): # 返回选择的日期 格式为 ’2019-02-20_星期3‘ try: self.cal = self.calendarWidget self.cal.setGridVisible(True) d = self.cal.selectedDate() date_1 = d.toString("yyyy-MM-dd") date_2 = d.dayOfWeek() date = str(date_1) + "_星期" + str(date_2) return date except Exception as e: traceback.print_exc() def showalltasktable(self): try: self.dlg_2 = Showalltask() self.dlg_2.show() except Exception as e: traceback.print_exc() def add_delete_task(self): self.dlg_2 = AddTask() self.dlg_2.show()
def add_delete_task(self): self.dlg_2 = AddTask() self.dlg_2.show()