Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The skeleton but committed to the correct project. #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.pyc
.Python

lib/
bin/
include/

pip-selfcheck.json


Empty file added api/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions api/teams.py
Original file line number Diff line number Diff line change
@@ -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__ ] })
Empty file added models/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions models/team.py
Original file line number Diff line number Diff line change
@@ -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)

28 changes: 28 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -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()
7 changes: 7 additions & 0 deletions templates/homepage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends 'layout.html' %}
{% block body %}
<h1>War on Ice</h1>
<div class="row">
Much Hockey Data about the {{ team.name }}
</div>
{% endblock %}
16 changes: 16 additions & 0 deletions templates/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>WOI : Skeleton</title>
</head>
<body>
<div class="header">
</div>
<div class="content">
{% block body %}{% endblock %}
</div>
<div class="footer">
</div>
</body>
</html>