def think(subject): tracer.current_span().set_tag('subject', subject) sleep(0.5) quote = Thought.query.filter_by(subject=subject).first() if quote is None: return Thought( quote='Hmmm, that\'s something I\'ll need to think about.', author='The Machine', subject=subject) return quote
def initialize_database(app, db): """Drop and restore database in a consistent state""" with app.app_context(): db.drop_all() db.create_all() db.session.add( Thought( quote= 'My religion consists of a humble admiration of the illimitable superior spirit who reveals himself in the slight details we are able to perceive with our frail and feeble mind.', author='Albert Einstein', subject='religion')) db.session.add( Thought( quote= 'For a successful technology, reality must take precedence over public relations, for Nature cannot be fooled.', author='Richard Feynman', subject='technology')) db.session.add( Thought( quote= 'One is left with the horrible feeling now that war settles nothing; that to win a war is as disastrous as to lose one.', author='Agatha Christie', subject='war')) db.session.add( Thought( quote='Life grants nothing to us mortals without hard work.', author='Horace', subject='work')) db.session.add( Thought(quote='Ah, music. A magic beyond all we do here!', author='J. K. Rowling', subject='music')) db.session.add( Thought( quote= 'I think that God in creating Man somewhat overestimated his ability.', author='Oscar Wilde', subject='mankind')) db.session.commit()
def lazy_signup(sender, **kwargs): request=kwargs['request'] user=kwargs['user'] Thought.reparent_all_my_session_objects(request.session, user)
def lazy_login(sender, **kwargs): request=kwargs['request'] user=kwargs['user'] print request if request.user.is_active: Thought.reparent_all_my_session_objects(request.session, user)