当前位置: 首页>>代码示例>>Python>>正文


Python helpers.url_for方法代码示例

本文整理汇总了Python中ckan.lib.helpers.url_for方法的典型用法代码示例。如果您正苦于以下问题:Python helpers.url_for方法的具体用法?Python helpers.url_for怎么用?Python helpers.url_for使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ckan.lib.helpers的用法示例。


在下文中一共展示了helpers.url_for方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: remove

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import url_for [as 别名]
def remove(self, id):
        if 'cancel' in toolkit.request.params:
            toolkit.redirect_to(controller=controller, action='manage', id=id)

        context, controller = self._get_context_controller()
        user_id = toolkit.request.params['user']
        user_object = model.User.get(user_id)
        username = user_object.name
        group_object = model.Group.get(id)
        groupname = group_object.name
        dataset_type = toolkit.request.params['dataset_type']
        classification = toolkit.request.params['classification']
        
        if toolkit.request.method == 'POST' and user_id:
            self._action('security_member_delete', 
                         context, 
                         username, 
                         groupname, 
                         dataset_type,
                         classification,
                         "User \"{0}\" is no longer a member of resource classification on type \"{1}\"".format(username, dataset_type))

        return toolkit.redirect_to(
                helpers.url_for(controller=controller, action='manage', id=id)) 
开发者ID:abgov,项目名称:ckanext-classification,代码行数:26,代码来源:security_controller.py

示例2: _send_mail

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import url_for [as 别名]
def _send_mail(self, recipient_email, user_name, dataset_name):
        subject = 'Outdated dataset'
        url = h.url_for(controller='package', action='read', id=dataset_name,
                        qualified=True)
        body = 'The dataset {0} is outdated. Go to {1} and make sure it\'s '\
            'updated.'.format(dataset_name, url)

        try:
            self.log.info('Notifying user {0} for dataset {1}...'.format(
                user_name, dataset_name)
            )
            ckan_mailer.mail_recipient(user_name, recipient_email, subject,
                                       body)
        except ckan_mailer.MailerException:
            self.log.error('Error notifying user {0} for dataset '
                           '{1}.'.format(user_name, dataset_name)) 
开发者ID:ViderumGlobal,项目名称:ckanext-tayside,代码行数:18,代码来源:commands.py

