• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python runtime.new_store函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: tearDown

    def tearDown(self):
        # Make sure to remove all committed persons from the database
        with new_store() as store:
            test_names = [u'dummy transaction test', u'dummy', u'doe', u'john']
            store.find(Person, Person.name.is_in(test_names)).remove()

        DomainTest.tearDown(self)
开发者ID:Guillon88,项目名称:stoq,代码行数:7,代码来源:test_transaction.py


示例17: _register_station

    def _register_station(self):
        # Register the current computer as a branch station
        from stoqlib.database.runtime import new_store
        from stoqlib.domain.person import Branch
        from stoqlib.domain.station import BranchStation
        from stoqlib.exceptions import StoqlibError
        from stoqlib.net.socketutils import get_hostname
        store = new_store()

        branches = store.find(Branch)
        if branches:
            branch = branches[0]
        else:
            branch = None

        try:
            BranchStation(store=store,
                          is_active=True,
                          branch=branch,
                          name=get_hostname())
        except StoqlibError as e:
            raise SystemExit("ERROR: %s" % e)

        store.commit()
        store.close()
开发者ID:barkinet,项目名称:stoq,代码行数:25,代码来源:dbadmin.py


示例18: _cancel_last_document

    def _cancel_last_document(self):
        try:
            self._validate_printer()
        except DeviceError as e:
            warning(str(e))
            return

        store = new_store()
        last_doc = self._get_last_document(store)
        if not self._confirm_last_document_cancel(last_doc):
            store.close()
            return

        if last_doc.last_till_entry:
            self._cancel_last_till_entry(last_doc, store)
        elif last_doc.last_sale:
            # Verify till balance before cancel the last sale.
            till = Till.get_current(store)
            if last_doc.last_sale.total_amount > till.get_balance():
                warning(_("You do not have this value on till."))
                store.close()
                return
            cancelled = self._printer.cancel()
            if not cancelled:
                info(_("Cancelling sale failed, nothing to cancel"))
                store.close()
                return
            else:
                self._cancel_last_sale(last_doc, store)
        store.commit()
开发者ID:LeonamSilva,项目名称:stoq,代码行数:30,代码来源:ecfui.py


示例19: _reset_last_doc

 def _reset_last_doc(self):
     # Last ecf document is not a sale or a till_entry anymore.
     store = new_store()
     printer = store.fetch(self._printer._printer)
     printer.last_till_entry = None
     printer.last_sale = None
     store.commit()
开发者ID:LeonamSilva,项目名称:stoq,代码行数:7,代码来源:ecfui.py


示例20: create_default_profiles

def create_default_profiles():
    store = new_store()

    log.info("Creating user default profiles")
    UserProfile.create_profile_template(store, _(u'Administrator'), True)
    UserProfile.create_profile_template(store, _(u'Manager'), True)
    UserProfile.create_profile_template(store, _(u'Salesperson'), False)

    store.commit(close=True)
开发者ID:romaia,项目名称:stoq,代码行数:9,代码来源:admin.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python address.CityLocation类代码示例发布时间:2022-05-27
下一篇:
Python runtime.get_default_store函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap