Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
1 change: 1 addition & 0 deletions migrations/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generic single-database configuration.
45 changes: 45 additions & 0 deletions migrations/alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# A generic, single database configuration.

[alembic]
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false


# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
73 changes: 73 additions & 0 deletions migrations/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from __future__ import with_statement
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from flask import current_app
config.set_main_option('sqlalchemy.url', current_app.config.get('SQLALCHEMY_DATABASE_URI'))
target_metadata = current_app.extensions['migrate'].db.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.

def run_migrations_offline():
"""Run migrations in 'offline' mode.

This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.

Calls to context.execute() here emit the given string to the
script output.

"""
url = config.get_main_option("sqlalchemy.url")
context.configure(url=url)

with context.begin_transaction():
context.run_migrations()

def run_migrations_online():
"""Run migrations in 'online' mode.

In this scenario we need to create an Engine
and associate a connection with the context.

"""
engine = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)

connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata
)

try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()

if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

22 changes: 22 additions & 0 deletions migrations/script.py.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""${message}

Revision ID: ${up_revision}
Revises: ${down_revision}
Create Date: ${create_date}

"""

# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}

from alembic import op
import sqlalchemy as sa
${imports if imports else ""}

def upgrade():
${upgrades if upgrades else "pass"}


def downgrade():
${downgrades if downgrades else "pass"}
13 changes: 13 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from flask.ext.script import Manager
from flask.ext.migrate import Migrate, MigrateCommand
from flask.ext.script.commands import ShowUrls, Clean

from todo import app, db

migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
manager.add_command('show-urls', ShowUrls())
manager.add_command('clean', Clean())

manager.run()
13 changes: 13 additions & 0 deletions todo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy

DATABASE = '/tmp/to_dov2.db'
DEBUG = True
SECRET_KEY = 'development key'
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + DATABASE

app = Flask(__name__)
app.config.from_object(__name__)
db = SQLAlchemy(app)

from . import views
6 changes: 6 additions & 0 deletions todo/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from flask_wtf import Form
from wtforms import StringField
from wtforms.validators import DataRequired

class TodoForm(Form):
text = StringField('text', validators=[DataRequired()])
43 changes: 43 additions & 0 deletions todo/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from . import db

class Users(db.Model):
username = db.Column(db.String(32), primary_key=True)
password = db.Column(db.String(120))

def __init__(self, username, password):
self.username = username
self.password = password

def __repr__(self):
return "<User {}>".format(self.username)


class ToDo(db.Model):

id = db.Column(db.Integer, primary_key=True)
owner = db.Column(db.String(32), db.ForeignKey(Users.username))
text = db.Column(db.String(255), nullable=False)
due_date = db.Column(db.DateTime)
completed_at = db.Column(db.DateTime)

def __init__(self, owner, text):
self.owner = owner
self.text = text

def __repr__(self):
return "<Todo {}>".format(self.text)

class Notes(db.Model):

id = db.Column(db.Integer, primary_key=True)
owner = db.Column(db.String(32), nullable=False)
todo_reference = db.Column(db.Integer, db.ForeignKey(ToDo.id))
text = db.Column(db.String(255), nullable=False)

def __init__(owner, todo_reference, text):
self.owner = owner
self.todo_reference = todo_reference
self.text = text

def __repr__(self):
return "<Notes {}>".format(self.text)
File renamed without changes.
47 changes: 47 additions & 0 deletions todo/static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
body { font-family: sans-serif; background: #eee; }
a { color: #377ba8; }
h1, h2, li { color: #000; }
h1, h2, li { font-family: 'Georgia', serif; margin: 0; }
h2, li { font-size: 1.2em; }

.page { margin: 2em auto; width: 35em; border: 5px solid #ccc;
padding: 0.8em; background: white; }
.entries { list-style: none; margin: 0; padding: 0; }
.entries li { margin: 0.8em 1.2em; }
.entries li h2 { margin-left: 1em; }
.add-entry { font-size: 0.9em; border-bottom: 1px solid #ccc; }
.add-entry dl { font-weight: bold; }
.metanav { text-align: right; font-size: 0.8em; padding: 0.3em;
margin-bottom: 1em; background: #fafafa; }
.flash { background: #cee5F5; padding: 0.5em;
border: 1px solid #aacbe2; }
.error { background: #f0d6d6; padding: 0.5em; }

div.ui-btn, button, input[type="submit"] {
/*width:60px;*/
background:#09C;
color:#fff;
font-family: Tahoma, Geneva, sans-serif;
/*height:20px;*/
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
border: 1p solid #999;
margin-top: 2px
}
div.ui-btn, button:hover, input[type="submit"]:hover{
background:#cccccc;
color:#09C;
}
div.ui-btn, input[class="edit"] {
/*width:60px;*/
background:#cccccc;
color:#09C;
font-family: Tahoma, Geneva, sans-serif;
/*height:20px;*/
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
border: 1p solid #999;
margin-top: 2px
}
Binary file added todo/templates/.DS_Store
Binary file not shown.
Empty file added todo/templates/.gitkeep
Empty file.
12 changes: 12 additions & 0 deletions todo/templates/add_entry.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "layout.html" %}
{% block body %}
<form action="{{ url_for('add_entry') }}" method=POST class=add-entry>
<dl>
<dt>Add Task:
<dd><textarea name=todo rows=5 cols=40></textarea>
<dt>Deadline:
<dd><textarea name=date rows=1 cols=20></textarea>
<dd><input type=submit value=Add>
</dl>
</form>
{% endblock %}
16 changes: 16 additions & 0 deletions todo/templates/create_user.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends "layout.html" %}
{% block body %}
<h2>Choose a username and password:</h2>
{% if error %}<p class=error><strong>Error:</strong>{{ error }}{% endif %}
<form action="{{ url_for('create_user') }}" method=POST>
<dl>
<dt>Username:
<dd><input type=text name=username>
<dt>Password:
<dd><input type=password name=password>
<dd><input type=submit value=Login>
</dl>
</form>
<a href="{{ url_for('login') }}">Return to login screen.</a>

{% endblock %}
14 changes: 14 additions & 0 deletions todo/templates/display_done.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "layout.html" %}
{% block body %}
<dl>
<dt>Finished Items:
</dl>
<ul class=entries>
{% for entry in entries %}
<li>{{ entry.text|safe }} </li>
<li>Completed on: {{ entry.completed_at }}</li>
{% else %}
<li>Nothing done yet! Get to work!
</ul>
{% endfor %}
{% endblock %}
9 changes: 9 additions & 0 deletions todo/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "layout.html" %}
{% block body %}
<h1>Please Select an Action:</h1>
<ul class="entries">
<li><button onclick="location.href='{{url_for('add_entry')}}'">Add Entry</button></li>
<li><button onclick="location.href='{{url_for('show_entries')}}'">See To Do List</button></li>
<li><button onclick="location.href='{{url_for('display_done')}}'">See Completed Tasks</button></li>
</ul>
{% endblock %}
22 changes: 22 additions & 0 deletions todo/templates/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<head>
<title>To Do List</title>
<link rel=stylesheet type=text/css href="{{ url_for('static', filename='style.css') }}">
</head>
<div class=page>
<h1>To Do List:</h1>

<div class=metanav>
{% if request.path != "/" %}
<button onclick="location.href='{{url_for('main_menu')}}'">Home</button>
{% endif %}
{% if session.logged_in %}
<button onclick="location.href='{{url_for('logout')}}'">Log Out</button>
{% endif %}
</div>
{% for message in get_flashed_messages() %}
<div class=flash>{{ message }}</div>
{% endfor %}
{% block body %}
{% endblock %}
</div>
15 changes: 15 additions & 0 deletions todo/templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "layout.html" %}
{% block body %}
<h2>Login</h2>
{% if error %}<p class=error><strong>Error:</strong>{{ error }}{% endif %}
<form action="{{ url_for('login') }}" method=POST>
<dl>
<dt>Username:
<dd><input type=text name=username>
<dt>Password:
<dd><input type=password name=password>
<dd><input type=submit value=Login>
</dl>
</form>
<a href="{{ url_for('create_user') }}">Create Account!</a>
{% endblock %}
15 changes: 15 additions & 0 deletions todo/templates/show_entries.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "layout.html" %}
{% block body %}
<ul class=entries>
<form action="{{ url_for('remove_entry')}}" method=POST class=remove-entry>
{% for entry in entries %}
<li><input type=checkbox value={{ entry.id }} name=item>{{ entry.text|safe }}</input> Deadline: {{ entry.due_date }}</li>
{% else %}
<li>Nothing to do!</li>
{% endfor %}
{% if entries %}
<li><input type=submit value=Remove></li>
{% endif %}
</form>
</ul>
{% endblock %}
Loading