本文整理汇总了Python中core.model.ConfigurationSetting.for_library方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigurationSetting.for_library方法的具体用法?Python ConfigurationSetting.for_library怎么用?Python ConfigurationSetting.for_library使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.model.ConfigurationSetting
的用法示例。
在下文中一共展示了ConfigurationSetting.for_library方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_libraries_get_with_multiple_libraries
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library [as 别名]
def test_libraries_get_with_multiple_libraries(self):
# Delete any existing library created by the controller test setup.
library = get_one(self._db, Library)
if library:
self._db.delete(library)
l1 = self._library("Library 1", "L1")
l2 = self._library("Library 2", "L2")
l3 = self._library("Library 3", "L3")
# L2 has some additional library-wide settings.
ConfigurationSetting.for_library(Configuration.FEATURED_LANE_SIZE, l2).value = 5
ConfigurationSetting.for_library(
Configuration.DEFAULT_FACET_KEY_PREFIX + FacetConstants.ORDER_FACET_GROUP_NAME, l2
).value = FacetConstants.ORDER_RANDOM
ConfigurationSetting.for_library(
Configuration.ENABLED_FACETS_KEY_PREFIX + FacetConstants.ORDER_FACET_GROUP_NAME, l2
).value = json.dumps([FacetConstants.ORDER_TITLE, FacetConstants.ORDER_RANDOM])
ConfigurationSetting.for_library(
Configuration.LARGE_COLLECTION_LANGUAGES, l2
).value = json.dumps(["French"])
# The admin only has access to L1 and L2.
self.admin.remove_role(AdminRole.SYSTEM_ADMIN)
self.admin.add_role(AdminRole.LIBRARIAN, l1)
self.admin.add_role(AdminRole.LIBRARY_MANAGER, l2)
with self.request_context_with_admin("/"):
response = self.manager.admin_library_settings_controller.process_get()
libraries = response.get("libraries")
eq_(2, len(libraries))
eq_(l1.uuid, libraries[0].get("uuid"))
eq_(l2.uuid, libraries[1].get("uuid"))
eq_(l1.name, libraries[0].get("name"))
eq_(l2.name, libraries[1].get("name"))
eq_(l1.short_name, libraries[0].get("short_name"))
eq_(l2.short_name, libraries[1].get("short_name"))
eq_({}, libraries[0].get("settings"))
eq_(4, len(libraries[1].get("settings").keys()))
settings = libraries[1].get("settings")
eq_("5", settings.get(Configuration.FEATURED_LANE_SIZE))
eq_(FacetConstants.ORDER_RANDOM,
settings.get(Configuration.DEFAULT_FACET_KEY_PREFIX + FacetConstants.ORDER_FACET_GROUP_NAME))
eq_([FacetConstants.ORDER_TITLE, FacetConstants.ORDER_RANDOM],
settings.get(Configuration.ENABLED_FACETS_KEY_PREFIX + FacetConstants.ORDER_FACET_GROUP_NAME))
eq_(["French"], settings.get(Configuration.LARGE_COLLECTION_LANGUAGES))
示例2: test_default_notification_email_address
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library [as 别名]
def test_default_notification_email_address(self):
"""Test the ability of the Overdrive API to detect an email address
previously given by the patron to Overdrive for the purpose of
notifications.
"""
ignore, patron_with_email = self.sample_json(
"patron_info.json"
)
self.api.queue_response(200, content=patron_with_email)
patron = self._patron()
# If the patron has used a particular email address to put
# books on hold, use that email address, not the site default.
ConfigurationSetting.for_library(
Configuration.DEFAULT_NOTIFICATION_EMAIL_ADDRESS,
self._default_library).value = "[email protected]"
eq_("[email protected]",
self.api.default_notification_email_address(patron, 'pin'))
# If the patron has never before put an Overdrive book on
# hold, their JSON object has no `lastHoldEmail` key. In this
# case we use the site default.
patron_with_no_email = dict(patron_with_email)
del patron_with_no_email['lastHoldEmail']
self.api.queue_response(200, content=patron_with_no_email)
eq_("[email protected]",
self.api.default_notification_email_address(patron, 'pin'))
# If there's an error getting the information, use the
# site default.
self.api.queue_response(404)
eq_("[email protected]",
self.api.default_notification_email_address(patron, 'pin'))
示例3: test_borrow_with_outstanding_fines
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library [as 别名]
def test_borrow_with_outstanding_fines(self):
# This checkout would succeed...
now = datetime.now()
loaninfo = LoanInfo(
self.pool.collection, self.pool.data_source,
self.pool.identifier.type,
self.pool.identifier.identifier,
now, now + timedelta(seconds=3600),
)
self.remote.queue_checkout(loaninfo)
# ...except the patron has too many fines.
old_fines = self.patron.fines
self.patron.fines = 1000
setting = ConfigurationSetting.for_library(
Configuration.MAX_OUTSTANDING_FINES,
self._default_library
)
setting.value = "$0.50"
assert_raises(OutstandingFines, self.borrow)
# Test the case where any amount of fines are too much.
setting.value = "$0"
assert_raises(OutstandingFines, self.borrow)
# Remove the fine policy, and borrow succeeds.
setting.value = None
loan, i1, i2 = self.borrow()
assert isinstance(loan, Loan)
self.patron.fines = old_fines
示例4: max_outstanding_fines
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library [as 别名]
def max_outstanding_fines(cls, library):
max_fines = ConfigurationSetting.for_library(
cls.MAX_OUTSTANDING_FINES, library
)
if max_fines.value is None:
return None
return MoneyUtility.parse(max_fines.value)
示例5: process_get
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library [as 别名]
def process_get(self):
libraries = []
for library in self._db.query(Library).order_by(Library.name):
# Only include libraries this admin has librarian access to.
if not flask.request.admin or not flask.request.admin.is_librarian(library):
continue
settings = dict()
for setting in Configuration.LIBRARY_SETTINGS:
if setting.get("type") == "list":
value = ConfigurationSetting.for_library(setting.get("key"), library).json_value
if value and setting.get("format") == "geographic":
value = self.get_extra_geographic_information(value)
else:
value = self.current_value(setting, library)
if value:
settings[setting.get("key")] = value
libraries += [dict(
uuid=library.uuid,
name=library.name,
short_name=library.short_name,
settings=settings,
)]
return dict(libraries=libraries, settings=Configuration.LIBRARY_SETTINGS)
示例6: test_libraries_get_with_geographic_info
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library [as 别名]
def test_libraries_get_with_geographic_info(self):
# Delete any existing library created by the controller test setup.
library = get_one(self._db, Library)
if library:
self._db.delete(library)
test_library = self._library("Library 1", "L1")
ConfigurationSetting.for_library(
Configuration.LIBRARY_FOCUS_AREA, test_library
).value = '{"CA": ["N3L"], "US": ["11235"]}'
ConfigurationSetting.for_library(
Configuration.LIBRARY_SERVICE_AREA, test_library
).value = '{"CA": ["J2S"], "US": ["31415"]}'
with self.request_context_with_admin("/"):
response = self.manager.admin_library_settings_controller.process_get()
library_settings = response.get("libraries")[0].get("settings")
eq_(library_settings.get("focus_area"), {u'CA': [{u'N3L': u'Paris, Ontario'}], u'US': [{u'11235': u'Brooklyn, NY'}]})
eq_(library_settings.get("service_area"), {u'CA': [{u'J2S': u'Saint-Hyacinthe Southwest, Quebec'}], u'US': [{u'31415': u'Savannah, GA'}]})
示例7: _email_uri_with_fallback
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library [as 别名]
def _email_uri_with_fallback(cls, library, key):
"""Try to find a certain email address configured for the given
purpose. If not available, use the general patron support
address.
:param key: The specific email address to look for.
"""
for setting in [key, Configuration.HELP_EMAIL]:
value = ConfigurationSetting.for_library(setting, library).value
if not value:
continue
return cls._as_mailto(value)
示例8: setup
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library [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)
示例9: estimate_language_collections_for_library
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library [as 别名]
def estimate_language_collections_for_library(cls, library):
"""Guess at appropriate values for the given library for
LARGE_COLLECTION_LANGUAGES, SMALL_COLLECTION_LANGUAGES, and
TINY_COLLECTION_LANGUAGES. Set configuration values
appropriately, overriding any previous values.
"""
holdings = library.estimated_holdings_by_language()
large, small, tiny = cls.classify_holdings(holdings)
for setting, value in (
(cls.LARGE_COLLECTION_LANGUAGES, large),
(cls.SMALL_COLLECTION_LANGUAGES, small),
(cls.TINY_COLLECTION_LANGUAGES, tiny),
):
ConfigurationSetting.for_library(
setting, library).value = json.dumps(value)
示例10: help_uris
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library [as 别名]
def help_uris(cls, library):
"""Find all the URIs that might help patrons get help from
this library.
:yield: A sequence of 2-tuples (media type, URL)
"""
for name in cls.HELP_LINKS:
setting = ConfigurationSetting.for_library(name, library)
value = setting.value
if not value:
continue
type = None
if name == cls.HELP_EMAIL:
value = cls._as_mailto(value)
if name == cls.HELP_WEB:
type = 'text/html'
yield type, value
示例11: library_configuration_settings
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library [as 别名]
def library_configuration_settings(self, library, validator):
for setting in Configuration.LIBRARY_SETTINGS:
if setting.get("format") == "geographic":
locations = validator.validate_geographic_areas(self.list_setting(setting), self._db)
if isinstance(locations, ProblemDetail):
return locations
value = locations or self.current_value(setting, library)
elif setting.get("type") == "list":
value = self.list_setting(setting) or self.current_value(setting, library)
if setting.get("format") == "language-code":
value = json.dumps([LanguageCodes.string_to_alpha_3(language) for language in json.loads(value)])
elif setting.get("type") == "image":
value = self.image_setting(setting) or self.current_value(setting, library)
else:
default = setting.get('default')
value = flask.request.form.get(setting['key'], default)
ConfigurationSetting.for_library(setting['key'], library).value = value
示例12: _collection_languages
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library [as 别名]
def _collection_languages(cls, library, key):
"""Look up a list of languages in a library configuration.
If the value is not set, estimate a value (and all related
values) by looking at the library's collection.
"""
setting = ConfigurationSetting.for_library(key, library)
value = None
try:
value = setting.json_value
if not isinstance(value, list):
value = None
except (TypeError, ValueError):
pass
if value is None:
# We have no value or a bad value. Estimate a better value.
cls.estimate_language_collections_for_library(library)
value = setting.json_value
return value
示例13: test__create_registration_payload
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library [as 别名]
def test__create_registration_payload(self):
m = self.registration._create_registration_payload
# Mock url_for to create good-looking callback URLs.
def url_for(controller, library_short_name):
return "http://server/%s/%s" % (library_short_name, controller)
# First, test with no configuration contact configured for the
# library.
stage = object()
expect_url = url_for(
"authentication_document", self.registration.library.short_name
)
expect_payload = dict(url=expect_url, stage=stage)
eq_(expect_payload, m(url_for, stage))
# If a contact is configured, it shows up in the payload.
contact = "mailto:[email protected]"
ConfigurationSetting.for_library(
Configuration.CONFIGURATION_CONTACT_EMAIL,
self.registration.library,
).value=contact
expect_payload['contact'] = contact
eq_(expect_payload, m(url_for, stage))
示例14: push
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library [as 别名]
def push(self, stage, url_for, catalog_url=None, do_get=HTTP.debuggable_get,
do_post=HTTP.debuggable_post):
"""Attempt to register a library with a RemoteRegistry.
NOTE: This method is designed to be used in a
controller. Other callers may use this method, but they must be
able to render a ProblemDetail when there's a failure.
NOTE: The application server must be running when this method
is called, because part of the OPDS Directory Registration
Protocol is the remote server retrieving the library's
Authentication For OPDS document.
:param stage: Either TESTING_STAGE or PRODUCTION_STAGE
:param url_for: Flask url_for() or equivalent, used to generate URLs
for the application server.
:param do_get: Mockable method to make a GET request.
:param do_post: Mockable method to make a POST request.
:return: A ProblemDetail if there was a problem; otherwise True.
"""
# Assume that the registration will fail.
#
# TODO: If a registration has previously succeeded, failure to
# re-register probably means a maintenance of the status quo,
# not a change of success to failure. But we don't have any way
# of being sure.
self.status_field.value = self.FAILURE_STATUS
if stage not in self.VALID_REGISTRATION_STAGES:
return INVALID_INPUT.detailed(
_("%r is not a valid registration stage") % stage
)
# Verify that a public/private key pair exists for this library.
# This key pair is created during initialization of the
# LibraryAuthenticator, so this should always be present.
#
# We can't just create the key pair here because the process
# of pushing a registration involves the other site making a
# request to the circulation manager. This means the key pair
# needs to be committed to the database _before_ the push
# attempt starts.
key_pair = ConfigurationSetting.for_library(
Configuration.KEY_PAIR, self.library).json_value
if not key_pair:
# TODO: We could create the key pair _here_. The database
# session will be committed at the end of this request,
# so the push attempt would succeed if repeated.
return SHARED_SECRET_DECRYPTION_ERROR.detailed(
_("Library %(library)s has no key pair set.",
library=self.library.short_name)
)
public_key, private_key = key_pair
cipher = Configuration.cipher(private_key)
# Before we can start the registration protocol, we must fetch
# the remote catalog's URL and extract the link to the
# registration resource that kicks off the protocol.
catalog_url = catalog_url or self.integration.url
response = do_get(catalog_url)
if isinstance(response, ProblemDetail):
return response
result = self._extract_catalog_information(response)
if isinstance(result, ProblemDetail):
return result
register_url, vendor_id = result
# Store the vendor id as a ConfigurationSetting on the integration
# -- it'll be the same value for all libraries.
if vendor_id:
ConfigurationSetting.for_externalintegration(
AuthdataUtility.VENDOR_ID_KEY, self.integration
).value = vendor_id
# Build the document we'll be sending to the registration URL.
payload = self._create_registration_payload(url_for, stage)
if isinstance(payload, ProblemDetail):
return payload
headers = self._create_registration_headers()
if isinstance(headers, ProblemDetail):
return headers
# Send the document.
response = self._send_registration_request(
register_url, headers, payload, do_post
)
if isinstance(response, ProblemDetail):
return response
catalog = json.loads(response.content)
# Process the result.
return self._process_registration_result(catalog, cipher, stage)
示例15: val
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library [as 别名]
def val(x):
return ConfigurationSetting.for_library(x, library).value