Beispiel #1
0
def test_add_todos():
    new_todo1 = Todo(name="test1", priority=1)
    new_todo2 = Todo(name="test2", priority=2)
    new_todo3 = Todo(name="test3", priority=5)
    add_todo(new_todo1)
    add_todo(new_todo2)
    add_todo(new_todo3)
    assert len(DATABASE) == 3
    assert DATABASE[1].name == "test1"
Beispiel #2
0
def create_todo():
    a1 = Course(title='Mathematics')
    b1 = Todo(description='Finish math homework', course=a1)
    db.session.add(b1)

    a2 = Course(title='English')
    b2 = Todo(description='write essay', course=a2)
    db.session.add(b2)
    db.session.commit()
Beispiel #3
0
def alter_todo():
    if (guild_id := request.json.get('guild_id')) is not None:

        member = User.query.get(get_internal_id())

        if guild_id in [x.id for x in member.permitted_guilds()]:

            if request.method == 'POST':
                if (channel_id := request.json.get('channel_id')) is not None and \
                        (value := request.json.get('value')) is not None and \
                        0 < len(value) <= 2000:

                    if channel_id == -1:
                        todo = Todo(guild_id=guild_id,
                                    channel_id=None,
                                    user_id=member.id,
                                    value=value)

                        db.session.add(todo)
                        db.session.commit()

                        return jsonify({'id': todo.id})

                    else:
                        guild = Guild.query.get(guild_id)

                        if guild.channels.filter(
                                Channel.id == channel_id).first() is not None:
                            todo = Todo(guild_id=guild_id,
                                        channel_id=channel_id,
                                        user_id=member.id,
                                        value=value)

                            db.session.add(todo)
                            db.session.commit()

                            return jsonify({'id': todo.id})

                        else:
                            abort(404)

                else:
                    abort(400)

            elif request.method == 'DELETE':
                if (channel_id := request.json.get('channel_id')) is not None and \
                        (todo_id := request.json.get('todo_id')) is not None:

                    if channel_id == -1:
                        channel_id = None

                    Todo.query \
                        .filter(Todo.id == todo_id) \
                        .filter(Todo.channel_id == channel_id) \
                        .filter(Todo.guild_id == guild_id) \
                        .delete(synchronize_session='fetch')
Beispiel #4
0
def add_todo():
    a1 = Course(title='Drafting')
    b1 = Todo(
        description='start blueprints',
        course=a1
    )
    db.session.add(b1)

    a2 = Course(title='Python')
    b2 = Todo(description='practice', todo=a2)
    db.session.add(b2)
    db.session.commit()
Beispiel #5
0
def add():
    title = request.form.get("title")
    descript = request.form.get("descript")
    if Todo.query.filter_by(title=title).first() is None:
        new_todo = Todo(title=title, complete=False, descript=descript)
        db.session.add(new_todo)
        db.session.commit()
        return redirect(url_for("home"))
    elif Todo.query.filter_by(title=title).first().title == title:
        return redirect(url_for("home"))
    else:
        new_todo = Todo(title=title, complete=False, descript=descript)
        db.session.add(new_todo)
        db.session.commit()
        return redirect(url_for("home"))
Beispiel #6
0
 def setUp(self):
     self.app = create_app(TestingConfig)
     self.client = self.app.test_client()
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     self.user1 = User(username='******', password='******')
     self.user2 = User(username='******', password='******')
     self.todo1 = Todo(text='Finish homework')
     self.todo2 = Todo(text='Exercise')
     self.user1.todos.extend([self.todo1, self.todo2])
     self.user2.todos.append((Todo(text='Mow lawn')))
     db.session.add_all([self.user1, self.user2])
     db.session.commit()
     self.token = self.user1.generate_jwt()
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('content', required=True)
     parser.add_argument('state')
     args = parser.parse_args()
     # 验证长度
     if len(args['content']) ==0 or len(args['content']) > 25:
         abort_unacceptable_length("content")
     if args['state'] is not None:
         if len(args['state']) > 10:
             abort_unacceptable_length("state")
     # 验证用户角色
     if current_user.role == 0:
         limitation = 1
         role_name = 'normal user'
     elif current_user.role == 1:
         limitation = 3
         role_name = 'vip 1 user'
     elif current_user.role == 2:
         limitation = 5
         role_name = 'vip 2 user'
     else:
         limitation = None
     if limitation:
         if Todo.query.filter_by(user=current_user).count() >= limitation:
             abort_role_limitation(role_name, limitation)
     # 写入数据库
     new_todo = Todo(content=args['content'],
                     state=args['state'], user=current_user)
     db.session.add(new_todo)
     db.session.commit()
     return "insert: %s"%(args['content']), 201
