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


Python ConfigurationSetting.sitewide方法代码示例

本文整理汇总了Python中core.model.ConfigurationSetting.sitewide方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigurationSetting.sitewide方法的具体用法?Python ConfigurationSetting.sitewide怎么用?Python ConfigurationSetting.sitewide使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在core.model.ConfigurationSetting的用法示例。


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

示例1: test_sitewide_settings_get

# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import sitewide [as 别名]
    def test_sitewide_settings_get(self):
        with self.request_context_with_admin("/"):
            response = self.manager.admin_sitewide_configuration_settings_controller.process_get()
            settings = response.get("settings")
            all_settings = response.get("all_settings")

            eq_([], settings)
            keys = [s.get("key") for s in all_settings]
            assert AcquisitionFeed.GROUPED_MAX_AGE_POLICY in keys
            assert AcquisitionFeed.NONGROUPED_MAX_AGE_POLICY in keys
            assert Configuration.SECRET_KEY in keys

        ConfigurationSetting.sitewide(self._db, AcquisitionFeed.GROUPED_MAX_AGE_POLICY).value = 0
        ConfigurationSetting.sitewide(self._db, Configuration.SECRET_KEY).value = "secret"
        self._db.flush()

        with self.request_context_with_admin("/"):
            response = self.manager.admin_sitewide_configuration_settings_controller.process_get()
            settings = response.get("settings")
            all_settings = response.get("all_settings")

            eq_(2, len(settings))
            settings_by_key = { s.get("key") : s.get("value") for s in settings }
            eq_("0", settings_by_key.get(AcquisitionFeed.GROUPED_MAX_AGE_POLICY))
            eq_("secret", settings_by_key.get(Configuration.SECRET_KEY))
            keys = [s.get("key") for s in all_settings]
            assert AcquisitionFeed.GROUPED_MAX_AGE_POLICY in keys
            assert AcquisitionFeed.NONGROUPED_MAX_AGE_POLICY in keys
            assert Configuration.SECRET_KEY in keys

            self.admin.remove_role(AdminRole.SYSTEM_ADMIN)
            self._db.flush()
            assert_raises(AdminNotAuthorized,
                          self.manager.admin_sitewide_configuration_settings_controller.process_get)
开发者ID:NYPL-Simplified,项目名称:circulation,代码行数:36,代码来源:test_sitewide_settings.py

示例2: process_post

# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import sitewide [as 别名]
    def process_post(self):
        self.require_system_admin()
        setting = ConfigurationSetting.sitewide(self._db, flask.request.form.get("key"))

        error = self.validate_form_fields(setting, flask.request.form.keys())
        if error:
            return error

        setting = ConfigurationSetting.sitewide(self._db, flask.request.form.get("key"))
        setting.value = flask.request.form.get("value")
        return Response(unicode(setting.key), 200)
开发者ID:NYPL-Simplified,项目名称:circulation,代码行数:13,代码来源:sitewide_settings.py

示例3: do_run

# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import sitewide [as 别名]
    def do_run(self, cmd_args=None, in_unit_test=False):
        parser = self.arg_parser(self._db)
        parsed = self.parse_command_line(self._db, cmd_args)

        url = parsed.registry_url
        registry = RemoteRegistry.for_protocol_goal_and_url(
            self._db, self.PROTOCOL, self.GOAL, url
        )
        stage = parsed.stage

        # Set up an application context so we have access to url_for.
        from api.app import app
        app.manager = CirculationManager(self._db, testing=in_unit_test)
        base_url = ConfigurationSetting.sitewide(
            self._db, Configuration.BASE_URL_KEY
        ).value
        ctx = app.test_request_context(base_url=base_url)
        ctx.push()
        for library in parsed.libraries:
            registration = Registration(registry, library)
            library_stage = stage or registration.stage_field.value
            self.process_library(
                registration, library_stage, app.manager.url_for
            )
        ctx.pop()

        # For testing purposes, return the application object that was
        # created.
        return app
开发者ID:NYPL-Simplified,项目名称:circulation,代码行数:31,代码来源:registry.py

示例4: opds_catalog

# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import sitewide [as 别名]
    def opds_catalog(self):
        url = ConfigurationSetting.sitewide(self._db, Configuration.BASE_URL_KEY).value_or_default(request.url)
        catalog = dict(
            id=url,
            title='Library Simplified Metadata Wrangler',
        )

        catalog['links'] = [
            {
                "rel": "register",
                "href": "/register",
                "type": "application/opds+json;profile=https://librarysimplified.org/rel/profile/metadata-service",
                "title": "Register your OPDS server with this metadata service"
            },
            {
                "rel": "http://librarysimplified.org/rel/metadata/lookup",
                "href": "/lookup{?data_source,urn*}",
                "type": "application/atom+xml;profile=opds-catalog",
                "title": "Look up metadata about one or more specific items",
                "templated": "true"
            },
            {
                "rel": "http://opds-spec.org/sort/new",
                "href": "/{collection_metadata_identifier}/updates{?data_source}",
                "type": "application/atom+xml;profile=opds-catalog",
                "title": "Recent changes to one of your tracked collections.",
                "templated": "true"
            },
            {
                "rel": "http://librarysimplified.org/rel/metadata/collection-add",
                "href": "/{collection_metadata_identifier}/add{?data_source,urn*}",
                "title": "Add items to one of your tracked collections.",
                "templated": "true"
            },
            {
                "rel": "http://librarysimplified.org/rel/metadata/collection-remove",
                "href": "/{collection_metadata_identifier}/remove{?data_source,urn*}",
                "title": "Remove items from one of your tracked collections.",
                "templated": "true"
            },
            {
                "rel": "http://librarysimplified.org/rel/metadata/collection-metadata-needed",
                "href": "/{collection_metadata_identifier}/metadata_needed",
                "title": "Get items in your collection for which the metadata wrangler needs more information to process.",
                "templated": "true"
            },
            {
                "rel": "http://librarysimplified.org/rel/metadata/resolve-name",
                "href": "/canonical-author-name{?urn,display_name}",
                "type": "text/plain",
                "title": "Look up an author's canonical sort name",
                "templated": "true"
            }
        ]

        return make_response(
            json.dumps(catalog), HTTP_OK,
            {'Content-Type' : OPDS_2_MEDIA_TYPE }
        )
开发者ID:NYPL-Simplified,项目名称:metadata_wrangler,代码行数:61,代码来源:controller.py

示例5: test_do_run

# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import sitewide [as 别名]
    def test_do_run(self):

        class Mock(LibraryRegistrationScript):
            processed = []
            def process_library(self, *args):
                self.processed.append(args)

        script = Mock(self._db)

        base_url_setting = ConfigurationSetting.sitewide(
            self._db, Configuration.BASE_URL_KEY
        )
        base_url_setting.value = u'http://test-circulation-manager/'

        library = self._default_library
        library2 = self._library()

        cmd_args = [library.short_name, "--stage=testing",
                    "--registry-url=http://registry/"]
        app = script.do_run(cmd_args=cmd_args, in_unit_test=True)

        # One library was processed.
        (registration, stage, url_for) = script.processed.pop()
        eq_([], script.processed)
        eq_(library, registration.library)
        eq_(Registration.TESTING_STAGE, stage)

        # A new ExternalIntegration was created for the newly defined
        # registry at http://registry/.
        eq_("http://registry/", registration.integration.url)

        # An application environment was created and the url_for
        # implementation for that environment was passed into
        # process_library.
        eq_(url_for, app.manager.url_for)

        # Let's say the other library was earlier registered in production.
        registration_2 = Registration(registration.registry, library2)
        registration_2.stage_field.value = Registration.PRODUCTION_STAGE

        # Now run the script again without specifying a particular
        # library or the --stage argument.
        app = script.do_run(cmd_args=[], in_unit_test=True)

        # Every library was processed.
        eq_(set([library, library2]),
            set([x[0].library for x in script.processed]))

        for i in script.processed:
            # Since no stage was provided, each library was registered
            # using the stage already associated with it.
            eq_(i[0].stage_field.value, i[1])

            # Every library was registered with the default
            # library registry.
            eq_(
                RemoteRegistry.DEFAULT_LIBRARY_REGISTRY_URL,
                x[0].integration.url
            )
开发者ID:NYPL-Simplified,项目名称:circulation,代码行数:61,代码来源:test_registry.py

示例6: setup

# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import sitewide [as 别名]
 def setup(self):
     super(TestLaneScript, self).setup()
     base_url_setting = ConfigurationSetting.sitewide(
         self._db, Configuration.BASE_URL_KEY)
     base_url_setting.value = u'http://test-circulation-manager/'
     for k, v in [
             (Configuration.LARGE_COLLECTION_LANGUAGES, []),
             (Configuration.SMALL_COLLECTION_LANGUAGES, []),
             (Configuration.TINY_COLLECTION_LANGUAGES, ['eng', 'fre'])
     ]:
         ConfigurationSetting.for_library(
             k, self._default_library).value = json.dumps(v)
开发者ID:NYPL-Simplified,项目名称:circulation,代码行数:14,代码来源:test_scripts.py

示例7: test_sitewide_settings_post_create

# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import sitewide [as 别名]
    def test_sitewide_settings_post_create(self):
        with self.request_context_with_admin("/", method="POST"):
            flask.request.form = MultiDict([
                ("key", AcquisitionFeed.GROUPED_MAX_AGE_POLICY),
                ("value", "10"),
            ])
            response = self.manager.admin_sitewide_configuration_settings_controller.process_post()
            eq_(response.status_code, 200)

        # The setting was created.
        setting = ConfigurationSetting.sitewide(self._db, AcquisitionFeed.GROUPED_MAX_AGE_POLICY)
        eq_(setting.key, response.response[0])
        eq_("10", setting.value)
开发者ID:NYPL-Simplified,项目名称:circulation,代码行数:15,代码来源:test_sitewide_settings.py

示例8: process_get

# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import sitewide [as 别名]
    def process_get(self):
        self.require_system_admin()
        sitewide_settings = Configuration.SITEWIDE_SETTINGS
        settings = []

        for s in sitewide_settings:
            setting = ConfigurationSetting.sitewide(self._db, s.get("key"))
            if setting.value:
                settings += [{ "key": setting.key, "value": setting.value }]

        return dict(
            settings=settings,
            all_settings=sitewide_settings,
        )
开发者ID:NYPL-Simplified,项目名称:circulation,代码行数:16,代码来源:sitewide_settings.py

示例9: test_sitewide_setting_delete

# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import sitewide [as 别名]
    def test_sitewide_setting_delete(self):
        setting = ConfigurationSetting.sitewide(self._db, AcquisitionFeed.GROUPED_MAX_AGE_POLICY)
        setting.value = "10"

        with self.request_context_with_admin("/", method="DELETE"):
            self.admin.remove_role(AdminRole.SYSTEM_ADMIN)
            assert_raises(AdminNotAuthorized,
                          self.manager.admin_sitewide_configuration_settings_controller.process_delete,
                          setting.key)

            self.admin.add_role(AdminRole.SYSTEM_ADMIN)
            response = self.manager.admin_sitewide_configuration_settings_controller.process_delete(setting.key)
            eq_(response.status_code, 200)

        eq_(None, setting.value)
开发者ID:NYPL-Simplified,项目名称:circulation,代码行数:17,代码来源:test_sitewide_settings.py

示例10: edition_permalink

# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import sitewide [as 别名]
    def edition_permalink(self, edition):
        """Gets a unique URL for the target Work"""

        base_url = ConfigurationSetting.sitewide(self._db, Configuration.BASE_URL_KEY).value
        scheme, host = urlparse(base_url)[0:2]
        base_url = '://'.join([scheme, host])

        urn = edition.primary_identifier.urn
        initialization_value = os.environ.get('AUTOINITIALIZE')
        try:
            os.environ['AUTOINITIALIZE'] = 'False'
            from app import app
            with app.test_request_context(base_url=base_url):
                permalink = url_for('lookup', urn=urn, _external=True)

        finally:
            os.unsetenv('AUTOINITIALIZE')
            if initialization_value:
                os.environ['AUTOINITIALIZE'] = initialization_value

        return permalink
开发者ID:NYPL-Simplified,项目名称:content_server,代码行数:23,代码来源:bibblio.py

示例11: process_delete

# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import sitewide [as 别名]
 def process_delete(self, key):
     self.require_system_admin()
     setting = ConfigurationSetting.sitewide(self._db, key)
     setting.value = None
     return Response(unicode(_("Deleted")), 200)
