heroku hosting

This commit is contained in:
Miguel Grinberg 2013-04-22 22:19:12 -07:00
parent efaa51743e
commit abdd43cd9b
8 changed files with 52 additions and 5 deletions

4
Procfile Normal file
View File

@ -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

View File

@ -29,7 +29,7 @@ if not app.debug and MAIL_SERVER != '':
mail_handler.setLevel(logging.ERROR) mail_handler.setLevel(logging.ERROR)
app.logger.addHandler(mail_handler) app.logger.addHandler(mail_handler)
if not app.debug: if not app.debug and os.environ.get('HEROKU') is None:
import logging import logging
from logging.handlers import RotatingFileHandler from logging.handlers import RotatingFileHandler
file_handler = RotatingFileHandler('tmp/microblog.log', 'a', 1 * 1024 * 1024, 10) file_handler = RotatingFileHandler('tmp/microblog.log', 'a', 1 * 1024 * 1024, 10)
@ -39,6 +39,13 @@ if not app.debug:
app.logger.setLevel(logging.INFO) app.logger.setLevel(logging.INFO)
app.logger.info('microblog startup') 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 app.jinja_env.globals['momentjs'] = momentjs
from app import views, models from app import views, models

View File

@ -1,7 +1,7 @@
from hashlib import md5 from hashlib import md5
from app import db from app import db
from app import app from app import app
import flask.ext.whooshalchemy as whooshalchemy from config import WHOOSH_ENABLED
import re import re
ROLE_USER = 0 ROLE_USER = 0
@ -89,4 +89,6 @@ class Post(db.Model):
def __repr__(self): # pragma: no cover def __repr__(self): # pragma: no cover
return '<Post %r>' % (self.body) return '<Post %r>' % (self.body)
if WHOOSH_ENABLED:
import flask.ext.whooshalchemy as whooshalchemy
whooshalchemy.whoosh_index(app, Post) whooshalchemy.whoosh_index(app, Post)

View File

@ -53,7 +53,7 @@
{% endif %} {% endif %}
</ul> </ul>
<div class="nav-collapse collapse"> <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> <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 %} {% endif %}
</div> </div>

View File

@ -9,7 +9,7 @@ from datetime import datetime
from emails import follower_notification from emails import follower_notification
from guess_language import guessLanguage from guess_language import guessLanguage
from translate import microsoft_translate 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 @lm.user_loader
def load_user(id): def load_user(id):
@ -28,6 +28,7 @@ def before_request():
db.session.commit() db.session.commit()
g.search_form = SearchForm() g.search_form = SearchForm()
g.locale = get_locale() g.locale = get_locale()
g.search_enabled = WHOOSH_ENABLED
@app.after_request @app.after_request
def after_request(response): def after_request(response):

View File

@ -20,6 +20,9 @@ SQLALCHEMY_MIGRATE_REPO = os.path.join(basedir, 'db_repository')
SQLALCHEMY_RECORD_QUERIES = True SQLALCHEMY_RECORD_QUERIES = True
WHOOSH_BASE = os.path.join(basedir, 'search.db') 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) # slow database query threshold (in seconds)
DATABASE_QUERY_TIMEOUT = 0.5 DATABASE_QUERY_TIMEOUT = 0.5

28
requirements.txt Normal file
View File

@ -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
runp-heroku.py Executable file
View File

@ -0,0 +1,2 @@
#!flask/bin/python
from app import app