Exemple #1
0
def create_task():
    if not request.json or not 'description' in request.json:
        abort(400)
    task = Task(description=request.json['description'], order=next_order(), done=False)
    task.save()
    result = task.wrap()
    
    return jsonify(result), 201
Exemple #2
0
 def create(self, validated_data, support, group):
     task = Task(
         client_name = validated_data['client_name'],
         title=validated_data['title'],
         description=validated_data['description'],
         price=validated_data['price'],
         start_dt=validated_data['start_dt'],
         finish_dt=validated_data['finish_dt'],
         is_start=bool(validated_data['is_start']),
         creater=support,
         last_editor=support,
         group=group)
     task.save()
     return task
Exemple #3
0
async def update_task(db: AsyncSession, task_create: task_schema.TaskCreate,
                      original: task_model.Task) -> task_model.Task:
    original.title = task_create.title
    db.add(original)
    await db.commit()
    await db.refresh(original)
    return original
Exemple #4
0
def get_task_list():
    done_tasks = []
    base_tasks = []
    tasks = Task.getTaskList()
    schema = TaskSchema(many=True)
    allTasks = schema.dump(tasks)
    for index in range(len(allTasks)):
        if allTasks[index]['done'] == 1:
            done_tasks.append(allTasks[index])
        else:
            base_tasks.append(allTasks[index])

    msg1 = ""
    msg2 = ""

    if base_tasks == []:
        msg1 = "None"
    if done_tasks == []:
        msg2 = "None"

    return make_response(
        jsonify({
            'code': 200,
            'tasks': base_tasks,
            'done': done_tasks,
            'msg': {
                "msg_task": msg1,
                "msg_done": msg2
            }
        }))
Exemple #5
0
def deleteTask(id):
    msg = Task.destroyTask(id)
    print("id : " + str(id) + "  " + str(msg) + " ===> deleted")
    return make_response(
        jsonify({
            'code': 200,
            'msg': "task : " + str(msg) + " is deleted"
        }))
Exemple #6
0
def updateTask(id):
    jsonData = json.dumps(request.json)
    taskData = json.loads(jsonData)
    print(taskData)

    task = Task.updateTask(taskData, id)
    task_schema = TaskSchema(many=True)

    return make_response(jsonify({'code': 200, 'task': task}))
def create_task():

    title = request.json['title']
    content = request.json['content']

    task = Task(title, content)

    db.session.add(task)
    db.session.commit()

    task_schema = TaskSchema()
    return task_schema.jsonify(task), 201
Exemple #8
0
def create():
    """
    Route to create and assign new tasks by admin.
    """
    current_user = get_current_user(create.role, create.public_id)
    try:
        req = request.get_json()
        title = str(req['title'])
        description = str(req['description'])
        extractor_email = None if str(req['extractor_email']) == "none" else str(req['extractor_email'])
        management_email = None if str(req['management_email']) == "none" else str(req['management_email'])
    except Exception as e:
        print(e)
        response = {
            "success": False,
            "message": "Please provide all parameters"
        }
        return make_response(jsonify(response)), status.UNPROCESSABLE_ENTITY
    extractor = None
    management = None
    # if no member selected
    if not extractor_email and not management_email:
        response = {
            "success": False,
            "message": "Please select atleast one member."
        }
        return make_response(jsonify(response)), status.UNPROCESSABLE_ENTITY
    elif extractor_email and management_email:
        response = {
            "success": False,
            "message": "Please select only one member."
        }
        return make_response(jsonify(response)), status.UNPROCESSABLE_ENTITY

    # Check for extractor member
    elif extractor_email != None:
        extractor = Extractor.query.filter_by(email = extractor_email).first()
        if not extractor:
            response = {
                "success": False,
                "message": "Extractor member not found."
            }
            return make_response(jsonify(response)), status.UNPROCESSABLE_ENTITY

    # check for manageement member
    elif management_email != None:
        management = Management.query.filter_by(email=management_email).first()
        if not management:
            response = {
                "success": False,
                "message": "management member not found."
            }
            return make_response(jsonify(response)), status.UNPROCESSABLE_ENTITY

    # Create new task
    new_task = Task(title=title, description=description, admin=current_user, extractor=extractor, management=management)
    try:
        db.session.add(new_task)
        db.session.commit()

    except Extractor as e:
        response = {
            "success": False,
            "message": e
        }
        return make_response(jsonify(response)), status.INTERNAL_SERVER_ERROR
    response = {
        "success": True,
        "message": "Task created.",
        "task": task_schema.dump(new_task)
    }
    return make_response(jsonify(response)), status.CREATED
Exemple #9
0
from api import db
from api.models.task import Task

if __name__ == "__main__":
    # Insere uma tarefa
    task = Task('lembrete', 'Estudar Flask!')
    db.session.add(task)
    db.session.commit()

    # Exibir tarefas cadastradas no banco
    tasks = Task.query.all()
    for task in tasks:
        print(task.title, task.content)
Exemple #10
0
 def mutate(self, info, name, description):
     task = Task(name=name, description=description, is_done=False)
     task.save()
     ok = True
     return CreateTask(task=task, ok=ok)