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


Python runtime.new_store函数代码示例

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


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

示例1: testCacheInvalidation

    def testCacheInvalidation(self):
        # First create a new person in an outside transaction
        outside_store = new_store()
        outside_person = Person(name=u'doe', store=outside_store)
        outside_store.commit()

        # Get this person in the default store
        default_store = get_default_store()
        db_person = default_store.find(Person, id=outside_person.id).one()
        self.assertEqual(db_person.name, u'doe')

        # Now, select that same person in an inside store
        inside_store = new_store()
        inside_person = inside_store.fetch(outside_person)

        # Change and commit the changes on this inside store
        inside_person.name = u'john'

        # Flush to make sure the database was updated
        inside_store.flush()

        # Before comminting the other persons should still be 'doe'
        self.assertEqual(db_person.name, u'doe')
        self.assertEqual(outside_person.name, u'doe')

        inside_store.commit()

        # We expect the changes to reflect on the connection
        self.assertEqual(db_person.name, u'john')

        # and also on the outside store
        self.assertEqual(outside_person.name, u'john')

        outside_store.close()
        inside_store.close()
开发者ID:marianaanselmo,项目名称:stoq,代码行数:35,代码来源:test_transaction.py

示例2: testSetNotMandatory

    def testSetNotMandatory(self):
        store = self.store
        store2 = new_store()
        store3 = new_store()

        client_form = store.find(UIForm, form_name=u'client').one()
        field = store.find(UIField,
                           ui_form=client_form, field_name=u'name').one()
        self.assertEquals(field.mandatory, True)

        field2 = store2.find(UIField,
                             ui_form=client_form, field_name=u'name').one()

        dialog = FormFieldEditor(self.store)
        dialog.forms.select(client_form)
        self.assertEquals(dialog.fields.get_cell_contents()[7][2], True)
        setattr(field, 'mandatory', False)
        dialog.fields.refresh()
        self.assertEquals(dialog.fields.get_cell_contents()[7][2], False)
        self.assertEquals(field2.mandatory, True)
        dialog.confirm()

        field3 = store3.find(UIField,
                             ui_form=client_form, field_name=u'name').one()
        self.assertEquals(field3.mandatory, False)

        store2.close()
        store3.close()

        # Restore initial state of the test database.
        setattr(field, 'mandatory', True)
        store.commit()
开发者ID:leandrorchaves,项目名称:stoq,代码行数:32,代码来源:test_formfieldeditor.py

示例3: test_dirty_flag

    def test_dirty_flag(self):
        # Creating an object should set its sync_status to 0 (not synced)
        store = new_store()
        obj = WillBeCommitted(store=store)
        obj_id = obj.id
        store.commit()
        self.assertEqual(obj.te.sync_status, '0')

        # Reset the flag to test changing the object
        obj.te.sync_status = '1'
        store.commit()
        store.close()

        # Get the same object from a new connection
        store = new_store()
        obj = store.get(WillBeCommitted, obj_id)

        # The bit must still be set to 1
        self.assertEqual(obj.te.sync_status, '1')

        # Changing the object and commiting should update the flag
        obj.test_var = u'asd'
        store.commit()
        self.assertEqual(obj.te.sync_status, '0')
        store.close()
开发者ID:hackedbellini,项目名称:stoq,代码行数:25,代码来源:test_runtime.py

示例4: test_dirty_flag

    def test_dirty_flag(self):
        # Creating an object should set its dirty flag to True
        store = new_store()
        obj = WillBeCommitted(store=store)
        obj_id = obj.id
        store.commit()
        self.assertTrue(obj.te.dirty)

        # Reset the flag to test changing the object
        obj.te.dirty = False
        store.commit()
        store.close()

        # Get the same object from a new connection
        store = new_store()
        obj = store.get(WillBeCommitted, obj_id)

        # The flag must be False
        self.assertFalse(obj.te.dirty)

        # Changing the object and commiting should update the flag
        obj.test_var = u'asd'
        store.commit()
        self.assertTrue(obj.te.dirty)
        store.close()
开发者ID:Joaldino,项目名称:stoq,代码行数:25,代码来源:test_runtime.py

示例5: test_autoreload

    def test_autoreload(self):
        # Create 3 stores.
        store1 = new_store()
        store2 = new_store()

        obj1 = WillBeCommitted(store=store1, test_var='ID1')
        store1.commit()

        obj2 = store2.get(WillBeCommitted, obj1.id)
        obj2

        store2.close()

        autoreload_object(obj1)
开发者ID:hackedbellini,项目名称:stoq,代码行数:14,代码来源:test_runtime.py

