當前位置: 首頁>>代碼示例>>Python>>正文


Python DBSession.add方法代碼示例

本文整理匯總了Python中kotti.resources.DBSession.add方法的典型用法代碼示例。如果您正苦於以下問題:Python DBSession.add方法的具體用法?Python DBSession.add怎麽用?Python DBSession.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在kotti.resources.DBSession的用法示例。


在下文中一共展示了DBSession.add方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: populate

# 需要導入模塊: from kotti.resources import DBSession [as 別名]
# 或者: from kotti.resources.DBSession import add [as 別名]
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()
開發者ID:WenkeZhou,項目名稱:Kotti,代碼行數:28,代碼來源:populate.py

示例2: test_unique_constraint

# 需要導入模塊: from kotti.resources import DBSession [as 別名]
# 或者: from kotti.resources.DBSession import add [as 別名]
    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)
開發者ID:tomster,項目名稱:Kotti,代碼行數:10,代碼來源:tests.py

示例3: _add_document_from_file

# 需要導入模塊: from kotti.resources import DBSession [as 別名]
# 或者: from kotti.resources.DBSession import add [as 別名]
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
開發者ID:twei55,項目名稱:Kotti,代碼行數:10,代碼來源:populate.py

示例4: populate

# 需要導入模塊: from kotti.resources import DBSession [as 別名]
# 或者: from kotti.resources.DBSession import add [as 別名]
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()
開發者ID:Doik,項目名稱:Kotti,代碼行數:10,代碼來源:populate.py

示例5: populate

# 需要導入模塊: from kotti.resources import DBSession [as 別名]
# 或者: from kotti.resources.DBSession import add [as 別名]
def populate():
    if DBSession.query(Node).count() == 0:
        root = Document(**_ROOT_ATTRS)
        root.__acl__ = SITE_ACL
        DBSession.add(root)
        root['about'] = Document(**_ABOUT_ATTRS)

    if DBSession.query(Settings).count() == 0:
        settings = Settings(data={'kotti.db_version': get_version()})
        DBSession.add(settings)

    populate_users()
開發者ID:fschulze,項目名稱:Kotti,代碼行數:14,代碼來源:populate.py

示例6: populate

# 需要導入模塊: from kotti.resources import DBSession [as 別名]
# 或者: from kotti.resources.DBSession import add [as 別名]
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()
開發者ID:appetito,項目名稱:Kotti,代碼行數:15,代碼來源:populate.py

示例7: populate_root_document

# 需要導入模塊: from kotti.resources import DBSession [as 別名]
# 或者: from kotti.resources.DBSession import add [as 別名]
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')
開發者ID:creationlineInc,項目名稱:sea_unicornis,代碼行數:16,代碼來源:populate.py

示例8: populate

# 需要導入模塊: from kotti.resources import DBSession [as 別名]
# 或者: from kotti.resources.DBSession import add [as 別名]
def populate():
    nodecount = DBSession.query(Node).count()
    if nodecount == 0:
        p = _add_document_from_file(
            "home.html", u"", None, u"Welcome to Kotti!", acl=SITE_ACL)
        _add_document_from_file(
            "about.html", u"about", p, u"About")

    settingscount = DBSession.query(Settings).count()
    if settingscount == 0:
        settings = Settings(data={'kotti.db_version': get_version()})
        DBSession.add(settings)

    populate_users()
    DBSession.flush()
    transaction.commit()
開發者ID:twei55,項目名稱:Kotti,代碼行數:18,代碼來源:populate.py

示例9: populate

# 需要導入模塊: from kotti.resources import DBSession [as 別名]
# 或者: from kotti.resources.DBSession import add [as 別名]
def populate():
    """
    Create the root node (Document) and the 'about' subnode in the nodes tree
    if there are no nodes yet.
    """

    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()
開發者ID:manish-kr,項目名稱:Kotti,代碼行數:20,代碼來源:populate.py

示例10: populate

# 需要導入模塊: from kotti.resources import DBSession [as 別名]
# 或者: from kotti.resources.DBSession import add [as 別名]
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.id).count() == 0:
        pkgdir = os.path.dirname(__file__)
        pagesdir = os.path.join(pkgdir, 'static/pages')
        #import pdb ; pdb.set_trace()
        root_filename = os.path.join(pagesdir, 'index.md')
        root_atts = make_markdown_attrs('', root_filename,
                                        title='Welcome to XYZZY',
                                        description='Home Page')
        root_atts['body'] = markdown.markdown(root_atts['body'])
        root = Document(**root_atts)
        root.__acl__ = SITE_ACL
        DBSession.add(root)
        webatts = make_markdown_attrs('webdesign',
                                      os.path.join(
                                          pagesdir, 'webdesign/index.md'),
                                      title='Web Design',
                                      description='Pages on Web Design')
        root['webdesign'] = MarkDownDocument(**webatts)
        wpages = ['history', 'development', 'stylesheets',
                  'javascript-components']
        for wp in wpages:
            wpfn = os.path.join(pagesdir, 'webdesign/%s.md' % wp)
            wptitle = ' '.join([p.capitalize() for p in wp.split('-')])
            wpatts = make_markdown_attrs(wp, wpfn, title=wptitle)
            root['webdesign'][wp] = MarkDownDocument(**wpatts)
        
        wf = get_workflow(root)
        if wf is not None:
            DBSession.flush()  # Initializes workflow
            wf.transition_to_state(root, None, u'public')

    populate_users()
開發者ID:umeboshi2,項目名稱:xyzzy,代碼行數:44,代碼來源:populate.py

示例11: test_container_methods

# 需要導入模塊: from kotti.resources import DBSession [as 別名]
# 或者: from kotti.resources.DBSession import add [as 別名]
    def test_container_methods(self):
        session = DBSession()

        # Test some of Node's container methods:
        root = session.query(Node).get(1)
        self.assertEquals(root.keys(), [])

        child1 = Node(name=u'child1', parent=root)
        session.add(child1)
        self.assertEquals(root.keys(), [u'child1'])
        self.assertEquals(root[u'child1'], child1)

        del root[u'child1']
        self.assertEquals(root.keys(), [])        

        # When we delete a parent node, all its child nodes will be
        # released as well:
        root[u'child2'] = Node()
        root[u'child2'][u'subchild'] = Node()
        self.assertEquals(
            session.query(Node).filter(Node.name == u'subchild').count(), 1)
        del root[u'child2']
        self.assertEquals(
            session.query(Node).filter(Node.name == u'subchild').count(), 0)
開發者ID:tomster,項目名稱:Kotti,代碼行數:26,代碼來源:tests.py

示例12: link_translation

# 需要導入模塊: from kotti.resources import DBSession [as 別名]
# 或者: from kotti.resources.DBSession import add [as 別名]
def link_translation(source, target):
    DBSession.add(Translation(source=source, target=target))
開發者ID:nightmarebadger,項目名稱:kotti_multilingual,代碼行數:4,代碼來源:api.py


注:本文中的kotti.resources.DBSession.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。