Beispiel #8
0
    def todos():
        if request.method == "POST":
            title = str(request.data.get('title', ''))
            description = str(request.data.get('description', ''))
            if title and description:
                todo = Todo(title=title, description=description)
                todo.save()
                response = jsonify({
                    'id': todo.id,
                    'title': todo.title,
                    'description': todo.description,
                    'date_created': todo.date_created,
                    'date_updated': todo.date_updated,
                    'done_status': todo.done_status
                })
                response.status_code = 201
                return response
        else:
            # GET
            todos = Todo.get_all()
            results = []

            for todo in todos:
                obj = {
                    'id': todo.id,
                    'title': todo.title,
                    'description': todo.description,
                    'done_status': todo.done_status,
                    'date_created': todo.date_created,
                    'date_updated': todo.date_updated
                }
                results.append(obj)
            response = jsonify(results)
            response.status_code = 200
            return response
def add():
    #不带验证的版本
    #form = request.form
    #content = form['content']
    #todo = Todo(content=content)
    #todo.save()
    #带验证的版本
    #form = TodoForm(request.form)
    #if form.validate():
    #    content = form.content.data
    #    todo = Todo(content=content, time=datetime.now())
    #    todo.save()
    #todos = Todo.objects.order_by('-time')
    #return render_template('index.html', todos=todos,form=form)
    #react的版本
    form = request.form
    content = form.get('content')
    finishtime = form.get('finishtime')
    classification = form.get('classification')
    todo = Todo(content=content,
                time=datetime.strftime(datetime.now(), '%d-%m-%Y   %H:%M:%S'),
                finishtime=finishtime,
                classification=classification)
    todo.save()
    return jsonify(status="success")
Beispiel #10
0
def todo():
    if request.method == 'POST' and session:
        data = request.get_json()
        todo = data['todo']
        user_id = session['id']    
        todo_row = Todo(content=todo, user_id=user_id)
        db.session.add(todo_row)
        db.session.commit()
        todo = TodoSchema().dump(todo_row).data 
        if todo:
            return jsonify(todo=todo)
        else:
            return jsonify(error='Something went wrong!')
 
    if request.method == 'GET':
        id = request.args.get('id')
        try:
            todo_row = Todo.query.filter_by(id=id).first()
            todo = TodoSchema().dump(todo_row).data
            return jsonify(todo=todo)
        except Exception as error:
            print(error)
            return jsonify(error='Something went wrong.')
    
    return jsonify(error='Invalid Request.')
Beispiel #11
0
def add_todo():
    text = request.json['text']
    new_todo = Todo(text)
    db.session.add(new_todo)
    db.session.commit()

    return jsonify({'id': new_todo.id, 'text': new_todo.text})
Beispiel #12
0
def new_todo():
    with db.database:
        Todo.create_table()
        todo = Todo(task="make eggs")
        todo.save()

    return todo
Beispiel #13
0
def create(record_name="First_Record"):
    new_record = Todo()
    new_record.content = record_name
    db.session.add(new_record)
    db.session.commit()
    # print(request.method)
    return jsonify({"result": True})
Beispiel #14
0
def test_user_adds_todo(user_with_password):
    user = user_with_password

    todo = Todo(name="Finish Exam", priority=4, due_date=datetime.now())

    user.todos().save(todo)
    assert user.todos().count() == 1
Beispiel #15
0
def create():
    post_form = PostForm()
    if request.method == 'POST' and post_form.validate_on_submit():
        to_do = Todo(content=post_form.todo.data)
        db.session.add(to_do)
        db.session.commit()
        return redirect(url_for('main.index'))
Beispiel #16
0
def index():
    form1 = TodoForm()
    if form1.validate_on_submit():
        day = form1.day.data
        month = form1.month.data
        year = form1.year.data
        hour = form1.hour.data
        minute = form1.minute.data
        a_p = form1.a_p.data
        date_str = year + '-' + month + '-' + day + '-' \
            + hour + '-' + minute + '-' + a_p
        datetime_obj = datetime.strptime(date_str, '%Y-%b-%d-%I-%M-%p')
        datetime_obj = datetime.astimezone(datetime_obj, pytz.UTC)
        sanitized = html.escape(form1.todo.data)
        todo = Todo(body=sanitized, author=current_user,
                    due_date=datetime_obj)
        db.session.add(todo)
        db.session.commit()
        return redirect(url_for('main.index'))

    page = request.args.get('page', 1, type=int)
    todos = current_user.all_todos().paginate(
        page, current_app.config['TODOS_PER_PAGE'], False)
    next_url = url_for('main.index', page=todos.next_num) \
        if todos.has_next else None
    prev_url = url_for('main.index', page=todos.prev_num) \
        if todos.has_prev else None
    return render_template('index.html', title=_('Home'), form=form1,
                           todos=todos.items, next_url=next_url,
                           prev_url=prev_url)
Beispiel #17
0
def todolist(id):
    todolist = TodoList.query.filter_by(id=id).first_or_404()
    form = TodoForm()
    if form.validate_on_submit():
        Todo(form.todo.data, todolist.id, _get_user()).save()
        return redirect(url_for("main.todolist", id=id))
    return render_template("todolist.html", todolist=todolist, form=form)
Beispiel #18
0
def test_add_duplicated_todo():
    new_todo1 = Todo(name="test1", priority=1)
    try:
        add_todo(new_todo1)
        assert False
    except Exception:
        assert True
