示例#1
0
def init_db():
    if pyphilo.init_db():
        @transactionnal
        def create_data():
            for i in range(17):
                article = Article(name="Something %d" % i, content="Hello world %d!" % i, published=True)
                session.add(article)

        create_data()
示例#2
0
        try:
            import psycopg2.extensions
            c = conn.cursor()
            c.execute("listen received_message;")
            conn.commit();
            print "waiting"
            if select.select([conn], [], [], 10) == ([],[],[]):
                print "Timeout"
                c.execute("unlisten received_message;")
                conn.commit()
            else:
                conn.poll()
                while conn.notifies:
                    notify = conn.notifies.pop()
                    print "Got NOTIFY:", notify.pid, notify.channel, notify.payload
                    c.execute("unlisten received_message;")
                    conn.commit()
                    posted.set()
                    posted.clear()
        finally:
            conn1.close()

class Message(pyphilo.Base):
    message = sa.Column(sa.String(200))

if __name__ == "__main__":
    pyphilo.engine.init_global_engine("postgresql+psycopg2://niv@/messages")
    pyphilo.init_db()
    gevent.spawn(listener)
    httpd = WSGIServer(('', 5000), app).serve_forever()
示例#3
0
    if flask.request.method == "GET":
        page = db.session.query(Page).filter(Page.name == page_name).all()
        if page:
            content = page[0].content
        else:
            content = flask.render_template("page.html")
        return content
    else: # POST
        content = flask.request.form["content"]
        page = db.session.query(Page).filter(Page.name == page_name).all()
        if page:
            page = page[0]
            page.content = content
        else:
            page = Page(name=page_name, content=content)
            db.session.add(page)
        return ""


if __name__ == "__main__":
    db.engine.init_sqlite("test.db")

    created = db.init_db()
    if created:
        default_data()

    app.debug = True
    app.run()