示例6: test_get_pending_count_with_savepoint

    def test_get_pending_count_with_savepoint(self):
        store = new_store()
        self.assertEqual(store.get_pending_count(), 0)

        obj = WillBeCommitted(store=store)
        self.assertEqual(store.get_pending_count(), 1)

        # savepoint should trigger a flush, making the next change set
        # obj dirty again
        store.savepoint("savepoint_a")
        obj.test_var = u'yyy'
        self.assertEqual(store.get_pending_count(), 2)

        store.savepoint("savepoint_b")
        obj.test_var = u'zzz'
        self.assertEqual(store.get_pending_count(), 3)

        store.savepoint("savepoint_c")
        obj.test_var = u'www'
        self.assertEqual(store.get_pending_count(), 4)

        store.rollback_to_savepoint("savepoint_b")
        self.assertEqual(store.get_pending_count(), 2)

        store.rollback()
开发者ID:hackedbellini,项目名称:stoq,代码行数:25,代码来源:test_runtime.py

示例7: _provide_current_station

def _provide_current_station(station_name=None, branch_name=None):
    if not station_name:
        station_name = get_hostname()
    store = new_store()
    if branch_name:
        branch = store.find(Person,
                            And(Person.name == branch_name,
                                Branch.person_id == Person.id)).one()
    else:
        branches = store.find(Branch)
        if branches.count() == 0:
            person = Person(name=u"test", store=store)
            branch = Branch(person=person, store=store)
        else:
            branch = branches[0]

    provide_utility(ICurrentBranch, branch)

    station = BranchStation.get_station(store, branch, station_name)
    if not station:
        station = BranchStation.create(store, branch, station_name)

    assert station
    assert station.is_active

    provide_utility(ICurrentBranchStation, station)
    store.commit(close=True)
开发者ID:leandrorchaves,项目名称:stoq,代码行数:27,代码来源:testsuite.py

示例8: install_plugin

    def install_plugin(self, plugin_name):
        """Install and enable a plugin

        @important: Calling this makes a plugin installed, but, it's
            your responsability to activate it!

        :param plugin: the :class:`IPlugin` implementation of the plugin
        """
        # Try to get the plugin first. If it was't registered yet,
        # PluginError will be raised.
        plugin = self.get_plugin(plugin_name)

        if plugin_name in self.installed_plugins_names:
            raise PluginError("Plugin %s is already enabled."
                              % (plugin_name, ))

        store = new_store()
        InstalledPlugin(store=store,
                        plugin_name=plugin_name,
                        plugin_version=0)
        store.commit(close=True)

        migration = plugin.get_migration()
        if migration:
            try:
                migration.apply_all_patches()
            except SQLError:
                # This means a lock could not be obtained. Warn user about this
                # and let stoq restart, that the schema will be upgraded
                # correctly
                error('Não foi possível terminar a instalação do plugin. '
                      'Por favor reinicie todas as instancias do Stoq que '
                      'estiver executando')
开发者ID:romaia,项目名称:stoq,代码行数:33,代码来源:pluginmanager.py

示例9: _check_param_online_services

    def _check_param_online_services(self):
        from stoqlib.database.runtime import get_default_store, new_store
        from stoqlib.lib.parameters import sysparam
        import gtk

        sparam = sysparam(get_default_store())
        if sparam.ONLINE_SERVICES is None:
            from kiwi.ui.dialogs import HIGAlertDialog
            # FIXME: All of this is to avoid having to set markup as the default
            #        in kiwi/ui/dialogs:HIGAlertDialog.set_details, after 1.0
            #        this can be simplified when we fix so that all descriptions
            #        sent to these dialogs are properly escaped
            dialog = HIGAlertDialog(
                parent=None,
                flags=gtk.DIALOG_MODAL,
                type=gtk.MESSAGE_WARNING)
            dialog.add_button(_("Not right now"), gtk.RESPONSE_NO)
            dialog.add_button(_("Enable online services"), gtk.RESPONSE_YES)

            dialog.set_primary(_('Do you want to enable Stoq online services?'))
            dialog.set_details(PRIVACY_STRING, use_markup=True)
            dialog.set_default_response(gtk.RESPONSE_YES)
            response = dialog.run()
            dialog.destroy()
            store = new_store()
            sysparam(store).ONLINE_SERVICES = int(bool(response == gtk.RESPONSE_YES))
            store.commit()
            store.close()
开发者ID:qman1989,项目名称:stoq,代码行数:28,代码来源:shell.py

示例10: _enable_demo

    def _enable_demo(self):
        from stoqlib.database.runtime import new_store

        store = new_store()
        store.execute("UPDATE parameter_data SET field_value = '1' WHERE field_name = 'DEMO_MODE';")
        store.commit()
        store.close()
开发者ID:rg3915,项目名称:stoq,代码行数:7,代码来源:dbadmin.py

示例11: initialize_system

