当前位置: 首页>>代码示例>>Python>>正文


Python transaction.commit函数代码示例

本文整理汇总了Python中transaction.commit函数的典型用法代码示例。如果您正苦于以下问题:Python commit函数的具体用法?Python commit怎么用?Python commit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了commit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_fixtures

 def add_fixtures(self):
     from pysite.models import DbSession
     from pprint import pprint
     sess = DbSession()
     transaction.begin()
     try:
         # Add in this sequence
         for g in self.__class__.FIXT_GROUPS:
             data = self.fixtures[g]
             print("***", g)
             for it in data:
                 it['owner'] = UNIT_TESTER_UID
                 pprint(it)
                 if g == 'roles':
                     usrmanager.add_role(it)
                 elif g == 'principals':
                     usrmanager.add_principal(it)
                 elif g == 'vmail_domains':
                     vmailmanager.add_domain(it)
                 elif g == 'vmail_mailboxes':
                     vmailmanager.add_mailbox(it)
                 elif g == 'vmail_aliases':
                     vmailmanager.add_alias(it)
                 else:
                     raise Exception("Unknown fixture group: '{0}'".format(
                         g))
         transaction.commit()
     except Exception as e:
         transaction.abort()
         raise e
开发者ID:dmdm,项目名称:PySite,代码行数:30,代码来源:app.py

示例2: inject_changes

 def inject_changes():
     # Change the database just after the list of objects
     # to analyze has been determined.
     child2 = PersistentMapping()
     root['child2'] = child2
     transaction.commit()
     expect_oids.append(child2._p_oid)
开发者ID:mamico,项目名称:relstorage,代码行数:7,代码来源:reltestbase.py

示例3: _import_users

def _import_users(context: IResource, registry: Registry, filename: str):
    users_info = _load_users_info(filename)
    users_info = [_normalize_user_info(u) for u in users_info]
    users = find_service(context, 'principals', 'users')
    groups = find_service(context, 'principals', 'groups')
    for user_info in users_info:
        user_by_name, user_by_email = _locate_user(user_info,
                                                   context,
                                                   registry)
        if user_by_name or user_by_email:
            logger.info('Updating user {} ({})'.format(user_info['name'],
                                                       user_info['email']))
            _update_user(user_by_name, user_by_email, user_info, groups)
        else:
            logger.info('Creating user {}'.format(user_info['name']))
            send_invitation = user_info.get('send_invitation_mail', False)
            activate = not send_invitation
            user = _create_user(user_info, users, registry, groups,
                                activate=activate)
            if send_invitation:
                logger.info('Sending invitation mail to {}'.format(user.name))
                _send_invitation_mail(user, user_info, registry)
            badge_names = user_info.get('badges', [])
            if badge_names:
                logger.info('Assign badge for user {}'.format(user.name))
                badges = _create_badges(user, badge_names, registry)
                _assign_badges(user, badges, registry)
    transaction.commit()
开发者ID:robx,项目名称:adhocracy3.mercator,代码行数:28,代码来源:import_users.py

示例4: checkAutoReconnect

    def checkAutoReconnect(self):
        # Verify auto-reconnect
        db = DB(self._storage)
        try:
            c1 = db.open()
            r = c1.root()
            r['alpha'] = 1
            transaction.commit()
            c1.close()

            c1._storage._load_conn.close()
            c1._storage._store_conn.close()
            # ZODB5 implicitly calls sync
            # immediately when a connection is opened;
            # fake that here for older releases.
            c2 = db.open()
            self.assertIs(c2, c1)
            c2.sync()
            r = c2.root()
            self.assertEqual(r['alpha'], 1)
            r['beta'] = PersistentMapping()
            c2.add(r['beta'])
            transaction.commit()
            c2.close()
        finally:
            db.close()
开发者ID:mamico,项目名称:relstorage,代码行数:26,代码来源:reltestbase.py

示例5: checkPackBatchLockNoWait

    def checkPackBatchLockNoWait(self):
        # Exercise the code in the pack algorithm that attempts to get the
        # commit lock but will sleep if the lock is busy.
        self._storage = self.make_storage(pack_batch_timeout=0)

        adapter = self._storage._adapter
        test_conn, test_cursor = adapter.connmanager.open()

        slept = []
        def sim_sleep(seconds):
            slept.append(seconds)
            adapter.locker.release_commit_lock(test_cursor)
            test_conn.rollback()
            adapter.connmanager.close(test_conn, test_cursor)

        db = DB(self._storage)
        try:
            # add some data to be packed
            c = db.open()
            r = c.root()
            r['alpha'] = PersistentMapping()
            transaction.commit()
            del r['alpha']
            transaction.commit()

            # Pack, with a commit lock held
            now = packtime = time.time()
            while packtime <= now:
                packtime = time.time()
            adapter.locker.hold_commit_lock(test_cursor)
            self._storage.pack(packtime, referencesf, sleep=sim_sleep)

            self.assertTrue(len(slept) > 0)
        finally:
            db.close()