开发者ID:NYPL-Simplified,项目名称:circulation,代码行数:7,代码来源:sitewide_settings.py

示例12: EI

# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import sitewide [as 别名]
        wrangler = EI(
            name=EI.METADATA_WRANGLER,
            protocol=EI.METADATA_WRANGLER,
            goal=EI.METADATA_GOAL
        )
        _db.add(wrangler)
        wrangler.url = metadata_wrangler_conf.get('url')
        wrangler.username = metadata_wrangler_conf.get('client_id')
        wrangler.password = metadata_wrangler_conf.get('client_secret')
        log_import(wrangler)

    # Get the base url.
    content_server_conf = Configuration.integration('Content Server')
    if content_server_conf:
        url = content_server_conf.get('url')
        setting = ConfigurationSetting.sitewide(_db, Configuration.BASE_URL_KEY)
        setting.value = url
        log_import(setting)

    # Copy facet configuration to the library.
    facet_policy = Configuration.policy("facets", default={})

    default_enabled = Configuration.DEFAULT_ENABLED_FACETS
    enabled = facet_policy.get("enabled", default_enabled)
    for k, v in enabled.items():
        library.enabled_facets_setting(unicode(k)).value = unicode(json.dumps(v))

    default_facets = Configuration.DEFAULT_FACET
    default = facet_policy.get("default", default_facets)
    for k, v in default.items():
        library.default_facet_setting(unicode(k)).value = unicode(v)
开发者ID:NYPL-Simplified,项目名称:content_server,代码行数:33,代码来源:20170714-1-move-third-party-config-to-external-integrations.py

示例13: log_import

# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import sitewide [as 别名]
log = logging.getLogger(name="Circulation manager configuration import")

def log_import(integration_or_setting):
    log.info("CREATED: %r" % integration_or_setting)

try:
    Configuration.load()
    _db = production_session()
    LIBRARIES = _db.query(Library).all()

    # Import Circulation Manager base url.
    circ_manager_conf = Configuration.integration('Circulation Manager')
    if circ_manager_conf:
        url = circ_manager_conf.get('url')
        if url:
            setting = ConfigurationSetting.sitewide(_db, Configuration.BASE_URL_KEY)
            setting.value = unicode(url)
            log_import(setting)

    # Import Metadata Wrangler configuration.
    metadata_wrangler_conf = Configuration.integration('Metadata Wrangler')

    if metadata_wrangler_conf:
        integration = EI(protocol=EI.METADATA_WRANGLER, goal=EI.METADATA_GOAL)
        _db.add(integration)

        integration.url = metadata_wrangler_conf.get('url')
        integration.username = metadata_wrangler_conf.get('client_id')
        integration.password = metadata_wrangler_conf.get('client_secret')

        log_import(integration)
开发者ID:NYPL-Simplified,项目名称:circulation,代码行数:33,代码来源:20170713-19-move-third-party-config-to-external-integrations.py

示例14: EI

# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import sitewide [as 别名]
        shadowcat = EI(
            name=EI.NYPL_SHADOWCAT,
            protocol=EI.NYPL_SHADOWCAT,
            goal=EI.METADATA_GOAL
        )
        _db.add(shadowcat)
        shadowcat.url = shadowcat_conf.get('url')
        log_import(shadowcat)

    content_cafe_conf = Configuration.integration('Content Cafe')
    if content_cafe_conf:
        content_cafe = EI(
            name=EI.CONTENT_CAFE,
            protocol=EI.CONTENT_CAFE,
            goal=EI.METADATA_GOAL
        )
        _db.add(content_cafe)

        content_cafe.username = content_cafe_conf.get('username')
        content_cafe.password = content_cafe_conf.get('password')

    metadata_wrangler_conf = Configuration.integration('Metadata Wrangler')
    if metadata_wrangler_conf:
        url = metadata_wrangler_conf.get('url')
        ConfigurationSetting.sitewide(_db, Configuration.BASE_URL_KEY).value = url


finally:
    _db.commit()
    _db.close()
开发者ID:NYPL-Simplified,项目名称:metadata_wrangler,代码行数:32,代码来源:20170728-move-third-party-config-to-external-integrations.py


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