本文整理匯總了Python中kotti.resources.DBSession類的典型用法代碼示例。如果您正苦於以下問題:Python DBSession類的具體用法?Python DBSession怎麽用?Python DBSession使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DBSession類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_order_of_addable_parents
def test_order_of_addable_parents(self):
from kotti.views.edit import add_node
# The 'add_node' view sorts the 'possible_parents' returned by
# 'addable_types' so that the parent comes first if the
# context we're looking at does not have any children yet.
session = DBSession()
root = session.query(Node).get(1)
request = testing.DummyRequest()
with nodes_addable():
# The child Document does not contain any other Nodes, so it's
# second in the 'possible_parents' list returned by 'node_add':
child = root['child'] = Document(title=u"Child")
info = add_node(child, request)
first_parent, second_parent = info['possible_parents']
self.assertEqual(first_parent['node'], root)
self.assertEqual(second_parent['node'], child)
# Now we add a grandchild and see that this behaviour changes:
child['grandchild'] = Document(title=u"Grandchild")
info = add_node(child, request)
first_parent, second_parent = info['possible_parents']
self.assertEqual(first_parent['node'], child)
self.assertEqual(second_parent['node'], root)
示例2: test_it
def test_it(self):
from kotti.views.view import view_node
session = DBSession()
root = session.query(Node).get(1)
request = testing.DummyRequest()
info = view_node(root, request)
self.assertEqual(info['api'].context, root)
示例3: populate
def populate():
"""
Create the root node (:class:`~kotti.resources.Document`) and the 'about'
subnode in the nodes tree if there are no nodes yet.
"""
lrm = LocalizerRequestMixin()
lrm.registry = get_current_registry()
lrm.locale_name = get_settings()['pyramid.default_locale_name']
localizer = lrm.localizer
if DBSession.query(Node).count() == 0:
localized_root_attrs = dict(
[(k, localizer.translate(v)) for k, v in _ROOT_ATTRS.iteritems()])
root = Document(**localized_root_attrs)
root.__acl__ = SITE_ACL
DBSession.add(root)
localized_about_attrs = dict(
[(k, localizer.translate(v)) for k, v in _ABOUT_ATTRS.iteritems()])
root['about'] = Document(**localized_about_attrs)
wf = get_workflow(root)
if wf is not None:
DBSession.flush() # Initializes workflow
wf.transition_to_state(root, None, u'public')
populate_users()
示例4: _add_document_from_file
def _add_document_from_file(filename, name, parent, title, package='kotti',
directory='populate-content', acl=None):
body = unicode(resource_string(package, os.path.join(directory, filename)))
node = Document(name=name, parent=parent, title=title, body=body)
if acl is not None:
node.__acl__ = acl
DBSession.add(node)
return node
示例5: test_unique_constraint
def test_unique_constraint(self):
session = DBSession()
# Try to add two children with the same name to the root node:
root = session.query(Node).get(1)
session.add(Node(name=u'child1', parent=root))
session.add(Node(name=u'child1', parent=root))
self.assertRaises(IntegrityError, session.flush)
示例6: populate
def populate():
if DBSession.query(Node).count() == 0:
root = Document(**_ROOT_ATTRS)
root.__acl__ = SITE_ACL
DBSession.add(root)
root['about'] = Document(**_ABOUT_ATTRS)
populate_users()
示例7: _make
def _make(self, context=None, id=1):
from kotti.views.util import TemplateAPIEdit
if context is None:
session = DBSession()
context = session.query(Node).get(id)
request = testing.DummyRequest()
return TemplateAPIEdit(context, request)
示例8: populate_users
def populate_users():
principals = get_principals()
if u'admin' not in principals:
principals[u'admin'] = {
'name': u'admin',
'password': get_settings()['kotti.secret'],
'title': u"Administrator",
'groups': [u'role:admin'],
}
DBSession.flush()
transaction.commit()
示例9: test_single_choice
def test_single_choice(self):
from kotti.views.edit import add_node
# The view should redirect straight to the add form if there's
# only one choice of parent and type:
session = DBSession()
root = session.query(Node).get(1)
request = testing.DummyRequest()
response = add_node(root, request)
self.assertEqual(response.status, '302 Found')
self.assertEqual(response.location, 'http://example.com/add_document')
示例10: populate
def populate():
if DBSession.query(Node).count() == 0:
root = Document(**_ROOT_ATTRS)
root.__acl__ = SITE_ACL
DBSession.add(root)
root['about'] = Document(**_ABOUT_ATTRS)
wf = get_workflow(root)
if wf is not None:
DBSession.flush() # Initializes workflow
wf.transition_to_state(root, None, u'public')
populate_users()
示例11: upgrade
def upgrade():
from kotti.resources import DBSession
from alembic.context import get_bind
conn = get_bind()
if conn.engine.dialect.name == 'mysql':
update = "update nodes set path = concat(path, '/') where path not \
like '%/'"
else:
update = "update nodes set path = path || '/' where path not like '%/'"
DBSession.execute(update)
示例12: populate_root_document
def populate_root_document():
if DBSession.query(Node).count() == 0:
root = Document(name=u'', title=u'Front Page')
root.__acl__ = SITE_ACL
root.default_view = 'front-page'
DBSession.add(root)
url = JOB_CONTAINERS['url']
root[url] = Document(title=u'Job Containers', owner=u'admin')
set_groups(u'admin', root[url], set([u'role:owner']))
wf = get_workflow(root)
if wf is not None:
DBSession.flush() # Initializes workflow
wf.transition_to_state(root, None, u'public')
示例13: test_root_acl
def test_root_acl(self):
session = DBSession()
root = session.query(Node).get(1)
# The root object has a persistent ACL set:
self.assertEquals(
root.__acl__, [
('Allow', 'group:managers', security.ALL_PERMISSIONS),
('Allow', 'system.Authenticated', ('view',)),
('Allow', 'group:editors', ('add', 'edit')),
])
# Note how the last ACE is class-defined, that is, users in
# the 'managers' group will have all permissions, always.
# This is to prevent lock-out.
self.assertEquals(root.__acl__[:-2], root._default_acl())
示例14: _used_snippets
def _used_snippets(self, context, slot):
snippets = DBSession.query(DocumentSlotToSnippet).filter(
and_(DocumentSlotToSnippet.document_id == context.id,
DocumentSlotToSnippet.slot_name == slot))\
.order_by(DocumentSlotToSnippet.position).all()
return [{"snippet": "snippet-%d" % snippet.snippet_id} for
snippet in snippets]
示例15: add_translation
def add_translation(context, request):
"""XXX: Check that we dont leak anything"""
source_id = request.params['id']
source = DBSession.query(Content).get(int(source_id))
translation = context[source.__name__] = source.copy()
api.link_translation(source, translation)
return HTTPFound(location=request.resource_url(translation, 'edit'))