Example #1
0
from datetime import datetime
from flask import Flask, request, flash, url_for, redirect, \
     render_template, abort
from flaskext.sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config.from_pyfile('hello.cfg')
db = SQLAlchemy(app)


class Todo(db.Model):
    __tablename__ = 'todos'
    id = db.Column('todo_id', db.Integer, primary_key=True)
    title = db.Column(db.String(60))
    text = db.Column(db.String)
    done = db.Column(db.Boolean)
    pub_date = db.Column(db.DateTime)

    def __init__(self, title, text):
        self.title = title
        self.text = text
        self.done = False
        self.pub_date = datetime.utcnow()


@app.route('/')
def show_all():
    return render_template('show_all.html',
                           todos=Todo.query.order_by(
                               Todo.pub_date.desc()).all())
Example #2
0
from logging import Formatter, FileHandler

from flask import Flask, render_template, flash, g, session, current_app

from flaskext.cache import Cache
from flaskext.markdown import Markdown
from flaskext.uploads import configure_uploads, UploadSet, IMAGES
from flaskext.sqlalchemy import SQLAlchemy
from flaskext.mail import Mail

from btnfemcol.settings import *

uploaded_avatars = UploadSet('avatars', IMAGES)
uploaded_images = UploadSet('images', IMAGES)

db = SQLAlchemy()
cache = Cache()
mail = Mail()


def create_app(debug=False):
    # Change static path based on whether we're debugging.
    if debug:
        print "Debug mode."
        app = Flask('btnfemcol', static_path='/static')

    else:
        app = Flask('btnfemcol', static_path='')

    # Handle configuration
    app.config.from_object('btnfemcol.settings')