On 04 Jun 12:35, Raimon Esteve wrote: > 2014-06-04 10:11 GMT+02:00 Cédric Krier <cedric.kr...@b2ck.com>: > > > On 04 Jun 09:51, Raimon Esteve wrote: > > > Hello, > > > > > > I'm working a Flask APP and use Flask Tryton to connect to Tryton (1) > > > > > > I have blueprints and context processor to connect to Tryton > > > > > > * Blueprint (2). Modular Application > > > * Context Processor: Functions in templates > > > > > > I have some routes or views call Tryton with @tryton.transaction > > > Also I have in some context processor call Trytn with > > @tryton.transaction. > > > > > > My problem is about I can't start two or more transaction. Second > > > transaction, self.user is not None and get assert error (4) > > > > Why would you want to start more than 1 transaction? > > > > First time I understand each decorator call a "independent" transaction > (new transaction each method) > > I continue working about context processor and blueprints.... > > *tryton.py* > > from flask import current_app > from flask_tryton import Tryton > > tryton = Tryton(current_app) > > Now I get message "RuntimeError: working outside of application context" > because I init tryton outsite app. I try "with current_app.app_context()" > and not expect good results.. If I change some parts "Flask tryton" to init > without app, I get successfull result. > > Any ideas? I continue investigating....
There was a little mistake in the initial design of flask-tryton. It should be fixed with https://code.google.com/p/flask-tryton/source/detail?r=34c8b01ac62f6ad2431c90088f32a87f8e6df7af Otherwise, you should not use current_app but import the instance of Flask from the right module. > *app.py* > > from tryton import tryton > > @app.context_processor > def cms_processor(): > > def menu(code=None): > Menu = tryton.pool.get('cms.menu') Should be (with latest code): tryton = current_app.extensions['Tryton'] Menu = tryton.pool.get('cms.menu') > print "call search tryton > > return dict(cms_menu=menu) > > *tryton.py* > > from flask import current_app > from flask_tryton import Tryton > > tryton = Tryton() > > *blueprint.py* > > from flask import Blueprint, current_app > from galatea.tryton import tryton > > cms = Blueprint('cms', __name__, template_folder='templates') > > @cms.route("/<slug>", endpoint="article") > @tryton.transaction() > def article(lang, slug): > Article = tryton.pool.get('cms.article') init_app should be called to use the pool. > print "call search tryton model" -- Cédric Krier - B2CK SPRL Email/Jabber: cedric.kr...@b2ck.com Tel: +32 472 54 46 59 Website: http://www.b2ck.com/
pgpmAJT9prvXI.pgp
Description: PGP signature