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


Python api.get_default_store函数代码示例

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


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

示例1: cookie_login

    def cookie_login(self):
        if api.sysparam(api.get_default_store()).DISABLE_COOKIES:
            log.info("Cookies disable by parameter")
            return

        cookie_file = get_utility(ICookieFile)
        try:
            username, password = cookie_file.get()
        except CookieError:
            log.info("Not using cookie based login")
            return

        def is_md5(password):
            # This breaks for passwords that are 32 characters long,
            # uses only digits and lowercase a-f, pretty unlikely as
            # real-world password
            if len(password) != 32:
                return False
            for c in '1234567890abcdef':
                password = password.replace(c, '')
            return password == ''

        # Migrate old passwords to md5 hashes.
        if not is_md5(password):
            password = _encrypt_password(password)
            cookie_file.store(username, password)

        try:
            user = self._check_user(username, password)
        except (LoginError, UserProfileError, DatabaseError) as e:
            log.info("Cookie login failed: %r" % e)
            return

        log.info("Logging in using cookie credentials")
        return user
开发者ID:leandrorchaves,项目名称:stoq,代码行数:35,代码来源:login.py

示例2: _check_user

    def _check_user(self, username, password):
        username = unicode(username)
        password = unicode(password)
        # This function is really just a post-validation item.
        default_store = api.get_default_store()
        user = default_store.find(LoginUser, username=username).one()
        if not user:
            raise LoginError(_("Invalid user or password"))

        if not user.is_active:
            raise LoginError(_('This user is inactive'))

        branch = api.get_current_branch(default_store)
        # current_branch may not be set if we are registering a new station
        if branch and not user.has_access_to(branch):
            raise LoginError(_('This user does not have access to this branch'))

        if user.pw_hash != password:
            raise LoginError(_("Invalid user or password"))

        # Dont know why, but some users have this empty. Prevent user from
        # login in, since it will break later
        if not user.profile:
            msg = (_("User '%s' has no profile set, "
                     "but this should not happen.") % user.username + '\n\n' +
                   _("Please contact your system administrator or Stoq team."))
            warning(msg)
            raise LoginError(_("User does not have a profile"))

        user.login()

        # ICurrentUser might already be provided which is the case when
        # creating a new database, thus we need to replace it.
        provide_utility(ICurrentUser, user, replace=True)
        return user
开发者ID:leandrorchaves,项目名称:stoq,代码行数:35,代码来源:login.py

示例3: sentry_report

def sentry_report(exctype, value, tb, **tags):
    tags.update({
        'version': stoqserver.version_str,
        'stoq_version': stoq.version,
        'architecture': platform.architecture(),
        'distribution': platform.dist(),
        'python_version': tuple(sys.version_info),
        'system': platform.system(),
        'uname': platform.uname(),
    })
    # Those are inside a try/except because thy require database access.
    # If the database access is not working, we won't be able to get them
    try:
        default_store = api.get_default_store()
        tags['user_hash'] = api.sysparam.get_string('USER_HASH')
        tags['demo'] = api.sysparam.get_bool('DEMO_MODE')
        tags['postgresql_version'] = get_database_version(default_store)
        tags['plugins'] = InstalledPlugin.get_plugin_names(default_store)
        tags['cnpj'] = get_main_cnpj(default_store)
    except Exception:
        pass

    # Disable send sentry log if we are on developer mode.
    developer_mode = stoqserver.library.uninstalled
    if raven_client is not None and not developer_mode:
        if hasattr(raven_client, 'user_context'):
            raven_client.user_context({'id': tags.get('hash', None),
                                       'username': tags.get('cnpj', None)})
        raven_client.captureException((exctype, value, tb), tags=tags)
开发者ID:hackedbellini,项目名称:stoq-server,代码行数:29,代码来源:main.py

示例4: _check_user

    def _check_user(self, username, pw_hash):
        username = unicode(username)
        pw_hash = unicode(pw_hash)
        # This function is really just a post-validation item.
        default_store = api.get_default_store()
        current_branch = api.get_current_branch(default_store)

        user = LoginUser.authenticate(default_store, username, pw_hash,
                                      current_branch)

        # Dont know why, but some users have this empty. Prevent user from
        # login in, since it will break later
        if not user.profile:
            msg = (_("User '%s' has no profile set, "
                     "but this should not happen.") % user.username + '\n\n' +
                   _("Please contact your system administrator or Stoq team."))
            warning(msg)
            raise LoginError(_("User does not have a profile"))

        user.login()

        # ICurrentUser might already be provided which is the case when
        # creating a new database, thus we need to replace it.
        provide_utility(ICurrentUser, user, replace=True)
        return user
