In this first assignment, you will write a backend to service a cloud-based todo list app. In this day and age, cloud-based products for viewing and saving various forms of content (photos, bookmarks, todo lists, etc.) are becoming increasingly popular, due to their ability to offload data from your local machine to the cloud, service your data to multiple platforms, etc.
This project aims to help you "ramp up" and get comfortable working with the following tools / technologies / concepts:
Python
as a language and aFlask
as a frameworkJSON
as a means of sending and receiving dataHTTP
requests and responses- Data modeling
- Basic exposure to SQL querying
- System configuration
Python
/Command-Line-Based
Testing
- Academic Integrity
- System Configuration
- Organization
- Expected Functionality
- Testing Your Code
- Extending the Assignment
- Project Submission
Note that these projects should be completed individually. As a result, all University-standard AI guidelines should be followed.
One of the reasons we chose Flask
as an initial backend framework for students to use is because of its phenomenal support online. Looking up framework documentation and adapting the docs' sample code to suite your own needs in something we expect and want you to do, as it allows you to explore and increase your self-sufficiency regarding backend development. However, if you find code in a StackOverflow
post or in an open source Github
repository, then you should cite it accordingly. See the project submission section for guidelines as to where to include those citations.
Perform the following steps in order:
You can check via:
python --version
If your version differs, then download 2.7
here
.
PyPI
allows one to easily download Python
modules required to run the project, as well as ones that may help you perform certain tasks in the future of the course. PyPI
is essential.
For this project and future projects, we will be using git. If you don't have git, you can find it here
.
You can clone the source code of this project by running the following:
git clone https://github.com/Cornell-PoBE/A1.git
cd A1
Virtualenv
helps establish an isolated Python
environment. The environment allows you to separate project-specific dependencies and their versions from the Python
modules installed locally on your computer. Once you have virtualenv
, run the following inside of the A1 directory:
virtualenv -p python2.7 venv
This creates a virtual environment called venv
. In order to enter than virtual environment, run the following:
source venv/bin/activate
The following command line prompt will indicate that you’re in the virtual environment:
(venv) >
To deactivate the virtual environment, run the following:
deactivate
Whenever you work with this project, you should always be in your virtual environment. Without this isolation, we might run into module versioning issues and other problems when trying to run your project, which creates administrative overhead.
At the root of directory of the project skeleton code, run the following:
pip install -r src/requirements.txt
This installs within your virtual environment all the necessary modules that are required at the beginning of the project.
Having been given some initial exposure to SQL
databases in class, the concept of "querying" data is one that we expect you to have a basic grasp of when approaching the future lectures on databases. As a result, we have decided to use SQLite
in this project as our means of storing and querying data. It provides a simple interface you can leverage via its Python
module, which is included, by default, in the version of Python we use for this class Python 2.7
.
SQLite
can be installed by following this
guide.
NOTE: The overarching system configuration concepts are explained in more detail in this guide
, which we are using as our standard for setting up Flask
apps in this course. For information regarding advanced system configuration (which you might need for some of the project extensions, if you tackle them), refer to that guide.
The following describes the initial file-structure of the directory ./src
:
.
├── config.py
├── requirements.txt
├── run.py
├── test.py
└── todo
├── __init__.py
├── db.py
├── models.py
└── routes.py
Below consists of brief discussions of each one of the above files:
config.py
defines the configuration for theFlask
app to run with. You do not need to touch this file.requirements.txt
outlines the initial module dependencies of the app. To install these, runpip install -r requirements.txt
. If youpip install
a module during the duration of your project, be sure topip freeze > requirements.txt
to add the new module to therequirements.txt
file, or else we won't be able to run your projectrun.py
is the run script for theFlask
app. You do not need to touch this file.test.py
is the test script for theFlask
app. You will use this file to monitor your progress as you implement all the necessary functionality.todo/__init__.py
defines theFlask
app instance. You do not need to touch this file.todo/db.py
defines a driver that reads and writes files as a form of persisting the data of your app. Read this file to get an idea of what functionalities it affords you and what you'll need to add to it. It outlines examples of how to perform basic storage operations. You should be writing basic storage operations to manipulate the data of your app.todo/models.py
is where you should define the models of your application. All models should inherit fromModel
, which is the base class defining fundamental fields / functions required to store models as files.todo/routes.py
defines all the routes (a.k.a. endpoints) that users will be able to interact with in order to create todo list items, delete todo list items, and list todo list items.
This initial framework is just a guideline to implementing the base features of the app. Feel free to change / reorganize at will. However, the expected functionality (listed below) stays the same.
In this project, we expect you to make an API
that lets an application make requests to perform operations on todo list items called "tasks"
.
Essentially, the application is just keeping track of a series of tasks that a person has to do. Tasks should contain the following:
- A unique ID (see
Model
class that you should be extending from) - A name
- A description
- A list of tags (like 'laundry', 'urgent', 'etc.')
- A time of creation
- A due date
You should write a model to represent this series of information called Task
. In addition, you should write endpoints that allow for the following functionality:
POST /tasks?name={name}&description={description}&tags={tags (comma separated)}&due_date={due date (in unix time)}
Creates a task with the following parameters. Testing is done via request.args
in test.py
. As such, you only need to ensure that all the tests pass in test.py
to get full credit.
{
"due_date": 1519328894,
"description": "Need to jog",
"tags": "run,jog,sprint",
"created_at": 1519328894,
"id": "3ab1a7e6-1833-11e8-af3d-9801a7a5b675",
"name": "jogging"
}
GET /tasks
Get a list of all tasks
[{
"due_date": 1519328894,
"description": "Need to jog",
"tags": "run,jog,sprint",
"created_at": 1519328894,
"id": "3ab1a7e6-1833-11e8-af3d-9801a7a5b675",
"name": "jogging"
}]
GET /tasks?id={id}
Get a task by its ID
[{
"due_date": 1519328894,
"description": "Need to jog",
"tags": "run,jog,sprint",
"created_at": 1519328894,
"id": "3ab1a7e6-1833-11e8-af3d-9801a7a5b675",
"name": "jogging"
}]
DELETE /tasks?id={id}
Delete a specific task
{
"success": "true"
}
DELETE /tasks/all
Delete all tasks
{
"success": "true"
}
We recommend testing your code using Flask Testing
, or cURL-ing
from the command line (although we prefer the tool httpie
:)
).
To make your lives easier we have provided you our test cases in the test.py
file that you may leverage to test your endpoints. This file uses the unittest
module extensively and can be extended if you wish to further develop your test suite to handle your own edge cases.
You can extend this assignment in the following ways:
- Provide endpoints for updating any part of a specific task (name, description, tags, due date)
- Create a
List
model that own tasks (separate tasks into different todo lists). Create aCRUD
interface for lists (Create, Read, Update, Delete) and modify the task creation endpoint to specify alist_id
- Add a front-end for utilizing your
API
(we recommendReact
,Angular
, orjQuery
for makingAJAX
requests to yourAPI
) - Anything else you may like!
You should submit your project along with a readme.txt
for your citations, project setup information, and any extensions you might have done. This should be at the root of your project (inside the src
directory). Run the following to zip your project:
zip -r src.zip src -x src/venv\*
You can then submit this file to CMS
.
You will be graded based on how many test cases you pass. Our test cases are provided for you in the test.py file.