def initialize_system(password=None, testsuite=False,
                      force=False):
    """Call all the necessary methods to startup Stoq applications for
    every purpose: production usage, testing or demonstration
    """

    log.info("Initialize_system")
    try:
        db_settings.clean_database(db_settings.dbname, force=force)
        create_base_schema()
        create_log("INIT START")
        store = new_store()
        populate_initial_data(store)
        register_accounts(store)
        register_payment_methods(store)
        from stoqlib.domain.uiform import create_default_forms
        create_default_forms(store)
        store.commit(close=True)
        ensure_sellable_constants()
        ensure_system_parameters()
        _ensure_card_providers()
        create_default_profiles()
        _install_invoice_templates()

        if not testsuite:
            create_default_profile_settings()
            ensure_admin_user(password)
    except Exception, e:
        raise
        if not testsuite:
            collect_traceback(sys.exc_info(), submit=True)
        raise SystemExit("Could not initialize system: %r" % (e, ))
开发者ID:romaia,项目名称:stoq,代码行数:32,代码来源:admin.py

示例12: _check_param_online_services

    def _check_param_online_services(self):
        from stoqlib.database.runtime import new_store
        from stoqlib.lib.parameters import sysparam
        from gi.repository import Gtk

        if sysparam.get_bool('ONLINE_SERVICES') is None:
            from kiwi.ui.dialogs import HIGAlertDialog
            # FIXME: All of this is to avoid having to set markup as the default
            #        in kiwi/ui/dialogs:HIGAlertDialog.set_details, after 1.0
            #        this can be simplified when we fix so that all descriptions
            #        sent to these dialogs are properly escaped
            dialog = HIGAlertDialog(
                parent=None,
                flags=Gtk.DialogFlags.MODAL,
                type=Gtk.MessageType.WARNING)
            dialog.add_button(_("Not right now"), Gtk.ResponseType.NO)
            dialog.add_button(_("Enable online services"), Gtk.ResponseType.YES)

            dialog.set_primary(_('Do you want to enable Stoq online services?'))
            dialog.set_details(PRIVACY_STRING, use_markup=True)
            dialog.set_default_response(Gtk.ResponseType.YES)
            response = dialog.run()
            dialog.destroy()
            store = new_store()
            sysparam.set_bool(store, 'ONLINE_SERVICES', response == Gtk.ResponseType.YES)
            store.commit()
            store.close()
开发者ID:hackedbellini,项目名称:stoq,代码行数:27,代码来源:shell.py

示例13: setUp

    def setUp(self):
        super(TestPluginManager, self).setUp()

        # Generate 2 instances of plugins that will be used for testing later.
        # '_dependent_plugin' will require 'independent_plugin' activation prior
        # to it's own.
        self._independent_plugin = _TestPlugin()
        self._dependent_plugin = _TestDependentPlugin()

        # Since the plugins are commited inside pluginmanager, try to remove
        # it first, or we will have problems if STOQLIB_TEST_QUICK is set.
        store = new_store()
        plugins = set(InstalledPlugin.get_plugin_names(store=self.store))
        expected = set([u'ecf', u'nfe', u'optical'])
        self.assertTrue(expected.issubset(plugins))

        ind_name = self._independent_plugin.name
        dep_name = self._dependent_plugin.name
        plugin_names = [ind_name, dep_name]

        test_plugins = store.find(InstalledPlugin,
                                  InstalledPlugin.plugin_name.is_in(plugin_names))
        for plugin in test_plugins:
            store.remove(plugin)
            store.commit()
        store.close()

        self._manager = get_plugin_manager()
        self._register_test_plugin()
开发者ID:Guillon88,项目名称:stoq,代码行数:29,代码来源:test_pluginmanager.py

示例14: tearDown

 def tearDown(self):
     store = new_store()
     for person in store.find(Person, name=NAME):
         store.remove(person)
     store.commit()
     DomainTest.tearDown(self)
     store.close()
开发者ID:leandrorchaves,项目名称:stoq,代码行数:7,代码来源:test_transaction.py

示例15: _check_branch

    def _check_branch(self):
        from stoqlib.database.runtime import (get_default_store, new_store,
                                              get_current_station,
                                              set_current_branch_station)
        from stoqlib.domain.person import Company
        from stoqlib.lib.parameters import sysparam
        from stoqlib.lib.message import info

        default_store = get_default_store()

        compaines = default_store.find(Company)
        if (compaines.count() == 0 or
                not sysparam.has_object('MAIN_COMPANY')):
            from stoqlib.gui.base.dialogs import run_dialog
            from stoqlib.gui.dialogs.branchdialog import BranchDialog
            if self._ran_wizard:
                info(_("You need to register a company before start using Stoq"))
            else:
                info(_("Could not find a company. You'll need to register one "
                       "before start using Stoq"))
            store = new_store()
            person = run_dialog(BranchDialog, None, store)
            if not person:
                raise SystemExit
            branch = person.branch
            sysparam.set_object(store, 'MAIN_COMPANY', branch)
            current_station = get_current_station(store)
            if current_station is not None:
                current_station.branch = branch
            store.commit()
            store.close()

        set_current_branch_station(default_store, station_name=None)
开发者ID:hackedbellini,项目名称:stoq,代码行数:33,代码来源:shell.py


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