Skip to content

Commit 021f13f

Browse files
committed
Adding working pages to the example 8 server
1 parent e842911 commit 021f13f

62 files changed

Lines changed: 289 additions & 4116 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

python-sqlite-sqlalchemy/project/examples/example_8/app/__init__.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,30 @@
55
from flask_sqlalchemy import SQLAlchemy
66
from config import Config
77

8-
# define the application
9-
app = Flask(__name__)
8+
# Define the application
9+
app = Flask(__name__, instance_relative_config=False)
1010

11-
# configure the application
11+
# Configure the application
1212
app.config.from_object(Config)
1313

14-
# Configurations
15-
app.config.from_object('config')
16-
17-
# Initialize Bootstrap connection
18-
Bootstrap(app)
14+
# # Configurations
15+
# app.config.from_object('config')
1916

2017
# Define the database object which is imported
2118
# by modules and controllers
2219
db = SQLAlchemy(app)
2320

21+
# Initialize Bootstrap connection
22+
Bootstrap(app)
23+
24+
# Register Blueprings
25+
from .artists import routes as artist_routes
26+
from .albums import routes as album_routes
27+
from .tracks import routes as track_routes
28+
app.register_blueprint(artist_routes.artists_bp)
29+
app.register_blueprint(album_routes.albums_bp)
30+
app.register_blueprint(track_routes.tracks_bp)
31+
2432
# Sample HTTP error handling
2533
@app.errorhandler(404)
2634
def not_found(error):
@@ -35,10 +43,10 @@ def not_found(error):
3543
# ..
3644

3745

38-
from app import routes
46+
#from app import routes
3947
from app import models
4048

4149
# Build the database:
4250
# This will create the database file using SQLAlchemy
43-
db.create_all()
51+
# db.create_all()
4452

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from flask import Blueprint
2+
from flask import render_template
3+
from app import db
4+
from app.models import Album
5+
6+
7+
# Setup the Blueprint
8+
albums_bp = Blueprint(
9+
"albums_bp",
10+
__name__,
11+
template_folder="templates",
12+
static_folder="static"
13+
)
14+
15+
16+
@albums_bp.route("/albums", methods=["GET"])
17+
@albums_bp.route("/albums/<int:artist_id>", methods=["GET"])
18+
def albums(artist_id=None):
19+
# Start the query for albums
20+
query = db.session.query(Album)
21+
22+
# Display the albums for the artist passed?
23+
if artist_id is not None:
24+
query = query.filter(Album.artist_id == artist_id)
25+
26+
albums = query.all()
27+
28+
return render_template(
29+
"albums.html",
30+
artist_id=artist_id,
31+
albums=albums
32+
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{% extends "base.html" %}
2+
3+
4+
{% block content %}
5+
<div class="container">
6+
<div class="m-4">
7+
{% if artist_id is not none %}
8+
<div class="card" style="width: 18rem;">
9+
<div class="card-body">
10+
<h5 class="card-title">Artist Name</h5>
11+
<p class="card-text">{{ albums[0].artist.name }}</p>
12+
</div>
13+
</div>
14+
{% endif %}
15+
<table class="table table-striped table-bordered table-hover table-sm">
16+
<caption>List of Albums</caption>
17+
<thead>
18+
<tr>
19+
<th>Album Name</th>
20+
</tr>
21+
</thead>
22+
<tbody>
23+
{% for album in albums %}
24+
<tr>
25+
<td>
26+
<a href="{{url_for('tracks_bp.tracks', album_id=album.album_id)}}">
27+
{{ album.title }}
28+
</a>
29+
</td>
30+
</tr>
31+
{% endfor %}
32+
</tbody>
33+
</table>
34+
</div>
35+
</div>
36+
{% endblock %}
37+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from flask import Blueprint
2+
from flask import render_template
3+
from app import db
4+
from app.models import Artist
5+
6+
7+
# Setup the Blueprint
8+
artists_bp = Blueprint(
9+
"artists_bp",
10+
__name__,
11+
template_folder="templates",
12+
static_folder="static"
13+
)
14+
15+
16+
@artists_bp.route("/artists", methods=["GET"])
17+
def artists():
18+
artists = db.session.query(Artist).all()
19+
return render_template("artists.html", artists=artists)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{% extends "base.html" %}
2+
3+
4+
{% block content %}
5+
<div class="container">
6+
<div class="m-4">
7+
<table class="table table-striped table-bordered table-hover table-sm">
8+
<caption>List of Artists</caption>
9+
<thead>
10+
<tr>
11+
<th>Artist Name</th>
12+
</tr>
13+
</thead>
14+
<tbody>
15+
{% for artist in artists %}
16+
<tr>
17+
<td>
18+
<a href="{{url_for('albums_bp.albums', artist_id=artist.artist_id)}}">
19+
{{ artist.name }}
20+
</a>
21+
</td>
22+
</tr>
23+
{% endfor %}
24+
</tbody>
25+
</table>
26+
</div>
27+
</div>
28+
{% endblock %}
29+

python-sqlite-sqlalchemy/project/examples/example_8/app/controller.py

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

python-sqlite-sqlalchemy/project/examples/example_8/app/templates/html5-boilerplate_v7.3.0/img/.gitignore renamed to python-sqlite-sqlalchemy/project/examples/example_8/app/customers/__init__.py

File renamed without changes.

python-sqlite-sqlalchemy/project/examples/example_8/app/templates/html5-boilerplate_v7.3.0/js/main.js renamed to python-sqlite-sqlalchemy/project/examples/example_8/app/customers/routes.py

File renamed without changes.
Binary file not shown.

python-sqlite-sqlalchemy/project/examples/example_8/app/employees/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)