def add_task(document_idx: int): """View for adding new tasks (form)""" if request.method == 'POST': add_new_task_schema = AddNewTask() errors = add_new_task_schema.validate(data=request.form) print(request.form) print(str(errors)) if errors: abort(400, str(errors)) args = add_new_task_schema.dump(request.form) task = Task(connection=connection, cursor=cursor) task.add_task(task_name=args['task_name'], executor_id=args['executor_id'], document_id=args['document_id'], factory_id=args['factory_id']) if document_idx: context = {'idx': document_idx} return make_response(jsonify(context), StatusCodes.Created) else: return Response(status=StatusCodes.Created) return Response(status=StatusCodes.BadRequest)
def change_task(task_idx: int): """View for task changing""" if request.method == 'POST': add_new_task_schema = AddNewTask() errors = add_new_task_schema.validate(data=request.args) if errors: abort(StatusCodes.BadRequest, str(errors)) args = add_new_task_schema.dump(request.args) task = Task(connection=connection, cursor=cursor) task.change_task( task_id=task_idx, task_name=args['task_name'], executor_id=args['executor_id'], document_id=args['document_id'], factory_id=args['factory_id'] ) return Response(status=StatusCodes.Created) return Response(status=StatusCodes.BadRequest)
def get_tasks(): """View for showing new tasks""" task = Task(connection=connection, cursor=cursor) all_tasks = task.get_all_tasks() context = {'all_tasks': all_tasks} return make_response(jsonify(context), StatusCodes.OK)
def get_one_task(idx: int): """View for one task page""" task = Task(connection=connection, cursor=cursor) task_description = task.get_task_by_id(task_id=idx) context = { 'task_description': task_description, } return make_response(jsonify(context), StatusCodes.OK)
def delete_task(task_idx: int): """View for deleting factory""" task = Task(connection=connection, cursor=cursor) task.delete_task(task_id=task_idx) all_tasks = task.get_all_tasks() context = {'all_tasks': all_tasks} return make_response(jsonify(context), StatusCodes.OK)
def get_one_document(idx: int): """View for one document page""" document = Document(connection=connection, cursor=cursor) document_description = document.get_document_by_id(document_id=idx) task = Task(connection=connection, cursor=cursor) all_document_tasks = task.get_task_by_document_id(document_id=idx) if isinstance(document_description['date_of_creation'], datetime): document_description['date_of_creation'] = str( document_description['date_of_creation'].date()) if isinstance(document_description['date_of_registration'], datetime): document_description['date_of_registration'] = str( document_description['date_of_registration'].date()) context = { 'document_description': document_description, 'all_document_tasks': all_document_tasks } return make_response(jsonify(context), StatusCodes.OK)