/
README
143 lines (102 loc) · 4.25 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
Description:
This is a basic todo-list application to illustrate 'CRUD' principles.
Setup/installation:
1. Set up virtualenv
Meringue:todolist chriszf$ virtualenv --no-site-packages --clear env
Meringue:todolist chriszf$ source env/bin/activate
(env)Meringue:todolist chriszf$
2. Set up the packages needed
(env)Meringue:todolist chriszf$ pip install -r requirements.txt
3. Run the database setup
(env)Meringue:todolist chriszf$ ./db_setup.py
Created the todolist database
(env)Meringue:todolist chriszf$
Experimenting with the task creation and deletion:
Start a python session while your virtual environment is active and do the
following import.
eg:
(env)Meringue:todolist chriszf$ python
Python 2.7.1 (r271:86832, Jun 25 2011, 05:09:01)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import todolist.model as m
To create a new task, make an instance of the Task() class. The Task
initializer looks like this:
model.Task(title)
The title of the task is a string 64 characters or less.
eg:
>>> t = m.Task("Buy milk")
>>> print t
Task -1:Buy milk Not Complete.
Notice the task has task id of -1. This is because the task must first be saved
to the database before receiving an id number.
To save to the database, is a two-step process, similar to the git commit
process. If this is a brand new Task, it must be first added to the database
for consideration.
model.add(task)
This adds a task to be considered for saving. This function should only be
used for new Tasks. If the Task has been added before, or has been pulled
from the database, it is not necessary to call this function.
eg:
>>> m.add(t)
>>>
After 'adding' the task, the next step is to save all outstanding changes.
model.save_all()
This takes all new tasks that have been added and all existing tasks that
have been changed and commits the change to the database. New tasks that
are saved are assigned an id number at this time.
eg:
>>> m.save_all()
>>> print t
Task 1:Buy milk Not Complete.
Updating a task:
Here is the documentation for the class task.
class Task
Task(title, notes = '')
Create a new task with a title text being set to title. Task titles are
strings up to 64 characters in length. A task can also have notes attached.
Notes are strings of arbitrary length.
The Task class supports the following attributes
id
The id is an integer that is automatically created and assigned to the task
when it is saved to the database. It is a number unique to a specific task
and should not be modified.
title
The title is a string up to 64 characters long
notes
The notes attribute is a string arbitrarily long. It is not required.
done
The done attribute is a boolean representing whether or not a task is
complete.
created_at
A datetime representing the date of creation.
completed_at
A datetime representing the date of completion.
Task.complete()
Complete a task by marking it done and setting the
completed_at date to the current time.
# Class methods
Task.query
Interface to creating a database query, not useful without accessing the
attributes on query.
Task.query.all()
Returns all the existing tasks from the database as a list.
Task.query.get(id)
Returns a task with the given numeric id from the database. If the given
task id does not exist, returns None.
When updating an existing task, you must call model.save_all() to actually save the changes to the database.
eg:
>>> t = m.Task.query.get(1)
>>> print t
Task 1:Finish this todolist application. Not Complete.
>>> t.title = "No, seriously, finish this application."
>>> t.complete()
>>> m.save_all()
>>> print t
Task 1:Finish this todolist application. Completed.
>>> print t.completed_at
2012-07-02 14:28:16.405071
Getting started
The webapp code is in the file todolist/webapp.py. Right now, there are three
'views' listed, one for the index, one for the editing anew task, and one for
saving a task. We will be filling those in.