开发者ID:Guillon88,项目名称:stoq,代码行数:25,代码来源:login.py

示例5: run_embedded

    def run_embedded(self, appdesc, app_window, params=None):
        app = self._load_app(appdesc, app_window)
        app.launcher = app_window

        self._current_app = app
        self._appname = appdesc.name

        if appdesc.name in self._blocked_apps:
            app_window.show()
            return

        app.run(params)

        # Possibly correct window position (livecd workaround for small
        # screens)
        from stoqlib.lib.pluginmanager import get_plugin_manager
        manager = get_plugin_manager()
        from stoqlib.api import api
        if (api.sysparam(api.get_default_store()).DEMO_MODE
            and manager.is_active(u'ecf')):
            pos = app.main_window.toplevel.get_position()
            if pos[0] < 220:
                app.main_window.toplevel.move(220, pos[1])

        return app
开发者ID:romaia,项目名称:stoq,代码行数:25,代码来源:shell.py

示例6: __init__

    def __init__(self, resource, manager, compact=False):
        self._resource = resource
        self._compact = compact
        self._manager = manager
        user = api.get_current_user(api.get_default_store())
        self._is_admin = user.profile.check_app_permission(u'admin')

        super(ResourceStatusBox, self).__init__(spacing=6)
        if compact:
            self.props.margin = 6
        else:
            self.props.margin = 12

        self.img = Gtk.Image()
        self.pack_start(self.img, False, True, 0)
        self.lbl = Gtk.Label()
        self.lbl.set_xalign(0)
        self.lbl.set_line_wrap(True)
        self.pack_start(self.lbl, False, True, 0)

        self.buttonbox = Gtk.Box()
        self.buttonbox.set_valign(Gtk.Align.CENTER)
        self.buttonbox.get_style_context().add_class('linked')
        if not compact:
            self.pack_end(self.buttonbox, False, True, 0)
开发者ID:hackedbellini,项目名称:stoq,代码行数:25,代码来源:statusbar.py

示例7: get_uri

 def get_uri(self):
     if locale.getlocale()[0] == 'pt_BR' or platform.system() == 'Windows':
         content = environ.find_resource('html', 'welcome-pt_BR.html')
     else:
         content = environ.find_resource('html', 'welcome.html')
     if api.sysparam(api.get_default_store()).DEMO_MODE:
         content += '?demo-mode'
     return 'file:///' + content
开发者ID:leandrorchaves,项目名称:stoq,代码行数:8,代码来源:welcomedialog.py

示例8: on_RemoveSettingsCache__activate

    def on_RemoveSettingsCache__activate(self, action):
        keys = ["app-ui", "launcher-geometry"]
        keys.append("search-columns-%s" % (api.get_current_user(api.get_default_store()).username,))

        for key in keys:
            try:
                api.user_settings.remove(key)
            except KeyError:
                pass
开发者ID:rosalin,项目名称:stoq,代码行数:9,代码来源:shellwindow.py

示例9: __init__

    def __init__(self, columns, tree=False, restore_name=None):
        self._restore_name = restore_name
        self._settings_key = 'search-columns-%s' % (
            api.get_current_user(api.get_default_store()).username, )
        self._columns = self.restore_columns(columns)

        SearchSlaveDelegate.__init__(self, self._columns, tree=tree)
        self.search.connect("search-completed",
                            self._on_search__search_completed)
开发者ID:romaia,项目名称:stoq,代码行数:9,代码来源:search.py

示例10: restore

def restore(restore_dir, user_hash, time=None):
    global _user_hash
    _user_hash = user_hash

    with _mock_environ():
        config = get_config()

        backup_key = config.get('Backup', 'key')
        if not backup_key:
            raise ValueError("No backup key set on configuration file")
        os.environ.setdefault('PASSPHRASE', backup_key)

        # Close the main store so the database can be dropped after this
        api.get_default_store().rollback(close=True)
        sys.argv.extend([_duplicity_bin, 'restore',
                         _webservice_url, restore_dir])
        if time is not None:
            sys.argv.extend(['--time', time])

        _duplicity_main.main()
