本文整理汇总了Python中ckan.plugins.toolkit.asbool方法的典型用法代码示例。如果您正苦于以下问题:Python toolkit.asbool方法的具体用法?Python toolkit.asbool怎么用?Python toolkit.asbool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ckan.plugins.toolkit
的用法示例。
在下文中一共展示了toolkit.asbool方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: group_create
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import asbool [as 别名]
def group_create(context, data_dict=None):
# Get the value of the ckan.iauthfunctions.users_can_create_groups
# setting from the CKAN config file as a string, or False if the setting
# isn't in the config file.
users_can_create_groups = config.get(
'ckan.iauthfunctions.users_can_create_groups', False)
# Convert the value from a string to a boolean.
users_can_create_groups = toolkit.asbool(users_can_create_groups)
if users_can_create_groups:
return {'success': True}
else:
return {'success': False,
'msg': 'Only sysadmins can create groups'}
示例2: show_most_popular_groups
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import asbool [as 别名]
def show_most_popular_groups():
'''Return the value of the most_popular_groups config setting.
To enable showing the most popular groups, add this line to the
[app:main] section of your CKAN config file::
ckan.example_theme.show_most_popular_groups = True
Returns ``False`` by default, if the setting is not in the config file.
:rtype: boolean
'''
value = config.get('ckan.example_theme.show_most_popular_groups', False)
value = toolkit.asbool(value)
return value
示例3: harvest_source_index_clear
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import asbool [as 别名]
def harvest_source_index_clear(context, data_dict):
'''
Clears all datasets, jobs and objects related to a harvest source, but
keeps the source itself. This is useful to clean history of long running
harvest sources to start again fresh.
:param id: the id of the harvest source to clear
:type id: string
'''
check_access('harvest_source_clear', context, data_dict)
harvest_source_id = data_dict.get('id')
source = HarvestSource.get(harvest_source_id)
if not source:
log.error('Harvest source %s does not exist', harvest_source_id)
raise NotFound('Harvest source %s does not exist' % harvest_source_id)
harvest_source_id = source.id
conn = make_connection()
query = ''' +%s:"%s" +site_id:"%s" ''' % (
'harvest_source_id', harvest_source_id, config.get('ckan.site_id'))
solr_commit = toolkit.asbool(config.get('ckan.search.solr_commit', 'true'))
if toolkit.check_ckan_version(max_version='2.5.99'):
# conn is solrpy
try:
conn.delete_query(query)
if solr_commit:
conn.commit()
except Exception, e:
log.exception(e)
raise SearchIndexError(e)
finally:
示例4: before_show
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import asbool [as 别名]
def before_show(self, resource_dict):
resource_dict[
'datastore_contains_all_records_of_source_file'] = toolkit.asbool(
resource_dict.get('datastore_contains_all_records_of_source_file'))
# IConfigurer
示例5: configure
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import asbool [as 别名]
def configure(self, config):
"""
Called upon CKAN setup, will pass current configuration dict
to the plugin to read custom options.
"""
discourse_url = config.get('discourse.url', None)
discourse_username = config.get('discourse.username', None)
discourse_count_cache_age = config.get('discourse.count_cache_age', 60)
discourse_ckan_category = config.get('discourse.ckan_category', None)
discourse_debug = asbool(config.get('discourse.debug', False))
if discourse_url is None:
log.warn("No discourse forum name is set. Please set \
'discourse.url' in your .ini!")
else:
discourse_url = discourse_url.rstrip('/') + '/'
if discourse_ckan_category is None:
log.warn("Discourse needs discourse.ckan_category set to work. Please set \
'discourse.ckan_category' in your .ini!")
# check for valid JSON
try:
discourse_api = discourse_url + discourse_ckan_category + '.json'
r = requests.get(discourse_api, verify=False)
test_category_dict = r.json()
except:
log.warn(discourse_api + " is not a valid Discourse JSON endpoint!")
config['pylons.app_globals'].has_commenting = True
# store these so available to class methods
self.__class__.discourse_url = discourse_url
self.__class__.discourse_username = discourse_username
self.__class__.discourse_count_cache_age = discourse_count_cache_age
self.__class__.discourse_ckan_category = discourse_ckan_category
self.__class__.discourse_debug = discourse_debug
self.__class__.next_sync = time.time() + discourse_count_cache_age
self.__class__.topic_lookup_dict = {}
self.__class__.active_conversations = 0
self.__class__.discourse_sync()
# IConfigurer