Esempio n. 1
0
 def test_count_todos(self):
     self.assertEqual(self.todolist.count(), 1)
     new_todo = Todo(description='test',
                     todolist_id=self.todolist.id,
                     create_user=self.user)
     new_todo.save()
     self.assertEqual(self.todolist.count(), 2)
Esempio n. 2
0
 def post(self, request):
     serializer = TodoSerializer(data=request.data)
     if not serializer.is_valid():
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
     Todo(creator=request.user, header=serializer.data['header']).save()
     return Response(request.data, status=status.HTTP_201_CREATED)
Esempio n. 3
0
def save_todo(request):
    if request.method == 'POST':
        data = json.loads(request.body.decode('utf-8'))

        if data['date'] == "":
            date = None
        else:
            date = data['date']

        if data['time'] == "":
            time = None
        else:
            time = data['time']

        to = Todo(
            title=data['title'],
            description=data['description'],
            dedline_date=date,
            dedline_time=time,
        )
        to.save()

        for tag in data['tags']:
            t = Tags.objects.all().filter(title=tag).first()
            if not t:
                t = Tags(title=tag)
                t.save()
            to.tags.add(t)
            to.save()

    return HttpResponse()
    def setUp(self):
        self.config = testing.setUp()
        from sqlalchemy import create_engine
        #engine = create_engine('sqlite:///todolist.sqlite')
        engine = create_engine(
            'postgresql://*****:*****@localhost:5432/todolist_test')

        DBSession.configure(bind=engine)
        Base.metadata.create_all(engine)
        # the transaction commited after added so rolling back doesnt work on Postgres
        #with transaction.manager:
        instances = (Todo(task='Second task',
                          priority=0), Todo(task='Thrid task', priority=5),
                     Todo(task='First task', priority=10),
                     Todo(task="Done task", priority=5,
                          done_at=datetime.now()))
        DBSession.add_all(instances)
Esempio n. 5
0
def add(username):
    user = User.query.filter_by(username=username).first()
    if user:
        todo = Todo(text=request.form['todoitem'],
                    complete=False,
                    user_id=user.id)
        db.session.add(todo)
        db.session.commit()
    return redirect(url_for('todos.todo', username=username))
Esempio n. 6
0
def create(request):
    todo = Todo(
        task=request.POST.get('task', None), 
        priority=request.POST.get('priority', None)
    )
    if not todo.save():
        return {'errors': todo.errors}
    # todos, done_todos = get_todo_set()
    return {'id': todo.id, 'task': todo.task, 'priority':todo.priority, 'messages': '%s has been created' % todo.task } #, \
Esempio n. 7
0
 def setUp(self):
     self.user = User.objects.create_user('test', '*****@*****.**',
                                          'test')
     self.todolist = TodoList(title='title', create_user=self.user)
     self.todolist.save()
     self.todo = Todo(description='description',
                      todolist_id=self.todolist.id,
                      create_user=self.user)
     self.todo.save()
Esempio n. 8
0
 def setUp(self):
     self.user = User.objects.create_user('test', '*****@*****.**',
                                          'test')
     self.todolist = TodoList(title='test title', create_user=self.user)
     self.todolist.save()
     self.todo = Todo(description='save todo',
                      todolist_id=self.todolist.id,
                      create_user=self.user)
     self.todo.save()
     self.client.login(username='******', password='******')
Esempio n. 9
0
 def test_count_closed_todos(self):
     self.assertEqual(self.todolist.count_finished(), 0)
     new_todo = Todo(description='test',
                     todolist_id=self.todolist.id,
                     create_user=self.user)
     new_todo.close()
     self.todo.close()
     self.assertEqual(self.todolist.count_finished(), 2)
     self.assertIsNotNone(new_todo.deadline)
     self.todo.reopen()
     self.assertEqual(self.todolist.count_finished(), 1)
     self.assertIsNone(self.todo.deadline)
