本文整理匯總了Python中pylons.config.get方法的典型用法代碼示例。如果您正苦於以下問題:Python config.get方法的具體用法?Python config.get怎麽用?Python config.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pylons.config
的用法示例。
在下文中一共展示了config.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_dataset_doi_admin_sysadmin_verify_xml
# 需要導入模塊: from pylons import config [as 別名]
# 或者: from pylons.config import get [as 別名]
def test_dataset_doi_admin_sysadmin_verify_xml(self):
model.repo.rebuild_db()
dataset = factories.Dataset(author='test author')
sysadmin = factories.Sysadmin()
env = {'REMOTE_USER': sysadmin['name'].encode('ascii')}
url = url_for(
controller='ckanext.ands.controller:DatasetDoiController', action='dataset_doi_admin',
id=dataset['name'])
mock_response = Mock(content=json.dumps(dict(response=dict(responsecode='MT001', doi='testdoi'))))
mock_post = Mock(return_value=mock_response)
response = self.app.get(url, extra_environ=env)
form = response.forms['dataset-doi']
assert_equal(sorted(form.fields.keys()), ['save', 'xml'])
with patch.object(requests, 'post', new=mock_post):
response = form.submit('submit', extra_environ=env)
# Don't bother checking the mocks, other tests do this
response = response.follow(extra_environ=env)
# Shouldn't appear as already created
response.mustcontain(no='Approve DOI')
response.mustcontain(no='Request DOI')
response.mustcontain('Cite this as')
示例2: build_xml
# 需要導入模塊: from pylons import config [as 別名]
# 或者: from pylons.config import get [as 別名]
def build_xml(dataset):
author = dataset['author']
publisher = config['ckanext.ands.publisher']
# Dev prefix default
doi_prefix = config.get('ckanext.ands.doi_prefix', '10.5072/')
# TODO what should this be?
ands_client_id = config['ckanext.ands.client_id']
namespaces = {
'xsi': "http://www.w3.org/2001/XMLSchema-instance",
None: "http://datacite.org/schema/kernel-3",
}
Root = ElementMaker(
nsmap=namespaces
)
E = ElementMaker()
xml = Root.resource(
E.identifier(doi_prefix + ands_client_id, identifierType="DOI"),
E.creators(E.creator(E.creatorName(author))),
E.titles(E.title(dataset['title'])),
E.publisher(publisher),
E.publicationYear("{}".format(package_get_year(dataset))),
E.language('en'),
E.resourceType('gDMCP Dataset', resourceTypeGeneral="Dataset"),
E.descriptions(E.description(dataset['notes'], descriptionType="Abstract")),
)
xml.attrib[etree.QName(namespaces['xsi'],
'schemaLocation')] = "http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd"
return etree.tostring(xml, pretty_print=True)
示例3: delete
# 需要導入模塊: from pylons import config [as 別名]
# 或者: from pylons.config import get [as 別名]
def delete(context, data_dict):
'''Delete a PowerView.
By default, only sysadmins can delete PowerViews. But the setting
`ckanext.powerview.allow_user_create` allows any logged in user to
delete powerviews they own.
'''
if not toolkit.asbool(config.get('ckanext.powerview.allow_user_create',
False)):
return {'success': False}
else:
user = context.get('user')
user_obj = model.User.get(user)
powerview = PowerView.get(id=data_dict['id'])
if powerview and user and powerview.created_by == user_obj.id:
return {'success': True}
return {'success': False}
示例4: _get_dict_value
# 需要導入模塊: from pylons import config [as 別名]
# 或者: from pylons.config import get [as 別名]
def _get_dict_value(self, _dict, key, default=None):
'''
Returns the value for the given key on a CKAN dict
By default a key on the root level is checked. If not found, extras
are checked, both with the key provided and with `dcat_` prepended to
support legacy fields.
If not found, returns the default value, which defaults to None
'''
if key in _dict:
return _dict[key]
for extra in _dict.get('extras', []):
if extra['key'] == key or extra['key'] == 'dcat_' + key:
return extra['value']
return default
示例5: _last_catalog_modification
# 需要導入模塊: from pylons import config [as 別名]
# 或者: from pylons.config import get [as 別名]
def _last_catalog_modification(self):
'''
Returns the date and time the catalog was last modified
To be more precise, the most recent value for `metadata_modified` on a
dataset.
Returns a dateTime string in ISO format, or None if it could not be
found.
'''
context = {
'user': toolkit.get_action('get_site_user')(
{'ignore_auth': True})['name']
}
result = toolkit.get_action('package_search')(context, {
'sort': 'metadata_modified desc',
'rows': 1,
})
if result and result.get('results'):
return result['results'][0]['metadata_modified']
return None
# Public methods for profiles to implement
示例6: update_config
# 需要導入模塊: from pylons import config [as 別名]
# 或者: from pylons.config import get [as 別名]
def update_config(self, config):
p.toolkit.add_template_directory(config, 'templates')
# Check catalog URI on startup to emit a warning if necessary
utils.catalog_uri()
# Check custom catalog endpoint
custom_endpoint = config.get(CUSTOM_ENDPOINT_CONFIG)
if custom_endpoint:
if not custom_endpoint[:1] == '/':
raise Exception(
'"{0}" should start with a backslash (/)'.format(
CUSTOM_ENDPOINT_CONFIG))
if '{_format}' not in custom_endpoint:
raise Exception(
'"{0}" should contain {{_format}}'.format(
CUSTOM_ENDPOINT_CONFIG))
# IRoutes
示例7: after_show
# 需要導入模塊: from pylons import config [as 別名]
# 或者: from pylons.config import get [as 別名]
def after_show(self, context, data_dict):
if context.get('for_view'):
field_labels = utils.field_labels()
def set_titles(object_dict):
for key, value in object_dict.iteritems():
if key in field_labels:
object_dict[field_labels[key]] = object_dict[key]
del object_dict[key]
for resource in data_dict.get('resources', []):
set_titles(resource)
for extra in data_dict.get('extras', []):
if extra['key'] in field_labels:
extra['key'] = field_labels[extra['key']]
return data_dict
示例8: dcat_catalog_search
# 需要導入模塊: from pylons import config [as 別名]
# 或者: from pylons.config import get [as 別名]
def dcat_catalog_search(context, data_dict):
toolkit.check_access('dcat_catalog_search', context, data_dict)
query = _search_ckan_datasets(context, data_dict)
dataset_dicts = query['results']
pagination_info = _pagination_info(query, data_dict)
serializer = RDFSerializer()
output = serializer.serialize_catalog({}, dataset_dicts,
_format=data_dict.get('format'),
pagination_info=pagination_info)
return output
示例9: graph_from_dataset
# 需要導入模塊: from pylons import config [as 別名]
# 或者: from pylons.config import get [as 別名]
def graph_from_dataset(self, dataset_dict):
'''
Given a CKAN dataset dict, creates a graph using the loaded profiles
The class RDFLib graph (accessible via `serializer.g`) will be updated
by the loaded profiles.
Returns the reference to the dataset, which will be an rdflib URIRef.
'''
uri_value = dataset_dict.get('uri')
if not uri_value:
for extra in dataset_dict.get('extras', []):
if extra['key'] == 'uri':
uri_value = extra['value']
break
dataset_ref = URIRef(dataset_uri(dataset_dict))
for profile_class in self._profiles:
profile = profile_class(self.g, self.compatibility_mode)
profile.graph_from_dataset(dataset_dict, dataset_ref)
return dataset_ref
示例10: test_pagination_less_results_than_page_size
# 需要導入模塊: from pylons import config [as 別名]
# 或者: from pylons.config import get [as 別名]
def test_pagination_less_results_than_page_size(self, mock_request):
mock_request.params = {}
mock_request.host_url = 'http://ckan.example.com'
mock_request.path = ''
# No page defined (defaults to 1)
query = {
'count': 12,
'results': [x for x in xrange(12)],
}
data_dict = {
'page': None
}
pagination = _pagination_info(query, data_dict)
eq_(pagination['count'], 12)
eq_(pagination['items_per_page'],
config.get('ckanext.dcat.datasets_per_page'))
eq_(pagination['current'], 'http://example.com?page=1')
eq_(pagination['first'], 'http://example.com?page=1')
eq_(pagination['last'], 'http://example.com?page=1')
assert 'next' not in pagination
assert 'previous' not in pagination
示例11: test_pagination_keeps_params
# 需要導入模塊: from pylons import config [as 別名]
# 或者: from pylons.config import get [as 別名]
def test_pagination_keeps_params(self, mock_request):
mock_request.params = {'a': 1, 'b': 2}
mock_request.host_url = 'http://ckan.example.com'
mock_request.path = '/feed/catalog.xml'
# No page defined (defaults to 1)
query = {
'count': 12,
'results': [x for x in xrange(10)],
}
data_dict = {
'page': None
}
pagination = _pagination_info(query, data_dict)
eq_(pagination['count'], 12)
eq_(pagination['items_per_page'],
config.get('ckanext.dcat.datasets_per_page'))
eq_(pagination['current'], 'http://example.com/feed/catalog.xml?a=1&b=2&page=1')
eq_(pagination['first'], 'http://example.com/feed/catalog.xml?a=1&b=2&page=1')
eq_(pagination['last'], 'http://example.com/feed/catalog.xml?a=1&b=2&page=2')
eq_(pagination['next'], 'http://example.com/feed/catalog.xml?a=1&b=2&page=2')
assert 'previous' not in pagination
示例12: test_pagination_without_site_url
# 需要導入模塊: from pylons import config [as 別名]
# 或者: from pylons.config import get [as 別名]
def test_pagination_without_site_url(self, mock_request):
mock_request.params = {}
mock_request.host_url = 'http://ckan.example.com'
mock_request.path = '/feed/catalog.xml'
# No page defined (defaults to 1)
query = {
'count': 12,
'results': [x for x in xrange(10)],
}
data_dict = {
'page': None
}
pagination = _pagination_info(query, data_dict)
eq_(pagination['count'], 12)
eq_(pagination['items_per_page'],
config.get('ckanext.dcat.datasets_per_page'))
eq_(pagination['current'], 'http://ckan.example.com/feed/catalog.xml?page=1')
eq_(pagination['first'], 'http://ckan.example.com/feed/catalog.xml?page=1')
eq_(pagination['last'], 'http://ckan.example.com/feed/catalog.xml?page=2')
eq_(pagination['next'], 'http://ckan.example.com/feed/catalog.xml?page=2')
assert 'previous' not in pagination
示例13: _collect_multilang_strings
# 需要導入模塊: from pylons import config [as 別名]
# 或者: from pylons.config import get [as 別名]
def _collect_multilang_strings(self, base_dict, key, subj, pred, loc_dict):
'''
Search for multilang Literals matching (subj, pred).
- Literals not localized will be stored as source_dict[key] -- possibly replacing the value set by the EURO parser
- Localized literals will be stored into target_dict[key][lang]
'''
for obj in self.g.objects(subj, pred):
value = obj.value
lang = obj.language
if not lang:
# force default value in dataset
base_dict[key] = value
else:
# add localized string
lang_dict = loc_dict.setdefault(key, {})
lang_dict[lang_mapping_xmllang_to_ckan.get(lang)] = value
示例14: organization_uri
# 需要導入模塊: from pylons import config [as 別名]
# 或者: from pylons.config import get [as 別名]
def organization_uri(orga_dict):
'''
Returns an URI for the organization
This will be used to uniquely reference the organization on the RDF serializations.
The value will be
`catalog_uri()` + '/organization/' + `orga_id`
Check the documentation for `catalog_uri()` for the recommended ways of
setting it.
Returns a string with the resource URI.
'''
uri = '{0}/organization/{1}'.format(catalog_uri().rstrip('/'), orga_dict.get('id', None))
return uri
示例15: update_extra_package_multilang
# 需要導入模塊: from pylons import config [as 別名]
# 或者: from pylons.config import get [as 別名]
def update_extra_package_multilang(extra, pkg_id, field, lang, field_type='extra'):
try:
from ckanext.multilang.model import PackageMultilang
except ImportError:
log.warn('DCAT-AP_IT: multilang extension not available.')
return
if extra.get('key') == field.get('name', None) and field.get('localized', False) == True:
log.debug(':::::::::::::::Localizing schema field: %r', field['name'])
f = PackageMultilang.get(pkg_id, field['name'], lang, field_type)
if f:
if extra.get('value') == '':
f.purge()
elif f.text != extra.get('value'):
# Update the localized field value for the current language
f.text = extra.get('value')
f.save()
log.info('Localized field updated successfully')
elif extra.get('value') != '':
# Create the localized field record
save_extra_package_multilang({'id': pkg_id, 'text': extra.get('value'), 'field': extra.get('key')}, lang, 'extra')