def delete_tasks(cls, user, project, no, start, end): tasks = cls.query.filter( cls.create_user == user if user else '', cls.project_id == project if project else '', cls.task_no.like(f'%{no}%') if no is not None else '', cls._create_time.between(start, end) if start and end else '', cls.delete_time == None, ).all() task_no_list = [task.task_no for task in tasks] try: for task in tasks: task.delete_time = datetime.now() db.session.commit() # 删除task全局变量 [mongo.db.task.delete_one({'task_id': task.id}) for task in tasks] # 删除日志 for task_no in task_no_list: Case.case_log_remove(name=None, url=None, project=None, task=task_no, result=None, start=None, end=None) except Exception: db.session.rollback() raise RecordRemoveException() return len(tasks)
def case_logs_delete(): form = CaseLogsSearchForm().validate_for_api() count = Case.case_log_remove(form.name.data, form.url.data, form.project.data, form.task.data, form.result.data, form.start.data, form.end.data) if count == 0: return Success(msg='无符合条件数据') else: return Success(msg='成功删除' + str(count) + '条数据')