The web framework that scales with you. TurboGears 2.4.3 released https://github.com/TurboGears/tg2/releases/tag/tg2.4.3
amol- on development
Remove deprecated DecoratedCont… (compare)
amol- on development
Mandate context argument in Dec… (compare)
amol- on development
Remove deprecated tmpl_context … (compare)
amol- on development
Remove deprecated beaker.sessio… (compare)
amol- on development
Remove more deprecations (compare)
amol- on development
Remove more deprecations (compare)
amol- on development
Remove deprecated request.contr… (compare)
amol- on development
Removing deprecated caching and… (compare)
amol- on development
Do not rely on deprecated getar… (compare)
amol- on development
Do not rely on deprecated getar… (compare)
amol- on development
Remove coverage as a mandatory … (compare)
amol- on development
Update run-tests.yml (compare)
amol- on development
simplify test dependencies inst… (compare)
amol- on development
Avoid installing unstable relea… (compare)
amol- on development
Update run-tests.yml (compare)
amol- on master
Switch to https transport (compare)
amol- on master
Remove 3.6 (compare)
TG has always supported many different libraries and backends, and it's hard to deprecate them because there are people using them out there, but without third parties help it's hard to maintain them all because it's hard to notice breakages (I never used CherryPy for TG for example, always Waitress).
So any help on that is greatly appreciated!
Hey Alessandro, I'm trying to do a thing that I'm not sure how to do. I am processing form results in (say) MyController.form_handler(). If the form doesn't validate, I want to pass the form object back to the original exposed MyController.form_start(self,form=None) method. That method uses @expose('form_template_name') to return a page that renders the form.
So I try doing
return self.form_start(form=erroneous_form)
but this does not work because the form_handler() method lacks the @expose('form_template_name') annotation -- since form_handler() is merely a POST handler it normally ends with a redirect rather than returning a result, and therefore uses the @expose() annotation.
Obviously I could add @expose('form_template_name') to the form_handler() method, but that seems wrong/inelegant. Is there a way to return the result of an exposed method and tell that method what template to use to render its results? Eg something like:
return self.form_start(form=erroneous_form,template_name='form_template_name')
?
@validate(YouForm, error_handler=form_start)
as a decorator for form_handler
? That's how validation for forms is expected to work: https://turbogears.readthedocs.io/en/latest/turbogears/widgets_forms.html#validating-fields
TW2 had nearly zero documentation. But I started rewriting it a few weeks ago. So there is now a newdoc branch ( https://github.com/toscawidgets/tw2.core/tree/newdoc/docs/source ) where I'm doing all the work of rewriting it.
But if you are using WTForms I guess you have to adhere to WTForms way of doing things. You should still be able to use the error_handler
to switch action of the controller in case of errors, but you will have to roll your own validator as WTForms forms aren't supported as validators by tg out of the box.
dynforms
import testapp.model as model
from testapp.tests import TestController
from nose.tools import eq_, ok_
class TestBreakage(TestController):
''' What the actual... '''
def setUp(self):
super().setUp()
u = model.User(user_name="what",email_address="what@where.whatever")
model.DBSession.add(u)
u = model.DBSession.query(model.User).first()
# Crash, because querying causes a transaction commit. But...
# which transaction? Why does this seem to cause the second
# test (only) to fail?.
def test_broken_1(self):
ok_(True)
def test_broken_2(self):
ok_(True)
a1
I suggest you try to update because there were changes to the transaction manager due to some compatibility issues with transaction library
setUp
, so it means it's outside of any request. The transaction manager is not involved.
super().setUp()
does call setup-app
which does commit the transaction that is using to initialize the database (see websetup/schema.py
and websetup/bootstrap.py
both of those commit a transaction)
try:
u = model.User(user_name="what",email_address="what@where.whatever")
model.DBSession.add(u)
except:
transaction.abort()
else:
transaction.commit()