diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b9c4b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*.pyc +.Python + +lib/ +bin/ +include/ + +pip-selfcheck.json + + diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/teams.py b/api/teams.py new file mode 100644 index 0000000..14396c7 --- /dev/null +++ b/api/teams.py @@ -0,0 +1,15 @@ +# +# If things get really nasty, this teams module +# could become package. +# +from flask import Blueprint, jsonify + +from models.team import Team + +teams_api = Blueprint('teams_api', __name__) + +@teams_api.route('/teams', methods=['GET']) +def index(): + cbj = Team('Columbus Blue Jackets', 'CBJ', 'blue-jackets') + flp = Team('Florida Panthers', 'FLP', 'florida-panthers') + return jsonify({ 'teams': [ cbj.__dict__, flp.__dict__ ] }) diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/models/team.py b/models/team.py new file mode 100644 index 0000000..f690a11 --- /dev/null +++ b/models/team.py @@ -0,0 +1,11 @@ + +class Team: + + def __init__(self, name, abbr, slug): + self.name = name + self.abbr = abbr + self.slug = slug + + def __repr__(self): + return 'Team({0})'.format(self.name) + diff --git a/run.py b/run.py new file mode 100644 index 0000000..2959d47 --- /dev/null +++ b/run.py @@ -0,0 +1,28 @@ +from flask import Flask, render_template + +from api.teams import teams_api +from models.team import Team + +# +# This would also allow db models to be shared between +# the web app and the api. The app would feed 'em to +# the template and the api would jsonize what it needed. +# + +app = Flask(__name__) +app.register_blueprint(teams_api, url_prefix='/api/v1') +# +# Moving to v2 would be fairly easy +# +# Or specify a header for version desired. A little more +# hairy as you look at each request instead of using +# routing +# + +@app.route("/") +def homepage(): + avs = Team('Colorado Avalanche', 'CAV', 'colorado-avalanche') + return render_template('homepage.html', team=avs) + +if __name__ == '__main__': + app.run() diff --git a/templates/homepage.html b/templates/homepage.html new file mode 100644 index 0000000..9100047 --- /dev/null +++ b/templates/homepage.html @@ -0,0 +1,7 @@ +{% extends 'layout.html' %} +{% block body %} +

War on Ice

+
+ Much Hockey Data about the {{ team.name }} +
+{% endblock %} diff --git a/templates/layout.html b/templates/layout.html new file mode 100644 index 0000000..d68cc91 --- /dev/null +++ b/templates/layout.html @@ -0,0 +1,16 @@ + + + + + WOI : Skeleton + + +
+
+
+ {% block body %}{% endblock %} +
+ + +