Beispiel #19
0
def new_todolist():
    form = TodoForm(todo=request.form.get("todo"))
    if form.validate():
        todolist = TodoList(creator=_get_user()).save()
        Todo(form.todo.data, todolist.id).save()
        return redirect(url_for("main.todolist", id=todolist.id))
    return redirect(url_for("main.index"))
Beispiel #20
0
def add():
    form = createTask()

    if request.method == "POST":
        description = request.form.get("description")
        content = request.form.get("content")
        # get the value of datetime in the form of html and then change the HTML's format to DB's format
        deadline = request.form.get("deadline")
        deadline = transformForm(deadline)
        # inserting the inputs to the database
        todo = Todo(
            description=description,
            content=content,
            deadline=deadline,
            status=False,
            statusShare=True,
            user=current_user._get_current_object(),
        )
        db.session.add(todo)
        db.session.commit()
        flash("Task successfully created!", "success")

        # flash('Successfully to create task!', 'success')

        return redirect(url_for("home"))
        # posts = Todo.query.order_by(Todo.timestamp.desc()).all()
    return render_template("tasks.html",
                           form=form,
                           legend="New Tasks",
                           title="add")
Beispiel #21
0
    def test_adding_new_todo_without_user(self):
        todo = Todo(description=self.read_todo_description,
                    todolist_id=TodoList().save().id).save()
        todo_from_db = Todo.query.filter_by(id=todo.id).first()

        self.assertEqual(todo_from_db.description, self.read_todo_description)
        self.assertIsNone(todo_from_db.creator)
Beispiel #22
0
def admin():
    if request.method == 'POST':
        event_name = request.form['name']
        event_desc = request.form['desc']
        event_date = request.form['date']
        new_event = Todo(name=event_name, desc=event_desc, date=event_date)
        try:
            db.session.add(new_event)
            db.session.commit()
            return redirect('/')
        except:
            return 'there was an error'
    else:
        events = Todo.query.all()
        #rows = Todo.query.count()
        names = []
        descs = []
        dates = []
        for event in events:
            names.append(event.name)
            descs.append(event.desc)
            dates.append(event.date)
    #return render_template('Current.html', names=names, descs=descs, dates=dates, peter=peter) # ,events=events, rows=rows)
    return render_template('admin.html',
                           events=events,
                           name=current_user.username)
Beispiel #23
0
def update():
    form = TodoForm()
    new_todo = Todo(body=form.todo.data, owner=current_user)
    db.session.add(new_todo)
    db.session.commit()
    todos = current_user.todos.order_by(Todo.timestamp.desc()).all()
    return render_template('todolist.html', todos=todos)
Beispiel #24
0
 def test_delete(self):
     todo = Todo(title='test', complete=False)
     self.session.add(todo)
     created_todo = Todo.query.filter_by(title='test').first()
     self.session.delete(created_todo)
     result = Todo.query.filter_by(title='test').first()
     self.assertIsNone(result)
Beispiel #25
0
def add():
    # form = TodoForm(request.form)
    form = TodoForm()
    if form.validate_on_submit():
        todo = Todo(content=form.content.data)
        todo.save()
    todos = Todo.query.order_by(desc(Todo.time)).all()
    return render_template('index.html', todos=todos, form=form)
Beispiel #26
0
def add_todolist_todo(todolist_id):
    todolist = TodoList.query.get_or_404(todolist_id)
    try:
        todo = Todo(description=request.json.get('description'),
                    todolist_id=todolist.id).save()
    except:
        abort(400)
    return jsonify(todo.to_dict()), 201
Beispiel #27
0
def add():
    form = TodoForm(request.form)
    if form.validate():
        content = form.content.data
        todo = Todo(content=content, time=datetime.now())
        todo.save()
    todos = Todo.objects.order_by('-time')
    return render_template("index.html", todos=todos, form=form)
Beispiel #28
0
 def test_delete_todo(self):
     todolist = TodoList(self.shopping_list_title).save()
     todo = Todo("A book about TDD", todolist.id).save()
     self.assertEqual(todolist.todo_count, 1)
     todo_id = todo.id
     todo.delete()
     self.assertIsNone(Todo.query.get(todo_id))
     self.assertEqual(todolist.todo_count, 0)
Beispiel #29
0
def init_database(test_client):
    # Create the database and the database table
    db.create_all()

    # Insert todolist data
    list1 = Todo(content='babachichi', status=4, done=False)
    list2 = Todo(content='hahahaha', status=3, done=True)
    db.session.add(list1)
    db.session.add(list2)

    # Commit the changes for the users
    db.session.commit()

    yield  # this is where the testing happens!

    Todo.query.delete()
    db.session.commit()
Beispiel #30
0
def add():
    form = TodoForm(request.form)
    if form.validate():
        content = request.form.get("content")
        todo = Todo(content=content)
        todo.save()
    todos = Todo.objects.all()
    return render_template('index.html', todos=todos, form=form)