本文整理汇总了Python中tutorial.models.DBSession.query方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.query方法的具体用法?Python DBSession.query怎么用?Python DBSession.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tutorial.models.DBSession
的用法示例。
在下文中一共展示了DBSession.query方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_it
# 需要导入模块: from tutorial.models import DBSession [as 别名]
# 或者: from tutorial.models.DBSession import query [as 别名]
def test_it(self):
from sqlalchemy import create_engine
engine = create_engine('sqlite:///:memory:')
self._callFUT(engine)
from tutorial.models import DBSession, Page
self.assertEqual(DBSession.query(Page).one().data,
'This is the front page')
示例2: edit_page
# 需要导入模块: from tutorial.models import DBSession [as 别名]
# 或者: from tutorial.models.DBSession import query [as 别名]
def edit_page(request):
name = request.matchdict['pagename']
session = DBSession()
page = session.query(Page).filter_by(name=name).one()
if 'form.submitted' in request.params:
page.data = request.params['body']
session.add(page)
return HTTPFound(location = route_url('view_page', request,
pagename=name))
return dict(
page=page,
save_url = route_url('edit_page', request, pagename=name),
)
示例3: view_page
# 需要导入模块: from tutorial.models import DBSession [as 别名]
# 或者: from tutorial.models.DBSession import query [as 别名]
def view_page(request):
matchdict = request.matchdict
session = DBSession()
page = session.query(Page).filter_by(name=matchdict['pagename']).one()
def check(match):
word = match.group(1)
exists = session.query(Page).filter_by(name=word).all()
if exists:
view_url = route_url('view_page', request, pagename=word)
return '<a href="%s">%s</a>' % (view_url, word)
else:
add_url = route_url('add_page', request, pagename=word)
return '<a href="%s">%s</a>' % (add_url, word)
content = publish_parts(page.data, writer_name='html')['html_body']
content = wikiwords.sub(check, content)
edit_url = route_url('edit_page', request,
pagename=matchdict['pagename'])
return dict(page=page, content=content, edit_url=edit_url)
示例4: view_page
# 需要导入模块: from tutorial.models import DBSession [as 别名]
# 或者: from tutorial.models.DBSession import query [as 别名]
def view_page(request):
pagename = request.matchdict['pagename']
session = DBSession()
page = session.query(Page).filter_by(name=pagename).first()
if page is None:
return HTTPNotFound('No such page')
def check(match):
word = match.group(1)
exists = session.query(Page).filter_by(name=word).all()
if exists:
view_url = route_url('view_page', request, pagename=word)
return '<a href="%s">%s</a>' % (view_url, word)
else:
add_url = route_url('add_page', request, pagename=word)
return '<a href="%s">%s</a>' % (add_url, word)
content = publish_parts(page.data, writer_name='html')['html_body']
content = wikiwords.sub(check, content)
edit_url = route_url('edit_page', request, pagename=pagename)
logged_in = authenticated_userid(request)
return dict(page=page, content=content, edit_url=edit_url,
logged_in=logged_in)
示例5: test_it
# 需要导入模块: from tutorial.models import DBSession [as 别名]
# 或者: from tutorial.models.DBSession import query [as 别名]
def test_it(self):
self._callFUT({'sqlalchemy.url':'sqlite://'})
from tutorial.models import DBSession, Page
self.assertEqual(DBSession.query(Page).one().data,
'This is the front page')
示例6: my_view
# 需要导入模块: from tutorial.models import DBSession [as 别名]
# 或者: from tutorial.models.DBSession import query [as 别名]
def my_view(request):
dbsession = DBSession()
root = dbsession.query(MyModel).filter(MyModel.name==u'root').first()
return {'root':root, 'project':'tutorial'}