示例3: test_dataset_doi_admin_sysadmin_verify_xml

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import url_for [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') 
开发者ID:Psykar,项目名称:ckanext-ands,代码行数:27,代码来源:test_plugin.py

示例4: test_catalog_default

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import url_for [as 别名]
def test_catalog_default(self):

        for i in xrange(4):
            factories.Dataset()

        url = url_for('dcat_catalog', _format='rdf')

        app = self._get_test_app()

        response = app.get(url)

        eq_(response.headers['Content-Type'], 'application/rdf+xml')

        content = response.body

        # Parse the contents to check it's an actual serialization
        p = RDFParser()

        p.parse(content, _format='xml')

        dcat_datasets = [d for d in p.datasets()]

        eq_(len(dcat_datasets), 4) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:25,代码来源:test_controllers.py

示例5: test_catalog_ttl

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import url_for [as 别名]
def test_catalog_ttl(self):

        for i in xrange(4):
            factories.Dataset()

        url = url_for('dcat_catalog', _format='ttl')

        app = self._get_test_app()

        response = app.get(url)

        eq_(response.headers['Content-Type'], 'text/turtle')

        content = response.body

        # Parse the contents to check it's an actual serialization
        p = RDFParser()

        p.parse(content, _format='turtle')

        dcat_datasets = [d for d in p.datasets()]

        eq_(len(dcat_datasets), 4) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:25,代码来源:test_controllers.py

示例6: test_catalog_modified_date

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import url_for [as 别名]
def test_catalog_modified_date(self):

        dataset1 = factories.Dataset(title='First dataset')
        time.sleep(1)
        dataset2 = factories.Dataset(title='Second dataset')

        url = url_for('dcat_catalog',
                      _format='ttl',
                      modified_since=dataset2['metadata_modified'])

        app = self._get_test_app()

        response = app.get(url)

        content = response.body

        p = RDFParser()

        p.parse(content, _format='turtle')

        dcat_datasets = [d for d in p.datasets()]

        eq_(len(dcat_datasets), 1)

        eq_(dcat_datasets[0]['title'], dataset2['title']) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:27,代码来源:test_controllers.py

示例7: test_spatial_extra_bad_json

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import url_for [as 别名]
def test_spatial_extra_bad_json(self):
        app = self._get_test_app()

        user = factories.User()
        env = {'REMOTE_USER': user['name'].encode('ascii')}
        dataset = factories.Dataset(user=user)

        offset = url_for(controller='package', action='edit', id=dataset['id'])
        res = app.get(offset, extra_environ=env)

        form = res.forms[1]
        form['extras__0__key'] = u'spatial'
        form['extras__0__value'] = u'{"Type":Bad Json]'

        res = helpers.webtest_submit(form, extra_environ=env, name='save')

        assert 'Error' in res, res
        assert 'Spatial' in res
        assert 'Error decoding JSON object' in res 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:21,代码来源:test_package.py

示例8: test_spatial_extra_bad_geojson

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import url_for [as 别名]
def test_spatial_extra_bad_geojson(self):
        app = self._get_test_app()

        user = factories.User()
        env = {'REMOTE_USER': user['name'].encode('ascii')}
        dataset = factories.Dataset(user=user)

        offset = url_for(controller='package', action='edit', id=dataset['id'])
        res = app.get(offset, extra_environ=env)

        form = res.forms[1]
        form['extras__0__key'] = u'spatial'
        form['extras__0__value'] = u'{"Type":"Bad_GeoJSON","a":2}'

        res = helpers.webtest_submit(form, extra_environ=env, name='save')

        assert 'Error' in res, res
        assert 'Spatial' in res
        assert 'Error creating geometry' in res 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:21,代码来源:test_package.py

示例9: get_proxified_resource_url

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import url_for [as 别名]
def get_proxified_resource_url(data_dict, proxy_schemes=['http','https']):
    '''
    :param data_dict: contains a resource and package dict
    :type data_dict: dictionary
    :param proxy_schemes: list of url schemes to proxy for.
    :type data_dict: list
    '''

    ckan_url = config.get('ckan.site_url', '//localhost:5000')
    url = data_dict['resource']['url']
    scheme = urlparse.urlparse(url).scheme
    compare_domains = datapreview.compare_domains
    if not compare_domains([ckan_url, url]) and scheme in proxy_schemes:
        url = h.url_for(
            action='proxy_resource',
            controller='ckanext.resourceproxy.controller:ProxyController',
            id=data_dict['package']['name'],
            resource_id=data_dict['resource']['id'])
        log.info('Proxified url is {0}'.format(url))
    return url 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:22,代码来源:plugin.py

示例10: resource_dictize

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import url_for [as 别名]
def resource_dictize(res, context):
    model = context['model']
    resource = d.table_dictize(res, context)
    extras = resource.pop("extras", None)
    if extras:
        resource.update(extras)
    # some urls do not have the protocol this adds http:// to these
    url = resource['url']
    ## for_edit is only called at the times when the dataset is to be edited
    ## in the frontend. Without for_edit the whole qualified url is returned.
    if resource.get('url_type') == 'upload' and not context.get('for_edit'):
        cleaned_name = munge.munge_filename(url)
        resource['url'] = h.url_for(controller='package',
                                    action='resource_download',
                                    id=resource['package_id'],
                                    resource_id=res.id,
                                    filename=cleaned_name,
                                    qualified=True)
    elif resource['url'] and not urlparse.urlsplit(url).scheme and not context.get('for_edit'):
        resource['url'] = u'http://' + url.lstrip('/')
    return resource 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:23,代码来源:model_dictize.py

示例11: test_email_address_nag

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import url_for [as 别名]
def test_email_address_nag(self):
        # before CKAN 1.6, users were allowed to have no email addresses
        app = self._get_test_app()
        # can't use factory to create user as without email it fails validation
        from ckan import model
        model.repo.new_revision()
        user = model.user.User(name='has-no-email')
        model.Session.add(user)
        model.Session.commit()
        env = {'REMOTE_USER': user.name.encode('ascii')}

        response = app.get(url=url_for('home'), extra_environ=env)

        assert 'update your profile' in response.body
        assert url_for(controller='user', action='edit') in response.body
        assert ' and add your email address.' in response.body 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:18,代码来源:test_home.py

示例12: setup_class

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import url_for [as 别名]
def setup_class(cls):
        plugins.load('test_resource_preview', 'test_json_resource_preview')
        cls.plugin = plugins.get_plugin('test_resource_preview')

        create_test_data.CreateTestData.create()

        cls.package = model.Package.get('annakarenina')
        cls.resource = cls.package.resources[0]
        cls.url = h.url_for(controller='package',
            action='resource_read',
            id=cls.package.name,
            resource_id=cls.resource.id)
        cls.preview_url = h.url_for(controller='package',
            action='resource_datapreview',
            id=cls.package.id,
            resource_id=cls.resource.id) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:18,代码来源:test_preview_interface.py

示例13: _form_save_redirect

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import url_for [as 别名]
def _form_save_redirect(self, pkgname, action, package_type=None):
        '''This redirects the user to the CKAN package/read page,
        unless there is request parameter giving an alternate location,
        perhaps an external website.
        @param pkgname - Name of the package just edited
        @param action - What the action of the edit was
        '''
        assert action in ('new', 'edit')
        url = request.params.get('return_to') or \
            config.get('package_%s_return_url' % action)
        if url:
            url = url.replace('<NAME>', pkgname)
        else:
            if package_type is None or package_type == 'dataset':
                url = h.url_for(controller='package', action='read',
                                id=pkgname)
            else:
                url = h.url_for('{0}_read'.format(package_type), id=pkgname)
        redirect(url) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:21,代码来源:package.py

示例14: login

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import url_for [as 别名]
def login(self, error=None):
        # Do any plugin login stuff
        for item in p.PluginImplementations(p.IAuthenticator):
            item.login()

        if 'error' in request.params:
            h.flash_error(request.params['error'])

        if not c.user:
            came_from = request.params.get('came_from')
            if not came_from:
                came_from = h.url_for(controller='user', action='logged_in',
                                      __ckan_no_root=True)
            c.login_handler = h.url_for(
                self._get_repoze_handler('login_handler_path'),
                came_from=came_from)
            if error:
                vars = {'error_summary': {'': error}}
            else:
                vars = {}
            return render('user/login.html', extra_vars=vars)
        else:
            return render('user/logout_first.html') 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:25,代码来源:user.py

示例15: edit

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import url_for [as 别名]
def edit(self, id=None):
        if id is None:
            base.abort(404)
        revision = model.Session.query(model.Revision).get(id)
        if revision is None:
            base.abort(404)
        action = request.params.get('action', '')
        if action in ['delete', 'undelete']:
            # this should be at a lower level (e.g. logic layer)
            if not c.revision_change_state_allowed:
                base.abort(403)
            if action == 'delete':
                revision.state = model.State.DELETED
            elif action == 'undelete':
                revision.state = model.State.ACTIVE
            model.Session.commit()
            h.flash_success(_('Revision updated'))
            h.redirect_to(
                h.url_for(controller='revision', action='read', id=id)) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:21,代码来源:revision.py


注:本文中的ckan.lib.helpers.url_for方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。