Skip to content

Commit

Permalink
New hgapp init_for pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Sep 15, 2012
1 parent 1e80916 commit 2efbce3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
16 changes: 13 additions & 3 deletions hgtv/__init__.py
Expand Up @@ -2,15 +2,18 @@

# The imports in this file are order-sensitive

from pytz import timezone
from flask import Flask
from flask.ext.assets import Environment, Bundle
from flask.ext.lastuser import Lastuser
from flask.ext.lastuser.sqlalchemy import UserManager
from baseframe import baseframe, baseframe_js, baseframe_css, toastr_js, toastr_css
from coaster import configureapp
import coaster.app

# First, make an app and config it
# First, make an app

app = Flask(__name__, instance_relative_config=True)
configureapp(app, 'ENVIRONMENT')
lastuser = Lastuser()

# Second, setup baseframe and assets

Expand All @@ -28,3 +31,10 @@

import hgtv.models
import hgtv.views


def init_for(env):
coaster.app.init_app(app, env)
lastuser.init_app(app)
lastuser.init_usermanager(UserManager(hgtv.models.db, hgtv.models.User))
app.config['tz'] = timezone(app.config['TIMEZONE'])
2 changes: 1 addition & 1 deletion hgtv/models/__init__.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-

from flask.ext.sqlalchemy import SQLAlchemy
from hgtv import app
from coaster.sqlalchemy import TimestampMixin, BaseMixin, BaseNameMixin, BaseIdNameMixin
from hgtv import app

db = SQLAlchemy(app)

Expand Down
11 changes: 4 additions & 7 deletions hgtv/views/index.py
Expand Up @@ -3,22 +3,19 @@
import os
from flask import send_from_directory, render_template
from hgtv import app
from hgtv.models import Channel, Playlist, Video
from sqlalchemy import desc
from hgtv.models import Channel, Playlist

from pytz import utc, timezone

tz = timezone(app.config['TIMEZONE'])
from pytz import utc


@app.template_filter('shortdate')
def shortdate(date):
return utc.localize(date).astimezone(tz).strftime('%b %e')
return utc.localize(date).astimezone(app.config['tz']).strftime('%b %e')


@app.template_filter('longdate')
def longdate(date):
return utc.localize(date).astimezone(tz).strftime('%B %e, %Y')
return utc.localize(date).astimezone(app.config['tz']).strftime('%B %e, %Y')


@app.route('/')
Expand Down
9 changes: 2 additions & 7 deletions hgtv/views/login.py
@@ -1,15 +1,10 @@
# -*- coding: utf-8 -*-

from flask import Response, redirect, flash, g
from flask.ext.lastuser import LastUser
from flask.ext.lastuser.sqlalchemy import UserManager
from coaster.views import get_next_url

from hgtv import app
from hgtv.models import db, User, Channel, CHANNEL_TYPE

lastuser = LastUser(app)
lastuser.init_usermanager(UserManager(db, User))
from hgtv import app, lastuser
from hgtv.models import db, Channel, CHANNEL_TYPE


@app.route('/login')
Expand Down
3 changes: 2 additions & 1 deletion runserver.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
from hgtv import app
from hgtv import app, init_for
from hgtv.models import db
init_for('development')
db.create_all()
app.run('0.0.0.0', debug=True, port=8000)
3 changes: 2 additions & 1 deletion website.wsgi
@@ -1,4 +1,5 @@
import sys
import os.path
sys.path.insert(0, os.path.dirname(__file__))
from hgtv import app as application
from hgtv import app as application, init_for
init_for('production')

0 comments on commit 2efbce3

Please sign in to comment.