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