Ejemplo n.º 1
0
    def test_flask_fail(self):
        # XXX This fails due to a bug in Flask-SQLAlchemy that affects
        # Flask-WhooshAlchemy. I submitted a pull request with a fix that is
        # pending.

        from flask.ext.sqlalchemy import before_models_committed, models_committed

        before_models_committed.connect(_after_flush)
        models_committed.connect(_after_flush)
        db.session.add(ObjectB(title=u'my title', content=u'hello world'))
        db.session.add(ObjectA(title=u'a title', content=u'hello world'))
        db.session.flush()
        db.session.commit()
Ejemplo n.º 2
0
    def test_flask_fail(self):
        # XXX This fails due to a bug in Flask-SQLAlchemy that affects
        # Flask-WhooshAlchemy. I submitted a pull request with a fix that is
        # pending.

        from flask.ext.sqlalchemy import before_models_committed, models_committed
        
        before_models_committed.connect(_after_flush)
        models_committed.connect(_after_flush)
        db.session.add(ObjectB(title=u'my title', content=u'hello world'))
        db.session.add(ObjectA(title=u'a title', content=u'hello world'))
        db.session.flush()
        db.session.commit()
Ejemplo n.º 3
0
from flask.ext.assets import Environment, Bundle
from flask.ext.sqlalchemy import before_models_committed, event

from sqlalchemy.dialects.postgres import JSONB
from sqlalchemy.sql.expression import cast

app = Flask(__name__)
app.config.from_object('config')

from cms.models import db, Document, on_before_models_committed, on_before_insert
db.init_app(app)

with app.app_context():
    db.create_all()

event.listen(Document, 'before_insert', on_before_insert)
before_models_committed.connect(on_before_models_committed, app)

assets = Environment(app)

style = Bundle('../styles/site.scss', filters='scss,cssmin', output='styles/site.css')
assets.register('style', style)

@app.route('/')
def home():
    things = Document.query.filter(Document.data['type'].astext == 'thing')
    return render_template('home.html', things=things)

if __name__ == '__main__':
    app.run('127.0.0.1', 3030)
Ejemplo n.º 4
0
from flask.ext.sqlalchemy import before_models_committed, event

from sqlalchemy.dialects.postgres import JSONB
from sqlalchemy.sql.expression import cast

app = Flask(__name__)
app.config.from_object('config')

from cms.models import db, Document, on_before_models_committed, on_before_insert
db.init_app(app)

with app.app_context():
    db.create_all()

event.listen(Document, 'before_insert', on_before_insert)
before_models_committed.connect(on_before_models_committed, app)

assets = Environment(app)

style = Bundle('../styles/site.scss',
               filters='scss,cssmin',
               output='styles/site.css')
assets.register('style', style)


@app.route('/')
def home():
    things = Document.query.filter(Document.data['type'].astext == 'thing')
    return render_template('home.html', things=things)

Ejemplo n.º 5
0
			done=0
			while(done==0):
				trolley_id=randint(100000, 999999)
				existing_trolley=TrolleyLink.query.get(trolley_id)
				print existing_trolley
				if existing_trolley is None:
					self.trolley_id=trolley_id
					done=1
				else:
					done=0


def outlet_db_sync(sender, changes):
	for model, change in changes:
		if isinstance(model, RetailLink):
			if model.product is not None and model.outlet is not None:
				views.outlet_sync(model.product.barcode, change, model.outlet.outlet_id)
			elif model.barcode is not None and model.outlet_id is not None:
				views.outlet_sync(model.barcode, change, model.outlet_id)
		elif isinstance(model, Product):
			outlets_with_product=RetailLink.query.filter_by(barcode=model.barcode).all()
			for outlet in outlets_with_product:
				if change != "delete":
					views.outlet_sync(model.barcode, change, outlet.outlet_id)
				else:
					db.session.delete(outlet)

before_models_committed.connect(outlet_db_sync, sender=app)