开发者ID:mamico,项目名称:relstorage,代码行数:35,代码来源:reltestbase.py

示例6: bootStrapSubscriber

def bootStrapSubscriber(event):
    """The actual subscriber to the bootstrap IDataBaseOpenedEvent

    Boostrap a Zope3 instance given a database object This first checks if the
    root folder exists and has a site manager.  If it exists, nothing else
    is changed.  If no root folder exists, one is added.
    """

    db, connection, root, root_folder = getInformationFromEvent(event)
    root_created = False

    if root_folder is None:
        root_created = True
        # ugh... we depend on the root folder implementation
        root_folder = rootFolder()
        root[ZopePublication.root_name] = root_folder
        if not ISite.providedBy(root_folder):
            site_manager = site.LocalSiteManager(root_folder)
            root_folder.setSiteManager(site_manager)

        transaction.commit()

    connection.close()

    zope.event.notify(interfaces.DatabaseOpenedWithRoot(db))
开发者ID:wpjunior,项目名称:proled,代码行数:25,代码来源:bootstrap.py

示例7: test_statusmap_on_objects_having_inactive_content

    def test_statusmap_on_objects_having_inactive_content(self, browser):
        # Create a container which will hold the content used for this test.
        # The container does not play an important role in the test.
        folder = create(Builder('folder').titled('Container'))

        # Create some content used in this test.
        create(Builder('folder')
               .titled('Active Folder')
               .within(folder))
        create(Builder('folder')
               .titled('Inactive Folder')
               .having(effectiveDate=DateTime() + 10)
               .within(folder))

        # A user not having the permission to access inactive content can only
        # change the state of the container and the active folder inside the
        # container, but not the inactive folder inside the container.
        # Thus the inactive folder must not be visible in the statusmap view.
        setRoles(self.portal, TEST_USER_ID, ['Contributor'])
        transaction.commit()
        browser.login().visit(folder, view="@@statusmap")
        self.assertEqual(
            ['Container', 'Active Folder'],
            browser.css('.listing tr td span').text
        )

        # A manager can also change the state of the inactive folder.
        # Thus the inactive folder must be visible in the statusmap view too.
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        transaction.commit()
        browser.login().visit(folder, view="@@statusmap")
        self.assertEqual(
            ['Container', 'Active Folder', 'Inactive Folder'],
            browser.css('.listing tr td span').text
        )
开发者ID:4teamwork,项目名称:ftw.statusmap,代码行数:35,代码来源:test_view_functional.py

示例8: test_statusmap_on_inactive_content

    def test_statusmap_on_inactive_content(self, browser):
        inactive_folder = create(Builder('folder')
                                 .titled('Inactive Folder')
                                 .having(effectiveDate=DateTime() + 10)
                                 .within(self.portal))

        create(Builder('folder')
               .titled('Active Folder')
               .within(inactive_folder))

        # A user not having the permission to access inactive content must
        # be able to change the state of the inactive content itself, i.e.
        # calling the statusmap view on an inactive context.
        setRoles(self.portal, TEST_USER_ID, ['Contributor'])
        transaction.commit()
        browser.login().visit(inactive_folder, view="@@statusmap")
        self.assertEqual(
            ['Inactive Folder', 'Active Folder'],
            browser.css('.listing tr td span').text
        )

        # The same applies to a user having the permission to access inactive
        # content.
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        transaction.commit()
        browser.login().visit(inactive_folder, view="@@statusmap")
        self.assertEqual(
            ['Inactive Folder', 'Active Folder'],
            browser.css('.listing tr td span').text
        )
开发者ID:4teamwork,项目名称:ftw.statusmap,代码行数:30,代码来源:test_view_functional.py

示例9: activateCondition

 def activateCondition(self, name=None):
     registry = getUtility(IRegistry)
     settings = registry.forInterface(ISettings)
     settings.enabled = True
     if name:
         settings.activated = set((name,))
     transaction.commit()
