This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from datetime import datetime | |
from werkzeug.contrib.atom import AtomFeed | |
from flask import Flask, request, render_template, flash, url_for | |
www = Flask(__name__) | |
www.config['SECRET_KEY'] = 'kjsas fo98qw 83' | |
www.debug = True | |
from flaskext.uploads import UploadSet, IMAGES, configure_uploads |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127.0.0.1 - - [20/May/2012 13:11:36] "GET /blog/ HTTP/1.1" 500 - | |
Traceback (most recent call last): | |
File "/Library/Python/2.7/site-packages/flask/app.py", line 1518, in __call__ | |
return self.wsgi_app(environ, start_response) | |
File "/Library/Python/2.7/site-packages/flask/app.py", line 1506, in wsgi_app | |
response = self.make_response(self.handle_exception(e)) | |
File "/Library/Python/2.7/site-packages/flask/app.py", line 1504, in wsgi_app | |
response = self.full_dispatch_request() | |
File "/Library/Python/2.7/site-packages/flask/app.py", line 1264, in full_dispatch_request | |
rv = self.handle_user_exception(e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from celery.schedules import crontab | |
from flask.ext.celery import Celery | |
CELERYBEAT_SCHEDULE = { | |
# executes every night at 4:15 | |
'every-night': { | |
'task': 'user.checkaccounts', | |
'schedule': crontab(hour=4, minute=20) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
class ExampleTestCase(unittest.TestCase): | |
def setUp(self): | |
# open files, set up database and stuff | |
pass | |
def test_1(self): | |
# start all tests with test, so unittest finds it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# enable virtual environment for python | |
source venv/bin/activate | |
# hide changes that are not in this commit | |
git stash -q --keep-index | |
./manage.py test | |
RESULT=$? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="control-group {% if input.errors %}error{% endif %}"> | |
{% if input.type == 'BooleanField' %} | |
<div class="controls"> | |
<label for="{{ input.name }}" class="checkbox"> | |
{{ input }} | |
{{ input.label.text }} | |
</label> | |
</div> | |
{% else %} | |
<label for="{{ input.name }}" class="control-label">{{ input.label.text }}</label> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from babel import support | |
def man_gettext(string, domain, **variables): | |
translations = support.Translations.load(os.path.join(www.root_path, 'translations')) | |
return translations.dgettext(domain, string) % variables | |
def man_lazy_gettext(string, domain, **variables): | |
from speaklater import make_lazy_string | |
return make_lazy_string(man_gettext, string, domain, **variables) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hosturl(url): | |
host = www.config['HOST'] | |
if host.endswith('/'): | |
host = host[0:-1] | |
if url.startswith('/'): | |
url = url[1:] | |
return '/'.join([host, url]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User(object): | |
def permission_list(self): | |
permissions = Permission.query.filter_by(user_id=self).all() | |
l = [] | |
for permission in permissions: | |
l.append((permission.to, permission.value)) | |
return l | |
def permission_has(self, to): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import exc | |
from sqlalchemy import event | |
from sqlalchemy.pool import Pool | |
@event.listens_for(Pool, "checkout") | |
def ping_connection(dbapi_connection, connection_record, connection_proxy): | |
cursor = dbapi_connection.cursor() | |
try: | |
cursor.execute("SELECT 1") | |
except: |
OlderNewer