Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
be9cd2f
initial
anamecheverri Feb 26, 2015
e2ec176
initial
anamecheverri Feb 26, 2015
5bf03b0
web app and api working except for updates
anamecheverri Mar 1, 2015
e99e894
easy mode finished. Everything works except for task updates through …
anamecheverri Mar 1, 2015
9eab684
fixed labels for links
anamecheverri Mar 1, 2015
394acb4
update issues fixed
anamecheverri Mar 1, 2015
cb0f8be
api ready. issues still with update of task. update of stats works fine
anamecheverri Mar 1, 2015
a2d8122
final forms easy mode
anamecheverri Mar 1, 2015
7d0f1a8
final index.html easy mode
anamecheverri Mar 1, 2015
86a6ccd
final tasks view easy mode
anamecheverri Mar 1, 2015
7a69a16
final api view easy mode
anamecheverri Mar 1, 2015
a74bfc6
added selectbox for type
anamecheverri Mar 1, 2015
0dd20bc
easy-mode done. web and api
anamecheverri Mar 2, 2015
a96c706
removed select box for type
anamecheverri Mar 2, 2015
68e32e9
added url to dict
anamecheverri Mar 2, 2015
1e08bdb
nothing
anamecheverri Mar 2, 2015
f7798ee
fixed url //
anamecheverri Mar 2, 2015
39e9748
added cascade on delete
anamecheverri Mar 2, 2015
b55a020
updated Procfile
anamecheverri Mar 2, 2015
2fbeb36
updated
anamecheverri Mar 2, 2015
89a7d69
r
anamecheverri Mar 2, 2015
fbb0f67
updated file
anamecheverri Mar 2, 2015
1769d88
remove import hashid
anamecheverri Mar 2, 2015
33f12a2
heroku
anamecheverri Mar 2, 2015
d940fb1
removed library
anamecheverri Mar 2, 2015
4a95fc2
added js. Messed up everything
anamecheverri Mar 4, 2015
191967a
added changes to the api.
anamecheverri Mar 4, 2015
103225f
updated end points
anamecheverri Mar 4, 2015
2125728
reviewing endpoints
anamecheverri Mar 4, 2015
9aeaf02
changed forms to APIforms. separated put, delete, post. now forms are…
anamecheverri Mar 5, 2015
80cfb6c
not much changed
anamecheverri Mar 5, 2015
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
46 changes: 46 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
*.py[cod]

# C extensions
*.so

# Packages
*.egg
*.egg-info
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox
nosetests.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Complexity
output/*.html
output/*/index.html

# Sphinx
docs/_build

.webassets-cache

# Virtualenvs
env
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn manage:app --log-file=-
18 changes: 18 additions & 0 deletions curls
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
curl -v -H "Authorization: Basic [email protected]:ana" -X PUT -d '{"name":"calories consumption","t_type":1,"units":"calories"}' http://127.0.0.1:5000/tasker/api/v1/activities/1

curl -v -H "Authorization: Basic [email protected]:ana" http://127.0.0.1:5000/tasker/api/v1/activities/1

curl -v -H "Authorization: Basic [email protected]:ana" -X DELETE http://127.0.0.1:5000/tasker/api/v1/activities/4

curl -v -H "Authorization: Basic [email protected]:ana" -X POST -d '{"tr_date":"2014/01/01","tr_value":1}' http://127.0.0.1:5000/tasker/api/v1/activities/1/stats

curl -v -H "Authorization: Basic [email protected]:ana" -X DELETE -d '{"tr_date":"2014/01/01"}' http://127.0.0.1:5000/tasker/api/v1/activities/1/stats

curl -v -H "Authorization: Basic [email protected]:ana" -X PUT -d '{"tr_date":"2015/02/27", "tr_value":20}' http://127.0.0.1:5000/tasker/api/v1/activities/1/stats


curl -v -H "Authorization: Basic [email protected]:ana" -X PUT -d '{"t_name":"calories consumption","t_type":1,"t_units":"calories"}' http://127.0.0.1:5000/tasker/api/v1/activities/1

