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
Binary file added .DS_Store
Binary file not shown.
11 changes: 0 additions & 11 deletions .homework.json

This file was deleted.

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"}
32 changes: 32 additions & 0 deletions migrations/versions/4dda8ccc9dc_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""empty message

Revision ID: 4dda8ccc9dc
Revises: None
Create Date: 2015-02-18 15:07:28.372334

"""

# revision identifiers, used by Alembic.
revision = '4dda8ccc9dc'
down_revision = None

from alembic import op
import sqlalchemy as sa


def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('todo',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('task', sa.String(length=255), nullable=False),
sa.Column('completed_at', sa.DateTime(), nullable=True),
sa.Column('due_date', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
### end Alembic commands ###


def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_table('todo')
### end Alembic commands ###
9 changes: 9 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from flask.ext.script import Manager
from flask.ext.migrate import Migrate, MigrateCommand
from to_do.app import app, db

migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)

manager.run()
22 changes: 22 additions & 0 deletions tests/test_to_do.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
import to_do


def test_create_db():
to_do.init_db()
if '/tmp/to_do.db':
assert True

def test_add_task():
task = 'take dog out'
to_do.add_task(task)
assert task in '/tmp/to_do.db'

def test_get_tasks():
to_do.add_task('take dog out')
assert to_do.get_tasks()[1] == 'take dog out'

def test_delete_task():
to_do.add_task('take dog out')
to_do.delete_task(get_tasks()[0])
assert to_do.get_tasks == False
Binary file added to_do/.DS_Store
Binary file not shown.
File renamed without changes.
28 changes: 28 additions & 0 deletions to_do/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy


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

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

class Todo(db.Model):
id = db.Column(db.Integer, primary_key=True)
text = db.Column(db.String(255), nullable=False)
completed_at = db.Column(db.DateTime)
due_date = db.Column(db.DateTime)

def __init__(self, text, due_date=None):
self.text = text
self.due_date = due_date

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


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

class TodoForm(Form):
text = StringField('text', validators=[DataRequired()])
due_date = DateField('due_date')
Binary file added to_do/static/.DS_Store
Binary file not shown.
File renamed without changes.
Loading