Пример #1
0
    def mutate(cls, _, info, title, milestones, type, expiration):
        user = User.objects(email=get_jwt_identity()).first()
        if not user:
            return NewToDoMutation(
                ResponseMessageField(is_success=False,
                                     message="User not found"))

        type_enum = {1: "INFINITY", 2: "STANDARD", 3: "HARD"}
        type = type_enum.get(type, None)

        new_todo = ToDo(
            title=title,
            type=str(type),
            milestones=[Milestone(id=uuid4().hex, name=m) for m in milestones],
            expiration=expiration)
        new_todo.save()

        user.update_one(inc__point=30)
        user.update_one(push__todo=new_todo)

        todo_activity_logger(user=user, type="new")

        return NewToDoMutation(
            ResponseMessageField(is_success=True,
                                 message="Todo upload success"))
Пример #2
0
def index():
    if request.method == 'POST' and request.form.get('task'):
        todo = ToDo()
        todo.task = request.form.get('task')
        db.session.add(todo)
        db.session.commit()
    todos = ToDo.query.all()
    return render_template('index.html', todos=todos)
Пример #3
0
def add_todo():
    form = ToDoForm(request.form)
    if form.validate_on_submit():
        content = form.todo.data
        todo = ToDo()
        todo.content = content
        todo.time = datetime.datetime.now()
        db.session.add(todo)
        db.session.commit()
    todos = ToDo.query.order_by(ToDo.time.desc())
    return render_template("index.html", todos=todos, form=form)
Пример #4
0
def create_todo():
    form = TodoForm()

    if form.validate_on_submit():
        todo_info = {
            "date": form.date.data,
            "whattodo": form.whattodo.data,
            "user_id": current_user.id
        }
        todo = ToDo(**todo_info)
        todo.save_db()
        return redirect(url_for("user_app.dashboard"))
    return render_template("todo.html", form=form)
Пример #5
0
 def post(self):
     form = ToDoCreateForm()
     if not form.validate_on_submit():
         return form.errors, 422
     todo = ToDo(form.text.data, form.is_complete.data, 'Active')
     db.session.add(todo)
     db.session.commit()
     return ToDoSerializer(todo).data, 201
Пример #6
0
def add_task():
    if request.method == "POST":
        # Taking Form Data To Add A Task
        task_title = request.form["title"]
        task_description = request.form["description"]

        # Storing Data In ToDo Model
        new_task = ToDo(title = task_title, description = task_description)
        new_task.user_id = current_user.id
        new_task.is_completed = False

        # Adding In DB
        try:
            db.session.add(new_task)
            db.session.commit()
            flash(_("Item Added! Your ToDo Item Successfully Created!"))
            return redirect(url_for("index"))
        except:
            flash(_("There was an issue adding your task! Please try again later."))
Пример #7
0
    def mutate(cls, _, info, todo_id, milestone_id):
        todo = ToDo.objects(id=todo_id, milestones__id=milestone_id)
        user = User.objects(email=get_jwt_identity(),
                            todo=todo.first()).first()

        if user is None:
            return DeleteMilestoneMutation(result=ResponseMessageField(
                is_success=False, message="Not found"))

        try:
            todo.update(pull__milestones__id=milestone_id)

            return DeleteMilestoneMutation(result=ResponseMessageField(
                is_success=True, message="Milestone delete success"))
        except Exception as e:
            return DeleteMilestoneMutation(
                result=ResponseMessageField(is_success=False, message=str(e)))
Пример #8
0
    def mutate(cls, _, info, todo_id, milestone_id):
        todo = ToDo.objects(id=todo_id, milestones__id=milestone_id)
        user = User.objects(email=get_jwt_identity(), todo=todo.first()).first()

        if user is None:
            return CompleteMilestoneMutation(result=ResponseMessageField(is_success=False,
                                                                         message="Not found"))
        try:
            todo.update(set__milestones__S__is_completed=True)
        except Exception as e:
            return CompleteMilestoneMutation(result=ResponseMessageField(is_success=False,
                                                                         message=str(e)))

        todo_activity_logger(user=user, type="milestone")

        return CompleteMilestoneMutation(result=ResponseMessageField(is_success=True,
                                                                     message="Milestone complete success"))
Пример #9
0
def post_todo():
    # Check if request is a valid JSON
    json_utils.is_not_json_request(request)
    try:
        # Extract data from request
        title = request.json.get('title')
        description = request.json.get('description')
        # Create an instance of a new To-Do
        new_todo = ToDo(title=title, description=description)
        # Add To-Do to db session
        db.session.add(new_todo)
        # Commit db session -> this will perform "INSERT" operation on db
        db.session.commit()
    except IntegrityError:
        # If something goes wrong it will abort with a 400 error code
        abort(400)
    return jsonify(request.json), 201
Пример #10
0
    def mutate(cls, _, info, id):
        todo = ToDo.objects(id=id).first()
        user = User.objects(email=get_jwt_identity(), todo=todo).first()

        if user is None:
            return DeleteToDoMutation(result=ResponseMessageField(
                is_success=False, message="Not found"))
        try:
            user.update(pull__todo=todo)
            todo.delete()
        except Exception as e:
            return DeleteToDoMutation(
                result=ResponseMessageField(is_success=False, message=str(e)))

        # TODO: User Log 남기는 기능은 함수로 따로 빼자

        return DeleteToDoMutation(result=ResponseMessageField(
            is_success=True, message="Todo delete success"))
Пример #11
0
    def mutate(cls, _, info, id, new_title):
        todo = ToDo.objects(id=id).first()
        user = User.objects(email=get_jwt_identity(), todo=todo).first()

        if user is None:
            return UpdateToDoMutation(
                ResponseMessageField(is_success=False, message="Not Found"))

        try:
            todo.update(set__title=new_title)
        except Exception as e:
            return UpdateToDoMutation(
                ResponseMessageField(is_success=False, message=str(e)))

        # TODO: User Log 남기는 기능은 함수로 따로 빼자

        return UpdateToDoMutation(
            ResponseMessageField(is_success=True,
                                 message="Todo update success"))
Пример #12
0
    def mutate(cls, _, info, id):
        todo = ToDo.objects(id=id).first()
        user = User.objects(email=get_jwt_identity(), todo=todo).first()

        if user is None:
            return CompleteToDoMutation(
                ResponseMessageField(is_success=False, message="Not Found"))

        try:
            todo.update(set__is_completed=True)
        except Exception as e:
            return CompleteToDoMutation(
                ResponseMessageField(is_success=False, message=str(e)))

        todo_activity_logger(user=user, type="todo")

        return CompleteToDoMutation(
            ResponseMessageField(is_success=True,
                                 message="Todo complete success"))
Пример #13
0
def save():
    todo = ToDo(content="study flask")
    todo.save()
Пример #14
0
def save():
    todo = ToDo(content = "study flask")
    todo.save()