forked from Faerbit/todo-backend-flask
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
40 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import os | ||
from flask import Flask | ||
from flask.ext.cors import CORS | ||
|
||
DATABASE=os.getenv("DATABASE_URL", "sqlite://") | ||
DATABASE=DATABASE.strip() | ||
|
||
app = Flask(__name__) | ||
app.config.from_object(__name__) | ||
CORS(app, resources=r'/*', allow_headers="Content-Type") | ||
|
||
import todo.views |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,5 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
from flask import Flask, Response, jsonify, request | ||
from flask import json | ||
from flask.ext.cors import CORS | ||
|
||
DATABASE=os.getenv("DATABASE_URL", "sqlite://") | ||
DATABASE=DATABASE.strip() | ||
|
||
app = Flask(__name__) | ||
app.config.from_object(__name__) | ||
CORS(app, resources=r'/*', allow_headers="Content-Type") | ||
|
||
# placed down here to prevent circular imports | ||
# messing up things | ||
from todo.database import db_session | ||
from todo.models import Entry | ||
|
||
@app.route("/", methods=["GET", "POST", "DELETE"]) | ||
def index(): | ||
if request.method == "POST": | ||
request_json = request.get_json() | ||
entry = Entry(request_json["title"]) | ||
db_session.add(entry) | ||
db_session.commit() | ||
return jsonify(title=request_json["title"]) | ||
else: | ||
response = "[" | ||
for entry in Entry.query.all(): | ||
response += json.dumps(dict(title=entry.title)) | ||
response += "]" | ||
return response | ||
|
||
@app.teardown_appcontext | ||
def shutdown_session(exception=None): | ||
db_session.remove() | ||
|
||
def run(): | ||
app.run() | ||
from todo import app | ||
|
||
if __name__ == "__main__": | ||
run() | ||
|
||
app.run() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from todo import app | ||
|
||
from flask import jsonify, request | ||
from flask import json | ||
|
||
from todo.database import db_session | ||
from todo.models import Entry | ||
|
||
@app.route("/", methods=["GET", "POST", "DELETE"]) | ||
def index(): | ||
if request.method == "POST": | ||
request_json = request.get_json() | ||
entry = Entry(request_json["title"]) | ||
db_session.add(entry) | ||
db_session.commit() | ||
return jsonify(title=request_json["title"]) | ||
else: | ||
response = "[" | ||
for entry in Entry.query.all(): | ||
response += json.dumps(dict(title=entry.title)) | ||
response += "]" | ||
return response | ||
|
||
@app.teardown_appcontext | ||
def shutdown_session(exception=None): | ||
db_session.remove() |