Skip to content

Commit e7e6bc1

Browse files
committed
change name of app folder and clean up a few files
1 parent 5d728e5 commit e7e6bc1

32 files changed

+70
-81
lines changed

AngularFlask/controllers.py

Lines changed: 0 additions & 64 deletions
This file was deleted.

AngularFlask/settings.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

AngularFlask/__init__.py renamed to angular_flask/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
app = Flask(__name__)
77

8-
app.config.from_object('AngularFlask.settings')
8+
app.config.from_object('angular_flask.settings')
99

1010
app.url_map.strict_slashes = False
1111

12-
import AngularFlask.core
13-
import AngularFlask.models
14-
import AngularFlask.controllers
12+
import angular_flask.core
13+
import angular_flask.models
14+
import angular_flask.controllers
1515

angular_flask/controllers.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import os
2+
3+
from flask import Flask, request, Response
4+
from flask import render_template, url_for, redirect, send_from_directory
5+
from flask import send_file, make_response, abort
6+
7+
from angular_flask import app
8+
9+
# routing for API endpoints (generated from the models designated as API_MODELS)
10+
from angular_flask.core import api_manager
11+
from angular_flask.models import *
12+
13+
for model_name in app.config['API_MODELS']:
14+
model_class = app.config['API_MODELS'][model_name]
15+
api_manager.create_api(model_class, methods=['GET', 'POST'])
16+
17+
session = api_manager.session
18+
19+
# routing for basic pages (pass routing onto the Angular app)
20+
@app.route('/')
21+
@app.route('/about')
22+
@app.route('/blog')
23+
def basic_pages(**kwargs):
24+
return make_response(open('angular_flask/templates/index.html').read())
25+
26+
# routing for CRUD-style endpoints
27+
# passes routing onto the angular frontend if the requested resource exists
28+
from sqlalchemy.sql import exists
29+
30+
crud_url_models = app.config['CRUD_URL_MODELS']
31+
32+
@app.route('/<model_name>/')
33+
@app.route('/<model_name>/<item_id>')
34+
def rest_pages(model_name, item_id=None):
35+
if model_name in crud_url_models:
36+
model_class = crud_url_models[model_name]
37+
if item_id is None or session.query(exists().where(
38+
model_class.id == item_id)).scalar():
39+
return make_response(open(
40+
'angular_flask/templates/index.html').read())
41+
abort(404)
42+
43+
# special file handlers and error handlers
44+
@app.route('/favicon.ico')
45+
def favicon():
46+
return send_from_directory(os.path.join(app.root_path, 'static'),
47+
'img/favicon.ico')
48+
49+
@app.errorhandler(404)
50+
def page_not_found(e):
51+
return render_template('404.html'), 404
52+
53+
54+

AngularFlask/core.py renamed to angular_flask/core.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from AngularFlask import app
1+
from angular_flask import app
22

3-
# SQLAlchemy
43
from flask.ext.sqlalchemy import SQLAlchemy
54
from flask.ext.restless import APIManager
65

AngularFlask/models.py renamed to angular_flask/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime
22

3-
from AngularFlask.core import db
4-
from AngularFlask import app
3+
from angular_flask.core import db
4+
from angular_flask import app
55

66
class Post(db.Model):
77
id = db.Column(db.Integer, primary_key=True)

angular_flask/settings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
DEBUG = True
3+
SECRET_KEY = 'temporary_secret_key' # make sure to change this
4+
5+
SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/angular_flask.db'
6+
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)