def logged_in(self): # we need to set the language via a redirect # Lang is not being retrieved properly by the Babel i18n lib in # this redirect, so using this clunky workaround for now. lang = session.pop('lang', None) if lang is None: came_from = request.params.get('came_from', '') if came_from.startswith('/fr'): lang = 'fr' else: lang = 'en' session.save() # we need to set the language explicitly here or the flash # messages will not be translated. i18n.set_lang(lang) if c.user: context = None data_dict = {'id': c.user} user_dict = get_action('user_show')(context, data_dict) h.flash_success( _('<strong>Note</strong><br>{0} is now logged in').format( user_dict['display_name'] ), allow_html=True ) notice_no_access() return h.redirect_to( controller='ckanext.canada.controller:CanadaController', action='home', locale=lang) else: h.flash_error(_('Login failed. Bad username or password.')) return h.redirect_to( controller='user', action='login', locale=lang )
def add_deletion_of_dataset_reason(data_dict): deletion_reason = '' if get_endpoint()[1] == 'action': body = json.loads(request.body) deletion_reason = body.get('deletion_reason', '') else: params = request.params.items() for param in params: if 'deletion_reason' in param: deletion_reason = param[1] if not deletion_reason: if get_endpoint()[1] == 'action': raise ValidationError('Missing deletion_reason field.') else: h.flash_error('Missing deletion reason.') return h.redirect_to('/dataset/edit/' + data_dict.id) if len(deletion_reason) < 10: if get_endpoint()[1] == 'action': raise ValidationError( 'Field deletion_reason must not less than 10 characters.') else: h.flash_error('Deletion reason must not less than 10 characters.') return h.redirect_to('/dataset/edit/' + data_dict.id) if len(deletion_reason) > 250: if get_endpoint()[1] == 'action': raise ValidationError( 'Field deletion_reason must not more than 250 characters.') else: h.flash_error('Deletion reason must not more than 250 characters.') return h.redirect_to('/dataset/edit/' + data_dict.id) get_action('package_patch')({}, { 'id': data_dict.id, 'deletion_reason': deletion_reason })