Esempio n. 1
0
 def resource_edit(self, id, resource_id, data=None, errors=None,
                   error_summary=None):
     try:
         return super(CanadaDatasetController, self).resource_edit(
             id, resource_id, data, errors, error_summary)
     except HTTPFound:
         h.flash_success(_(u'Resource updated.'))
         # resource read page is unfinished, return to dataset page
         h.redirect_to(controller='package', action='read', id=id)
Esempio n. 2
0
 def resource_edit(self, id, resource_id, data=None, errors=None,
                   error_summary=None):
     try:
         return super(CanadaDatasetController, self).resource_edit(
             id, resource_id, data, errors, error_summary)
     except HTTPFound:
         h.flash_success(_(u'Resource updated.'))
         # resource read page is unfinished, return to dataset page
         h.redirect_to(controller='package', action='read', id=id)
Esempio n. 3
0
    def home(self):
        if not c.user:
            h.redirect_to(controller='user', action='login')

        is_new = not h.check_access('package_create')

        if is_new:
            return h.redirect_to(controller='package', action='search')
        return h.redirect_to(
            controller='ckanext.canada.controller:CanadaController',
            action='links')
Esempio n. 4
0
    def home(self):
        if not c.user:
            h.redirect_to(controller='user', action='login')

        is_new = not h.check_access('package_create')

        if is_new:
            return h.redirect_to(controller='package', action='search')
        return h.redirect_to(
            controller='ckanext.canada.controller:CanadaController',
            action='links')
Esempio n. 5
0
    def package_undelete(self, pkg_id):
        h.flash_success(
            _('<strong>Note</strong><br> The record has been restored.'),
            allow_html=True)

        lc = LocalCKAN(username=c.user)
        lc.action.package_patch(id=pkg_id, state='active')

        return h.redirect_to(controller='package', action='read', id=pkg_id)
Esempio n. 6
0
    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
            )
Esempio n. 7
0
    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
            )
Esempio n. 8
0
    def package_delete(self, pkg_id):
        h.flash_success(_(
            '<strong>Note</strong><br> The dataset has been removed from'
            ' the Open Government Portal. <br/> The record may re-appear'
            ' if it is re-harvested or updated. Please ensure that the'
            ' record is deleted and purged from the source catalogue in'
            ' order to prevent it from reappearing.'),
                        allow_html=True)
        lc = LocalCKAN(username=c.user)
        lc.action.package_delete(id=pkg_id)

        return h.redirect_to(controller='package', action='search')
Esempio n. 9
0
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
    })
Esempio n. 10
0
    def package_undelete(self, pkg_id):
        h.flash_success(_(
            '<strong>Note</strong><br> The record has been restored.'),
            allow_html=True
        )

        lc = LocalCKAN(username=c.user)
        lc.action.package_patch(
            id=pkg_id,
            state='active'
        )

        return h.redirect_to(
            controller='package',
            action='read',
            id=pkg_id
        )
Esempio n. 11
0
    def package_delete(self, pkg_id):
        h.flash_success(_(
            '<strong>Note</strong><br> The dataset has been removed from'
            ' the Open Government Portal. <br/> The record may re-appear'
            ' if it is re-harvested or updated. Please ensure that the'
            ' record is deleted and purged from the source catalogue in'
            ' order to prevent it from reappearing.'
            ),
            allow_html=True
        )
        lc = LocalCKAN(username=c.user)
        lc.action.package_delete(id=pkg_id)

        return h.redirect_to(
            controller='package',
            action='search'
        )