本文整理汇总了Python中ckan.lib.helpers.flash_success方法的典型用法代码示例。如果您正苦于以下问题:Python helpers.flash_success方法的具体用法?Python helpers.flash_success怎么用?Python helpers.flash_success使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ckan.lib.helpers
的用法示例。
在下文中一共展示了helpers.flash_success方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _action
# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_success [as 别名]
def _action(self, action, context, username, groupname,
dataset_type, classification, success_msg):
try:
toolkit.get_action(action)(context,
data_dict={'username': username,
'groupname': groupname,
'dataset_type': dataset_type,
'classification': classification}
)
except toolkit.NotAuthorized:
toolkit.abort(401,
toolkit._('Unauthorized to perform that action'))
except toolkit.ObjectNotFound as e :
error_message = (e.message or e.error_summary
or e.error_dict)
helpers.flash_error(error_message)
except toolkit.ValidationError as e:
error_message = e.error_dict
helpers.flash_error(error_message['message'])
else:
helpers.flash_success(toolkit._(success_msg))
示例2: follow
# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_success [as 别名]
def follow(self, id):
'''Start following this group.'''
self._ensure_controller_matches_group_type(id)
context = {'model': model,
'session': model.Session,
'user': c.user}
data_dict = {'id': id}
try:
get_action('follow_group')(context, data_dict)
group_dict = get_action('group_show')(context, data_dict)
h.flash_success(_("You are now following {0}").format(
group_dict['title']))
except ValidationError as e:
error_message = (e.message or e.error_summary
or e.error_dict)
h.flash_error(error_message)
except NotAuthorized as e:
h.flash_error(e.message)
h.redirect_to(controller='group', action='read', id=id)
示例3: unfollow
# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_success [as 别名]
def unfollow(self, id):
'''Stop following this group.'''
self._ensure_controller_matches_group_type(id)
context = {'model': model,
'session': model.Session,
'user': c.user}
data_dict = {'id': id}
try:
get_action('unfollow_group')(context, data_dict)
group_dict = get_action('group_show')(context, data_dict)
h.flash_success(_("You are no longer following {0}").format(
group_dict['title']))
except ValidationError as e:
error_message = (e.message or e.error_summary
or e.error_dict)
h.flash_error(error_message)
except (NotFound, NotAuthorized) as e:
error_message = e.message
h.flash_error(error_message)
h.redirect_to(controller='group', action='read', id=id)
示例4: follow
# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_success [as 别名]
def follow(self, id):
'''Start following this dataset.'''
context = {'model': model,
'session': model.Session,
'user': c.user, 'auth_user_obj': c.userobj}
data_dict = {'id': id}
try:
get_action('follow_dataset')(context, data_dict)
package_dict = get_action('package_show')(context, data_dict)
h.flash_success(_("You are now following {0}").format(
package_dict['title']))
except ValidationError as e:
error_message = (e.message or e.error_summary
or e.error_dict)
h.flash_error(error_message)
except NotAuthorized as e:
h.flash_error(e.message)
h.redirect_to(controller='package', action='read', id=id)
示例5: unfollow
# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_success [as 别名]
def unfollow(self, id):
'''Stop following this dataset.'''
context = {'model': model,
'session': model.Session,
'user': c.user, 'auth_user_obj': c.userobj}
data_dict = {'id': id}
try:
get_action('unfollow_dataset')(context, data_dict)
package_dict = get_action('package_show')(context, data_dict)
h.flash_success(_("You are no longer following {0}").format(
package_dict['title']))
except ValidationError as e:
error_message = (e.message or e.error_summary
or e.error_dict)
h.flash_error(error_message)
except (NotFound, NotAuthorized) as e:
error_message = e.message
h.flash_error(error_message)
h.redirect_to(controller='package', action='read', id=id)
示例6: generate_apikey
# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_success [as 别名]
def generate_apikey(self, id):
'''Cycle the API key of a user'''
context = {'model': model,
'session': model.Session,
'user': c.user,
'auth_user_obj': c.userobj,
}
if id is None:
if c.userobj:
id = c.userobj.id
else:
abort(400, _('No user specified'))
data_dict = {'id': id}
try:
result = get_action('user_generate_apikey')(context, data_dict)
except NotAuthorized:
abort(403, _('Unauthorized to edit user %s') % '')
except NotFound:
abort(404, _('User not found'))
h.flash_success(_('Profile updated'))
h.redirect_to(controller='user', action='read', id=result['name'])
示例7: follow
# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_success [as 别名]
def follow(self, id):
'''Start following this user.'''
context = {'model': model,
'session': model.Session,
'user': c.user,
'auth_user_obj': c.userobj}
data_dict = {'id': id, 'include_num_followers': True}
try:
get_action('follow_user')(context, data_dict)
user_dict = get_action('user_show')(context, data_dict)
h.flash_success(_("You are now following {0}").format(
user_dict['display_name']))
except ValidationError as e:
error_message = (e.message or e.error_summary
or e.error_dict)
h.flash_error(error_message)
except NotAuthorized as e:
h.flash_error(e.message)
h.redirect_to(controller='user', action='read', id=id)
示例8: unfollow
# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_success [as 别名]
def unfollow(self, id):
'''Stop following this user.'''
context = {'model': model,
'session': model.Session,
'user': c.user,
'auth_user_obj': c.userobj}
data_dict = {'id': id, 'include_num_followers': True}
try:
get_action('unfollow_user')(context, data_dict)
user_dict = get_action('user_show')(context, data_dict)
h.flash_success(_("You are no longer following {0}").format(
user_dict['display_name']))
except (NotFound, NotAuthorized) as e:
error_message = e.message
h.flash_error(error_message)
except ValidationError as e:
error_message = (e.error_summary or e.message
or e.error_dict)
h.flash_error(error_message)
h.redirect_to(controller='user', action='read', id=id)
示例9: delete
# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_success [as 别名]
def delete(self,id):
try:
context = {'model':model, 'user':c.user}
context['clear_source'] = request.params.get('clear', '').lower() in (u'true', u'1')
p.toolkit.get_action('harvest_source_delete')(context, {'id':id})
if context['clear_source']:
h.flash_success(_('Harvesting source successfully cleared'))
else:
h.flash_success(_('Harvesting source successfully inactivated'))
h.redirect_to(h.url_for('{0}_admin'.format(DATASET_TYPE_NAME), id=id))
except p.toolkit.ObjectNotFound:
abort(404,_('Harvest source not found'))
except p.toolkit.NotAuthorized:
abort(401,self.not_auth_message)
示例10: refresh
# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_success [as 别名]
def refresh(self, id):
try:
context = {'model':model, 'user':c.user, 'session':model.Session}
p.toolkit.get_action('harvest_job_create')(
context, {'source_id': id, 'run': True})
h.flash_success(_('Harvest will start shortly. Refresh this page for updates.'))
except p.toolkit.ObjectNotFound:
abort(404,_('Harvest source not found'))
except p.toolkit.NotAuthorized:
abort(401,self.not_auth_message)
except HarvestSourceInactiveError, e:
h.flash_error(_('Cannot create new harvest jobs on inactive '
'sources. First, please change the source status '
'to \'active\'.'))
except HarvestJobExists, e:
h.flash_notice(_('A harvest job has already been scheduled for '
'this source'))
except Exception, e:
msg = 'An error occurred: [%s]' % str(e)
h.flash_error(msg)
h.redirect_to(h.url_for('{0}_admin'.format(DATASET_TYPE_NAME), id=id))
示例11: dataset_doi_admin_process
# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_success [as 别名]
def dataset_doi_admin_process(self, dataset_url, dataset):
# If running on local machine, just resolve DOI to the dev server
if 'localhost' in dataset_url or '127.0.0.1' in dataset_url:
xml_url = config.get('ckanext.ands.debug_url')
else:
xml_url = dataset_url
post_data = request.POST['xml']
resp = post_doi_request(xml_url, post_data)
try:
json = loads(resp.content)
except ValueError as exp:
h.flash_error("Invalid response from DOI server: {} :: {}".format(exp, resp.content))
return toolkit.redirect_to(dataset_url)
try:
response_dict = json["response"]
except KeyError:
h.flash_error("Response had no response key: {}".format(json))
return toolkit.redirect_to(dataset_url)
doi = response_dict["doi"]
response_code = response_dict["responsecode"]
success_code = "MT001"
if response_code == success_code:
dataset['doi_id'] = doi
toolkit.get_action('package_update')(None, dataset)
email_requestors(dataset['id'])
h.flash_success("DOI Created successfully")
else:
type = response_dict["type"]
err_msg = response_dict["message"]
verbose_msg = response_dict["verbosemessage"]
msg = response_code + ' - ' + type + '. ' + verbose_msg + '. ' + err_msg
h.flash_error(_(msg))
return toolkit.redirect_to(dataset_url)
示例12: handle_submit
# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_success [as 别名]
def handle_submit(self, id):
data = clean_dict(dict_fns.unflatten(tuplize_dict(parse_params(
request.params))))
data['dataset_url'] = toolkit.url_for(
controller='package',
action='read',
id=id,
qualified=True
)
package = get_action('package_show')(None, {'id': id})
self.fail_if_private(package, data['dataset_url'])
# Comma separated config var
to_addrs = config['ckanext.ands.support_emails'].split(',')
subject = 'DataPortal Support: Request to publish dataset'
body = base.render(
'package/doi_email.text',
extra_vars=data)
for email in to_addrs:
mail_recipient('Dataportal support', email, subject, body)
data['package_id'] = package['id']
data['user_id'] = c.userobj.id
doi_request = DoiRequest(**data)
Session.add(doi_request)
Session.commit()
h.flash_success("DOI Request sent")
return toolkit.redirect_to(data['dataset_url'])
示例13: clear
# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_success [as 别名]
def clear(self, id):
try:
context = {'model':model, 'user':c.user, 'session':model.Session}
p.toolkit.get_action('harvest_source_clear')(context,{'id':id})
h.flash_success(_('Harvest source cleared'))
except p.toolkit.ObjectNotFound:
abort(404,_('Harvest source not found'))
except p.toolkit.NotAuthorized:
abort(401,self.not_auth_message)
except Exception, e:
msg = 'An error occurred: [%s]' % str(e)
h.flash_error(msg)
h.redirect_to(h.url_for('{0}_admin'.format(DATASET_TYPE_NAME), id=id))
示例14: email
# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_success [as 别名]
def email(self):
'''
Handles creating the email template in admin dashboard.
:returns template
'''
data = request.POST
if 'save' in data:
try:
data_dict = dict(request.POST)
del data_dict['save']
data = _get_action('config_option_update', data_dict)
h.flash_success(_('Successfully updated.'))
except logic.ValidationError, e:
errors = e.error_dict
error_summary = e.error_summary
vars = {'data': data, 'errors': errors,
'error_summary': error_summary}
return base.render('admin/email.html', extra_vars=vars)
h.redirect_to(controller=self.ctrl, action='email')
schema = logic.schema.update_configuration_schema()
data = {}
for key in schema:
data[key] = config.get(key)
vars = {'data': data, 'errors': {}}
return toolkit.render('admin/email.html', extra_vars=vars)
示例15: clear
# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_success [as 别名]
def clear(self):
'''
Clears the PyCSW database
'''
config_path = config.get('ckan.ioos_theme.pycsw_config')
if os.path.exists(config_path):
try:
self._clear_pycsw(config_path)
h.flash_success(_('PyCSW has been cleared'))
except Exception:
h.flash_error('Unable to clear PyCSW, see logs for details')
else:
h.flash_error('Config for PyCSW doesn\'t exist')
h.redirect_to(controller='ckanext.ioos_theme.controllers.csw:CswController', action='index')
return