开发者ID:collective,项目名称:wildcard.lockdown,代码行数:7,代码来源:test_lockdown.py

示例10: _registerPackage

def _registerPackage(module_, init_func=None):
    """Registers the given python package as a Zope 2 style product
    """

    if not hasattr(module_, '__path__'):
        raise ValueError("Must be a package and the " \
                         "package must be filesystem based")
    
    app = Zope2.app()
    try:
        product = initializeProduct(module_, 
                                    module_.__name__, 
                                    module_.__path__[0],
                                    app)

        product.package_name = module_.__name__

        if init_func is not None:
            newContext = ProductContext(product, app, module_)
            init_func(newContext)
    finally:
        try:
            import transaction
            transaction.commit()
        finally:
            app._p_jar.close()
开发者ID:goschtl,项目名称:zope,代码行数:26,代码来源:fiveconfigure.py

示例11: get_login_headers

def get_login_headers(request, user):
    headers = remember(request, user.email)
    user.last_login_date = datetime.now()
    DBSession.add(user)
    DBSession.flush()
    transaction.commit()
    return headers
开发者ID:aagusti,项目名称:i-sipkd,代码行数:7,代码来源:__init__.py

示例12: checkin_documents_for_user

def checkin_documents_for_user(portal, options):
    """Attempts to check in all documents checked out by a particular user.
    """
    username = options.user

    # Assume security context of user
    user = portal.acl_users.getUser(username)
    user = user.__of__(portal.acl_users)
    newSecurityManager(portal, user)

    catalog = getToolByName(portal, 'portal_catalog')
    docs = catalog(portal_type='opengever.document.document')
    checked_out_docs = [b.getObject() for b in docs if b.checked_out == username]

    for obj in checked_out_docs:
        manager = getMultiAdapter((obj, obj.REQUEST), ICheckinCheckoutManager)
        if not manager.is_checkin_allowed():
            print "WARNING: Checkin not allowed for document %s" % obj.absolute_url()
            print checkin_not_allowed_reason(obj)
        else:
            if not options.dryrun:
                manager.checkin(comment=options.comment)
                print "Checked in document %s" % obj.absolute_url()
            else:
                print "Would checkin document %s" % obj.absolute_url()

    if not options.dryrun:
        transaction.commit()
开发者ID:4teamwork,项目名称:opengever.maintenance,代码行数:28,代码来源:checkin_all_docs.py

示例13: delete_restore_single_result

 def delete_restore_single_result(self, result_id):
     try:
         DBSession.query(VMRestoreResult).filter(VMRestoreResult.id == result_id).delete()
         LOGGER.info('VM restore single result is deleted.')
         transaction.commit()
     except Exception as ex:
         LOGGER.error(to_str(ex).replace("'", ''))
开发者ID:smarkm,项目名称:ovm,代码行数:7,代码来源:Restore.py

示例14: registerLocalUser

 def registerLocalUser(cls, email='', password='', groups=None):
     from quizsmith.app.models import Groups
     if groups == None:
         groups = [Groups.by(3).first()]
     user = Users(email=email, password=password, groups=groups)
     DBSession.add(user)
     transaction.commit()
开发者ID:hietpasd,项目名称:quizsmith,代码行数:7,代码来源:users.py

示例15: __call__

    def __call__(self, name, content_type, data):
        ctr = getToolByName(self.context, 'content_type_registry')
        type_ = ctr.findTypeName(name.lower(), '', '') or 'File'

        # XXX: quick fix for german umlauts
        name = name.decode("utf8")

        normalizer = getUtility(IFileNameNormalizer)
        chooser = INameChooser(self.context)

        # otherwise I get ZPublisher.Conflict ConflictErrors
        # when uploading multiple files
        upload_lock.acquire()

        # this should fix #8
        newid = chooser.chooseName(normalizer.normalize(name),
                                   self.context.aq_parent)
        try:
            transaction.begin()
            obj = ploneutils._createObjectByType(type_,
                                                 self.context, newid)
            mutator = obj.getPrimaryField().getMutator(obj)
            mutator(data, content_type=content_type)
            obj.setTitle(name)
            obj.reindexObject()

            notify(ObjectInitializedEvent(obj))
            notify(ObjectModifiedEvent(obj))

            transaction.commit()
        finally:
            upload_lock.release()
        return obj
开发者ID:cillianderoiste,项目名称:plone.app.widgets,代码行数:33,代码来源:factories.py


注:本文中的transaction.commit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。