Browse Source

now with flask; index shows all routes

master
Julio Biason 10 years ago
parent
commit
21be36a582
  1. 4
      .gitignore
  2. BIN
      luncho/.server.py.swp
  3. 4
      luncho/__init__.py
  4. BIN
      luncho/blueprints/.index.py.swp
  5. 0
      luncho/blueprints/__init__.py
  6. 34
      luncho/blueprints/index.py
  7. 24
      luncho/database.py
  8. 39
      luncho/server.py
  9. 14
      manage.py
  10. 2
      requirements.txt

4
.gitignore vendored

@ -6,3 +6,7 @@ lib-cov
*.out
*.pid
*.gz
*.pyc
.venv
.ropeproject

BIN
luncho/.server.py.swp

Binary file not shown.

4
luncho/__init__.py

@ -0,0 +1,4 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

BIN
luncho/blueprints/.index.py.swp

Binary file not shown.

0
luncho/blueprints/__init__.py

34
luncho/blueprints/index.py

@ -0,0 +1,34 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""The index blueprint. There is nothing here, we just show a summary of
the current API requests."""
from operator import itemgetter
from flask import Blueprint
from flask import jsonify
from flask import current_app
index = Blueprint('index', __name__)
@index.route('')
def show_routes():
"""List the current API"""
routes = []
for rule in current_app.url_map.iter_rules():
endpoint = rule.endpoint
if endpoint == 'static':
continue
path = str(rule)
methods = rule.methods
doc = current_app.view_functions[endpoint].__doc__
routes.append([
path,
doc
])
routes.sort(key=itemgetter(0))
return jsonify(routes)

24
luncho/database.py

@ -0,0 +1,24 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import datetime
from pony.orm import Database
from pony.orm import PrimaryKey
from pony.orm import Optional
from pony.orm import Required
# from pony.orm import Set
db = Database("sqlite", "tagallery.db", create_db=True)
class User(db.Entity):
"""Users."""
username = PrimaryKey(unicode)
passhash = Required(unicode)
token = Optional(unicode) # 1. if the user never logged in, they will
# not have a token.
# 2. This forces the user to have a single
# login everywhere, per day.
issue_date = Optional(datetime.datetime)
db.generate_mapping(create_tables=True)

39
luncho/server.py

@ -0,0 +1,39 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import sys
from flask import Flask
# ----------------------------------------------------------------------
# Config
# ----------------------------------------------------------------------
SQLITE_FILENAME = './luncho.db3'
# ----------------------------------------------------------------------
# Load the config
# ----------------------------------------------------------------------
app = Flask(__name__)
app.config.from_object(__name__)
app.config.from_envvar('LUCNHO_CONFIG', True)
# ----------------------------------------------------------------------
# Blueprints
# ----------------------------------------------------------------------
from blueprints.index import index
app.register_blueprint(index, url_prefix='/')
# ----------------------------------------------------------------------
# Database
# ----------------------------------------------------------------------
from pony.orm import db_session
app.wsgi_app = db_session(app.wsgi_app)
# ----------------------------------------------------------------------
# Main
# ----------------------------------------------------------------------
if __name__ == '__main__':
log.warning('Use manage.py to run the server.')
sys.exit(1)

14
manage.py

@ -0,0 +1,14 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import logging
from flask.ext.script import Manager
from luncho.server import app
manager = Manager(app)
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
manager.run()

2
requirements.txt

@ -1,3 +1,3 @@
Flask
flask-script
flask-sqlalchemy
pony

Loading…
Cancel
Save