开发者ID:turbonetlink,项目名称:stoq-server,代码行数:20,代码来源:backup.py

示例11: _migrate_from_pickle

 def _migrate_from_pickle(self):
     username = api.get_current_user(api.get_default_store()).username
     filename = os.path.join(get_application_dir(), 'columns-%s' % username,
                             self._restore_name + '.pickle')
     log.info("Migrating columns from pickle: %s" % (filename, ))
     try:
         with open(filename) as fd:
             import cPickle
             return cPickle.load(fd)
     except Exception, e:
         log.info("Exception while migrating: %r" % (e, ))
         return {}
开发者ID:romaia,项目名称:stoq,代码行数:12,代码来源:search.py

示例12: validate_confirm

 def validate_confirm(self):
     if not self.edit_mode:
         settings = DeviceSettings.get_by_station_and_type(
             store=api.get_default_store(), station=self.model.station.id, type=self.model.type
         )
         if settings:
             self.station.set_invalid(
                 _(u'A %s already exists for station "%s"')
                 % (self.model.get_device_type_name(), self.model.station.name)
             )
             return False
     return True
开发者ID:romaia,项目名称:stoq,代码行数:12,代码来源:deviceseditor.py

示例13: validate_confirm

    def validate_confirm(self):
        settings = DeviceSettings.get_by_station_and_type(
            store=api.get_default_store(),
            station=self.model.station.id,
            type=self.model.type,
            exclude=self.model)
        if settings and self.is_active_button.get_active():
            warning(_(u"An active %s already exists for station \"%s\"") % (
                    self.model.device_type_name,
                    self.model.station_name))
            return False

        return True
开发者ID:hackedbellini,项目名称:stoq,代码行数:13,代码来源:deviceseditor.py

示例14: setup_widgets

    def setup_widgets(self):
        self.get_toplevel().set_size_request(*self.size)
        self.notification_label.set_text('')
        self.notification_label.set_color('black')

        if api.sysparam(api.get_default_store()).DISABLE_COOKIES:
            self.remember.hide()
            self.remember.set_active(False)

        gtkimage = gtk.Image()
        gtkimage.set_from_pixbuf(render_logo_pixbuf('login'))
        self.logo_container.add(gtkimage)
        self.logo_container.show_all()
开发者ID:leandrorchaves,项目名称:stoq,代码行数:13,代码来源:login.py

示例15: _get_proxy

    def _get_proxy(self):
        if self._proxy is None:
            config = get_config()
            if not config:
                raise ServerError(_('Configuration not found'))

            address = config.get('General', 'serveraddress')
            if not address:
                query = ("SELECT client_addr FROM pg_stat_activity "
                         "WHERE application_name LIKE ? AND "
                         "      datname = ? "
                         "LIMIT 1")
                params = [u'stoqserver%', str(db_settings.dbname)]
                res = api.get_default_store().execute(query, params=params).get_one()

                if res:
                    # When stoqserver is located in another machine
                    if res[0] not in ['127.0.0.1', '::1', '', None]:
                        address = res[0]
                    else:
                        # XXX: For now we only support ipv4
                        # XXX: If the client_addr is NULL, then stoqserver is
                        # connected using the unix socket, which means that he
                        # is in the same ip as the postgresql
                        address = db_settings.address
                        if not address:
                            address = 'localhost'
                else:
                    address = None

            if not address:
                raise ServerError(_("Stoq server not found"))

            port = config.get('General', 'serverport') or 6970
            url = 'http://%s:%s/XMLRPC' % (address, port)

            default_timeout = socket.getdefaulttimeout()
            socket.setdefaulttimeout(self._timeout)
            self._proxy = xmlrpc.client.ServerProxy(url, allow_none=True)
            socket.setdefaulttimeout(default_timeout)

        try:
            retval = self._proxy.ping()
        except (Exception, AttributeError):
            self._proxy = None
            raise

        if not retval:
            raise ServerError(_("Server not responding to pings"))

        return self._proxy
开发者ID:hackedbellini,项目名称:stoq,代码行数:51,代码来源:server.py


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