コード例 #1
0
    def patch(self, username, list_id: str, todo_id: str):
        body_parser = reqparse.RequestParser(bundle_errors=True)
        body_parser.add_argument('name',
                                 type=str,
                                 required=True,
                                 help="Missing the name of the list")
        body_parser.add_argument('description',
                                 type=str,
                                 required=True,
                                 help="Missing the description of the list")
        args = body_parser.parse_args(
            strict=False
        )  # Accepted only if these two parameters are strictly declared in body else raise exception

        if len(list_id) != 24:
            return sendErrorNotFound({"message": "todo_list id not found"})
        if len(todo_id) != 24:
            return sendErrorNotFound({"message": "todo_id id not found"})
        try:
            todo = Todo.objects(id=todo_id, username=username).first()

            if todo is None:
                return sendErrorNotFound({"message": "todo id not found"})

            todo_list = TodoList.objects(id=list_id, username=username).first()

            if todo_list is None:
                return sendErrorNotFound({"message": "todo_list id not found"})

            todo.update(name=args['name'],
                        description=args['description'],
                        username=username)

            todo = Todo.objects(id=todo_id, username=username).first()

            return sendSuccess({'todo': todo.asJson()})
        except Exception as err:
            return sendJson(400, str(err), args)
コード例 #2
0
def queryPies(todo_date):
    date = todo_date.split('-')
    year = date[0]
    month = int(date[1])
    datas=[
            ['工作',0],
             ['人情',0],
             {
                'name': '娱乐',
                'y':0,
                'sliced': 'true',
                'selected': 'true'
             },
             ['教育',0],
             ['日杂',0],
            ]
    data_count=[0,0,0,0,0]
    sum=0
    search = {
        'time': re.compile(year)
    }
    todos = Todo.objects(**search)
    for todo in todos:
        date = todo.time
        date_split = date.split('-')
        todo_month = int(date_split[1])
        if(todo_month==month and todo.classification=="工作"):
            data_count[0] = data_count[0]+1
        elif(todo_month==month and todo.classification=="人情"):
            data_count[1] = data_count[1]+1
        elif (todo_month == month and todo.classification == "娱乐"):
            data_count[2] = data_count[2]+1
        elif (todo_month == month and todo.classification == "教育"):
            data_count[3] = data_count[3]+1
        elif (todo_month == month and todo.classification == "日杂"):
            data_count[4] = data_count[4]+1
    for i in range(5):
        sum = sum+data_count[i]
    if(sum!=0):
        datas[0][1] = data_count[0]/sum
        datas[1][1] = data_count[1]/sum
        datas[2]['y'] = data_count[2]/sum
        datas[3][1] = data_count[3]/sum
        datas[4][1] = data_count[4]/sum
    return jsonify(status="success", data=datas)
コード例 #3
0
def queryPies(todo_date):
    date = todo_date.split('-')
    year = date[0]
    month = int(date[1])
    datas = [
        ['工作', 0],
        ['人情', 0],
        {
            'name': '娱乐',
            'y': 0,
            'sliced': 'true',
            'selected': 'true'
        },
        ['教育', 0],
        ['日杂', 0],
    ]
    data_count = [0, 0, 0, 0, 0]
    sum = 0
    search = {'time': re.compile(year)}
    todos = Todo.objects(**search)
    for todo in todos:
        date = todo.time
        date_split = date.split('-')
        todo_month = int(date_split[1])
        if (todo_month == month and todo.classification == "工作"):
            data_count[0] = data_count[0] + 1
        elif (todo_month == month and todo.classification == "人情"):
            data_count[1] = data_count[1] + 1
        elif (todo_month == month and todo.classification == "娱乐"):
            data_count[2] = data_count[2] + 1
        elif (todo_month == month and todo.classification == "教育"):
            data_count[3] = data_count[3] + 1
        elif (todo_month == month and todo.classification == "日杂"):
            data_count[4] = data_count[4] + 1
    for i in range(5):
        sum = sum + data_count[i]
    if (sum != 0):
        datas[0][1] = data_count[0] / sum
        datas[1][1] = data_count[1] / sum
        datas[2]['y'] = data_count[2] / sum
        datas[3][1] = data_count[3] / sum
        datas[4][1] = data_count[4] / sum
    return jsonify(status="success", data=datas)
コード例 #4
0
def queryBars(todo_date):
    search = {'time': re.compile(todo_date)}
    todos = Todo.objects(**search)
    dones = []
    undones = []
    for i in range(1, 13):
        count_done = 0
        count_undone = 0
        for todo in todos:
            date = todo.time
            date_split = date.split('-')
            month = int(date_split[1])
            if (month == i and todo.status == 1):
                count_done = count_done + 1
            elif (month == i and todo.status == 0):
                count_undone = count_undone + 1
        dones.append(count_done)
        undones.append(count_undone)
        count_done = 0
        count_undone = 0
    return jsonify(status="success", done=dones, undone=undones)
コード例 #5
0
    def get(self, username, list_id: str, todo_id: str):
        if len(list_id) != 24:
            return sendErrorNotFound({"message": "todo_list id not found"})
        if len(todo_id) != 24:
            return sendErrorNotFound({"message": "todo_id id not found"})
        try:
            todo = Todo.objects(id=todo_id, username=username).first()

            if todo is None:
                return sendErrorNotFound({"message": "todo id not found"})

            todo_list = TodoList.objects(id=list_id, username=username).first()

            if todo_list is None:
                return sendErrorNotFound({"message": "todo_list id not found"})

            return sendSuccess({
                'todo': todo.asJson(),
                'todo_list_id': todo_list.asJson()['id'],
            })
        except Exception as err:
            return sendJson(400, str(err), {"list_id": list_id})
コード例 #6
0
    def delete(self, username, list_id: str, todo_id: str):
        if len(list_id) != 24:
            return sendErrorNotFound({"message": "todo_list id not found"})
        if len(todo_id) != 24:
            return sendErrorNotFound({"message": "todo_id id not found"})
        try:
            todo = Todo.objects(id=todo_id, username=username).first()

            if todo is None:
                return sendErrorNotFound({"message": "todo id not found"})

            todo_list = TodoList.objects(id=list_id, username=username).first()

            if todo_list is None:
                return sendErrorNotFound({"message": "todo_list id not found"})

            todo.delete()

            todo_list.update(pull__todo_list=todo.id, username=username)

            return sendSuccess({'todo_id': todo_id, "list_id": list_id})
        except Exception as err:
            return sendJson(400, str(err), {"list_id": list_id})
コード例 #7
0
def queryBars(todo_date):
    search = {
        'time': re.compile(todo_date)
    }
    todos = Todo.objects(**search)
    dones=[]
    undones=[]
    for i in range(1,13):
        count_done = 0
        count_undone = 0
        for todo in todos:
            date = todo.time
            date_split = date.split('-')
            month = int(date_split[1])
            if(month==i and todo.status==1):
                count_done = count_done+1
            elif(month==i and todo.status==0):
                count_undone = count_undone+1
        dones.append(count_done)
        undones.append(count_undone)
        count_done = 0
        count_undone = 0
    return jsonify(status="success", done=dones, undone=undones)
コード例 #8
0
def undone(todo_id):
    todo = Todo.objects(id=todo_id)[0]
    todo.status = 0
    todo.save()
    todos = Todo.objects()
    return render_template('index.html', todos=todos)
コード例 #9
0
def index():
    todos = Todo.objects()
    return render_template("index.html", todos=todos)
コード例 #10
0
def delete(todo_id):
    todo = Todo.objects(id=todo_id)[0]
    Todo.delete(todo)
    todos = Todo.objects()
    return render_template('index.html', todos=todos)
コード例 #11
0
def query(todo_content):
    search = {
            'content':re.compile(todo_content)
    }
    todos = Todo.objects(**search).order_by('-time')
    return jsonify(status="success", todos=[todo.to_json() for todo in todos])
コード例 #12
0
def query(todo_content):
    search = {'content': re.compile(todo_content)}
    todos = Todo.objects(**search).order_by('-time')
    return jsonify(status="success", todos=[todo.to_json() for todo in todos])