Skip to content

Commit

Permalink
heroku hosting
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Apr 24, 2013
1 parent efaa517 commit abdd43c
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
web: gunicorn runp-heroku:app
init: python db_create.py && pybabel compile -d app/translations
upgrade: python db_upgrade.py && pybabel compile -d app/translations

9 changes: 8 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
mail_handler.setLevel(logging.ERROR)
app.logger.addHandler(mail_handler)

if not app.debug:
if not app.debug and os.environ.get('HEROKU') is None:
import logging
from logging.handlers import RotatingFileHandler
file_handler = RotatingFileHandler('tmp/microblog.log', 'a', 1 * 1024 * 1024, 10)
Expand All @@ -39,6 +39,13 @@
app.logger.setLevel(logging.INFO)
app.logger.info('microblog startup')

if os.environ.get('HEROKU') is not None:
import logging
stream_handler = logging.StreamHandler()
app.logger.addHandler(stream_handler)
app.logger.setLevel(logging.INFO)
app.logger.info('microblog startup')

app.jinja_env.globals['momentjs'] = momentjs

from app import views, models
Expand Down
6 changes: 4 additions & 2 deletions app/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from hashlib import md5
from app import db
from app import app
import flask.ext.whooshalchemy as whooshalchemy
from config import WHOOSH_ENABLED
import re

ROLE_USER = 0
Expand Down Expand Up @@ -89,4 +89,6 @@ class Post(db.Model):
def __repr__(self): # pragma: no cover
return '<Post %r>' % (self.body)

whooshalchemy.whoosh_index(app, Post)
if WHOOSH_ENABLED:
import flask.ext.whooshalchemy as whooshalchemy
whooshalchemy.whoosh_index(app, Post)
2 changes: 1 addition & 1 deletion app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
{% endif %}
</ul>
<div class="nav-collapse collapse">
{% if g.user.is_authenticated() %}
{% if g.user.is_authenticated() and g.search_enabled %}
<form class="navbar-search pull-right" action="{{url_for('search')}}" method="post" name="search">{{g.search_form.hidden_tag()}}{{g.search_form.search(size=20,placeholder=_('Search'),class="search-query")}}</form>
{% endif %}
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from emails import follower_notification
from guess_language import guessLanguage
from translate import microsoft_translate
from config import POSTS_PER_PAGE, MAX_SEARCH_RESULTS, LANGUAGES, DATABASE_QUERY_TIMEOUT
from config import POSTS_PER_PAGE, MAX_SEARCH_RESULTS, LANGUAGES, DATABASE_QUERY_TIMEOUT, WHOOSH_ENABLED

@lm.user_loader
def load_user(id):
Expand All @@ -28,6 +28,7 @@ def before_request():
db.session.commit()
g.search_form = SearchForm()
g.locale = get_locale()
g.search_enabled = WHOOSH_ENABLED

@app.after_request
def after_request(response):
Expand Down
3 changes: 3 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
SQLALCHEMY_RECORD_QUERIES = True
WHOOSH_BASE = os.path.join(basedir, 'search.db')

# Whoosh does not work on Heroku
WHOOSH_ENABLED = os.environ.get('HEROKU') is None

# slow database query threshold (in seconds)
DATABASE_QUERY_TIMEOUT = 0.5

Expand Down
28 changes: 28 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Babel==0.9.6
Flask==0.9
Flask-Babel==0.8
Flask-Login==0.1.3
Flask-Mail==0.8.2
Flask-OpenID==1.1.1
Flask-SQLAlchemy==0.16
Flask-WTF==0.8.3
git+git://github.com/miguelgrinberg/Flask-WhooshAlchemy
Jinja2==2.6
MySQL-python==1.2.4
SQLAlchemy==0.7.9
Tempita==0.5.1
WTForms==1.0.3
Werkzeug==0.8.3
Whoosh==2.4.1
blinker==1.2
coverage==3.6
decorator==3.4.0
flup==1.0.3.dev-20110405
guess-language==0.2
gunicorn==0.17.2
psycopg2==2.5
python-openid==2.2.5
pytz==2013b
speaklater==1.3
sqlalchemy-migrate==0.7.2

2 changes: 2 additions & 0 deletions runp-heroku.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!flask/bin/python
from app import app

0 comments on commit abdd43c

Please sign in to comment.