curl -v -H "Authorization: Basic [email protected]:ana" -X POST -d '{"t_name":"cooking","t_type":1,"t_units":"hours"}' http://127.0.0.1:5000/tasker/api/v1/activities

curl -v -H "Authorization: Basic [email protected]:ana" http://127.0.0.1:5000/tasker/api/v1/activities
63 changes: 63 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python
import os
import csv
import random
from datetime import date

from flask.ext.script import Manager, Shell, Server
from flask.ext.migrate import MigrateCommand
from flask.ext.script.commands import ShowUrls, Clean

from tasker import create_app, db, models

HERE = os.path.abspath(os.path.dirname(__file__))
TEST_PATH = os.path.join(HERE, 'tests')

app = create_app()
manager = Manager(app)
manager.add_command('server', Server())
manager.add_command('db', MigrateCommand)
manager.add_command('show-urls', ShowUrls())
manager.add_command('clean', Clean())


@manager.shell
def make_shell_context():
""" Creates a python REPL with several default imports
in the context of the app
"""
return dict(app=app,
db=db,
user=models.User,
task=models.Task,
tracking=models.Tracking
)


@manager.command
def test():
"""Run the tests."""
import pytest
exit_code = pytest.main([TEST_PATH, '--verbose'])
return exit_code

@manager.command
def seed_stats():
myusers = models.User.query.order_by(models.User.id.desc()).all()
for user in myusers:
tasks = models.Task.query.filter_by(t_user=user.id).all()
for task in tasks:
month = 1
days = 31
for month in range(1,3):
for day in range(1,days):
r_date = date(2015,month,day)
r_value = random.randint(1,100)
stat = models.Tracking(user.id, task.id, r_date, r_value)
db.session.add(stat)
days = 28
db.session.commit()


if __name__ == '__main__':
manager.run()
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.
Binary file added migrations/__pycache__/env.cpython-34.pyc
Binary file not shown.
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"}
26 changes: 26 additions & 0 deletions migrations/versions/22e559aaea2_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""empty message

Revision ID: 22e559aaea2
Revises: c0fd22a946
Create Date: 2015-03-02 07:22:03.294992

"""

# revision identifiers, used by Alembic.
revision = '22e559aaea2'
down_revision = 'c0fd22a946'

from alembic import op
import sqlalchemy as sa


def upgrade():
### commands auto generated by Alembic - please adjust! ###
pass
### end Alembic commands ###


def downgrade():
### commands auto generated by Alembic - please adjust! ###
pass
### end Alembic commands ###
Binary file not shown.
57 changes: 57 additions & 0 deletions migrations/versions/c0fd22a946_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""empty message

Revision ID: c0fd22a946
Revises: None
Create Date: 2015-02-28 16:01:43.793939

"""

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

from alembic import op
import sqlalchemy as sa


def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('email', sa.String(length=255), nullable=False),
sa.Column('encrypted_password', sa.String(length=60), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
op.create_table('task',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('t_name', sa.String(length=255), nullable=False),
sa.Column('t_type', sa.Integer(), nullable=False),
sa.Column('t_units', sa.String(length=255), nullable=False),
sa.Column('t_user', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['t_user'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('tracking',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('tr_value', sa.Integer(), nullable=False),
sa.Column('tr_beg_value', sa.Integer(), nullable=True),
sa.Column('tr_end_value', sa.Integer(), nullable=True),
sa.Column('tr_target_date', sa.Date(), nullable=True),
sa.Column('tr_date', sa.Date(), nullable=False),
sa.Column('tr_task_id', sa.Integer(), nullable=True),
sa.Column('tr_user_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['tr_task_id'], ['task.id'], ),
sa.ForeignKeyConstraint(['tr_user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
### end Alembic commands ###


def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_table('tracking')
op.drop_table('task')
op.drop_table('user')
### end Alembic commands ###
Loading