Esempio n. 10
0
def home(request):
    if request.method == "POST":
        if request.POST.get("event") == "":
            lst = Todo.objects.all()
            return render(request, 'home.html', {"err": "请输入内容", "lst": lst})
        else:
            events = Todo(events=request.POST.get("event"), finished=False)
            events.save()
            lst = Todo.objects.all()
            return render(request, 'home.html', {"info": "添加成功", "lst": lst})
    else:
        lst = Todo.objects.all()
        return render(request, 'home.html', {"lst": lst})
Esempio n. 11
0
def inittodo():
    todos = [
        '我要去新疆',
        '我要去云南',
        '我要去贵州',
        '我要去四川',
        '我要去重庆',
    ]
    for item in todos:
        n1 = Todo(title=item, createTime=datetime.now())
        db.session.add(n1)
        db.session.commit()
    click.echo('init the todolist')
Esempio n. 12
0
def index():
    todo = Todo.query.order_by('id')    #两个方法,如果是post,那么就添加数据,否则就是请求数据。
    _form = request.form
    if request.method == 'POST':
        title = _form['title']
        td = Todo(title = title)
        try:
            td.store_to_db()
            flash('add task Done')
            return  redirect(url_for('todo.index'))
        except Exception as e:
            print e
            flash('add failue')
    return render_template('index.html',todo = todo)
Esempio n. 13
0
def todolist(request):
    if request.method == 'POST':
        atodo = request.POST['todo']
        priority = request.POST['priority']
        user = User.objects.get(id='1')
        todo = Todo(user=user, todo=atodo, priority=priority, flag='1')
        todo.save()
        return HttpResponseRedirect('/')
    todolist = Todo.objects.filter(flag=1)
    finishtodos = Todo.objects.filter(flag=0)
    return render_to_response('simpleTodo.html', {
        'todolist': todolist,
        'finishtodos': finishtodos
    },
                              context_instance=RequestContext(request))
Esempio n. 14
0
def add_todo(request, todolist_id):
    if request.method == 'POST':
        form = TodoForm(request.POST)
        if form.is_valid():
            user = request.user if request.user.is_authenticated else None
            todo = Todo(title=request.POST['description'],
                        description=request.POST['description'],
                        todolist_id=todolist_id,
                        create_user=user)
            todo.save()
            return redirect('lists:todolist', todolist_id=todolist_id)
        else:
            return render(request, 'todolist/todolist.html', {'form': form})

    return redirect('lists:index')
Esempio n. 15
0
def new_todolist(request):
    if request.method == 'POST':
        form = TodoForm(request.POST)
        if form.is_valid():
            # create default todolist
            user = request.user if request.user.is_authenticated else None
            todolist = TodoList(create_user=user)
            todolist.save()
            todo = Todo(description=request.POST['description'],
                        todolist_id=todolist.id,
                        create_user=user)
            todo.save()
            return redirect('lists:todolist', todolist_id=todolist.id)
        else:
            return render(request, 'todolist/index.html', {'form': form})

    return redirect('lists:index')
Esempio n. 16
0
def addTodo(request):
    if request.method == 'POST':
        newTodo = request.POST['todo']
        priority = request.POST['priority']
        user = User.objects.get(id='1')
        todo = Todo(pubUser=user,
                    todo=newTodo,
                    todoPriority=priority,
                    todoStatus=1)
        todo.save()
        todolist = Todo.objects.filter(todoStatus=1)
        finishtodos = Todo.objects.filter(todoStatus=0)
        return render(request, 'todolist/reloadTodo.html', {
            'todolist': todolist,
            'finishtodos': finishtodos
        })
    else:
        todolist = Todo.objects.filter(todoStatus=1)
        finishtodos = Todo.objects.filter(todoStatus=0)
        return render(request, 'todolist/index.html', {
            'todolist': todolist,
            'finishtodos': finishtodos
        })
Esempio n. 17
0
def addtodo():
    todo = Todo(createTime=datetime.now(), title=request.json['title'])
    db.session.add(todo)
    db.session.commit()
    return jsonify(id=todo.id)
Esempio n. 18
0
 def create(self, validated_data):
     todo = Todo(name=validated_data['name'],
                 is_active=validated_data['is_active'],
                 owner=validated_data['owner'])
     todo.save()
     return todo
Esempio n. 19
0
def add(content):
    newtodo = Todo(content=content)
    newtodo.save()
    return None