Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Blueprint for public facing website; add Whitenoise (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
alysivji authored Apr 19, 2020
1 parent f5463b7 commit a99cc89
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 2 deletions.
17 changes: 15 additions & 2 deletions busy_beaver/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
from flask import Flask, request

from .blueprints import events_bp, github_bp, healthcheck_bp, slack_bp, twitter_bp
from whitenoise import WhiteNoise

from .blueprints import (
events_bp,
github_bp,
healthcheck_bp,
slack_bp,
twitter_bp,
web_bp,
)
from .common.oauth import OAuthError
from .config import DATABASE_URI, REDIS_URI, SECRET_KEY
from .exceptions import NotAuthorized, ValidationError
Expand Down Expand Up @@ -54,6 +62,11 @@ def create_app(*, testing=False):
app.register_blueprint(github_bp, url_prefix="/github", cli_group=None)
app.register_blueprint(slack_bp, url_prefix="/slack")
app.register_blueprint(twitter_bp, cli_group=None)
app.register_blueprint(web_bp)

app.wsgi_app = WhiteNoise(
app.wsgi_app, root="busy_beaver/static/", prefix="assets/"
)

@app.before_request
def add_internal_dictionary():
Expand Down
Empty file.
5 changes: 5 additions & 0 deletions busy_beaver/apps/web/blueprint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from flask import blueprints

web_bp = blueprints.Blueprint("web", __name__)

from . import views # noqa isort:skip
27 changes: 27 additions & 0 deletions busy_beaver/apps/web/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import logging

from flask import render_template
from flask.views import View

from .blueprint import web_bp

logger = logging.getLogger(__name__)


class RenderTemplateView(View):
"""Template View
Pulled straight from Flask docs:
- https://flask.palletsprojects.com/en/1.1.x/views/
"""

def __init__(self, template_name):
self.template_name = template_name

def dispatch_request(self):
return render_template(self.template_name)


web_bp.add_url_rule(
"/", view_func=RenderTemplateView.as_view("home", template_name="index.html")
)
1 change: 1 addition & 0 deletions busy_beaver/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from busy_beaver.apps.github_integration.blueprint import github_bp # noqa
from busy_beaver.apps.retweeter.blueprint import twitter_bp # noqa
from busy_beaver.apps.slack_integration.api import slack_bp # noqa
from busy_beaver.apps.web.blueprint import web_bp # noqa
3 changes: 3 additions & 0 deletions busy_beaver/static/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions busy_beaver/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<br><br><br>

<center>
<img src="{{ url_for('static', filename='images/logo.png') }}" width=300 />
</center>
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ SQLAlchemy==1.3.12
transitions==0.7.2
tweepy==3.8.0
werkzeug==0.16.0
whitenoise==5.0.1 # serving static files quickly; use until we need a CDN
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ transitions==0.7.2
tweepy==3.8.0
urllib3==1.24.3 # via requests, sentry-sdk
werkzeug==0.16.0
whitenoise==5.0.1
yarl==1.3.0 # via aiohttp

# The following packages are considered to be unsafe in a requirements file:
Expand Down
Empty file added tests/apps/web/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions tests/apps/web/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def test_index(client):
rv = client.get("/")
assert rv.status_code == 200

0 comments on commit a99cc89

Please sign in to comment.