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


Python Package.get方法代码示例

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


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

示例1: send

# 需要导入模块: from ckan.model import Package [as 别名]
# 或者: from ckan.model.Package import get [as 别名]
 def send(self, pkg_id):
     package = Package.get(pkg_id)
     url = h.url_for(controller='package',
             action="read",
             id=package.id)
     if c.user:
             userid = None
             for role in package.roles:
                 if role.role == "admin":
                     userid = role.user_id
                     break
             if userid:
                 owner = User.get(userid)
                 msg = request.params.get('msg', '')
                 if msg:
                     send_contact_email(owner, c.userobj, package,\
                                    msg)
                 else:
                     h.flash_error(_("No message"))
                     return redirect(url)
             else:
                 h.flash_error(_("No owner found"))
                 return redirect(url)
             h.flash_notice(_("Message sent"))
     else:
         h.flash_error(_("Please login"))
     return redirect(url)
开发者ID:ugeuder-kata,项目名称:ckanext-kata,代码行数:29,代码来源:controllers.py

示例2: test_new

# 需要导入模块: from ckan.model import Package [as 别名]
# 或者: from ckan.model.Package import get [as 别名]
    def test_new(self):
        name = "test-spatial-dataset-1"

        offset = url_for(controller="package", action="new")
        res = self.app.get(offset, extra_environ=self.extra_environ)
        assert "Add - Datasets" in res
        fv = res.forms["dataset-edit"]
        prefix = ""
        fv[prefix + "name"] = name
        fv[prefix + "extras__0__key"] = u"spatial"
        fv[prefix + "extras__0__value"] = self.geojson_examples["point"]

        res = fv.submit("save", extra_environ=self.extra_environ)
        assert not "Error" in res, res

        package = Package.get(name)

        # Check that a PackageExtent object has been created
        package_extent = Session.query(PackageExtent).filter(PackageExtent.package_id == package.id).first()

        geojson = json.loads(self.geojson_examples["point"])

        assert package_extent
        assert package_extent.package_id == package.id
        assert Session.scalar(package_extent.the_geom.x) == geojson["coordinates"][0]
        assert Session.scalar(package_extent.the_geom.y) == geojson["coordinates"][1]
        assert Session.scalar(package_extent.the_geom.srid) == self.db_srid
开发者ID:Zharktas,项目名称:ckanext-spatial,代码行数:29,代码来源:test_package.py

示例3: send_email

# 需要导入模块: from ckan.model import Package [as 别名]
# 或者: from ckan.model.Package import get [as 别名]
def send_email(req):
    requestee = User.get(req.user_id)
    pkg = Package.get(req.pkg_id)
    selrole = False
    for role in pkg.roles:
        if role.role == "admin":
            selrole = role
    if not selrole:
        return
    admin = User.get(selrole.user_id)
    msg = _("""%s (%s) is requesting editor access to a dataset you have created
    %s.

Please click this link if you want to give this user write access:
%s%s""")
    controller = 'ckanext.kata.controllers:AccessRequestController'
    body = msg % (requestee.name, requestee.email, pkg.title if pkg.title else pkg.name,
                config.get('ckan.site_url', ''),
                h.url_for(controller=controller,
                action="unlock_access",
                id=req.id))
    email_dict = {}
    email_dict["subject"] = _("Access request for dataset %s" % pkg.title if pkg.title else pkg.name)
    email_dict["body"] = body
    send_notification(admin.as_dict(), email_dict)
开发者ID:ugeuder-kata,项目名称:ckanext-kata,代码行数:27,代码来源:utils.py

示例4: is_owner

# 需要导入模块: from ckan.model import Package [as 别名]
# 或者: from ckan.model.Package import get [as 别名]
def is_owner(context, data_dict):
    '''
    This is used in "request edit rights" feature.
    Checks if the user is creator, admin or editor of the
    package in question

    :param context: context
    :param data_dict: package data
    :type data_dict: dictionary

    :rtype: dictionary
    '''

    # Package creator is always owner regardless of organizations
    pkg = context.get('package', None) or Package.get(data_dict['id'])
    user = context.get('user', False)

    # If user id can't be resolved, user can't be owner
    try:
        user_id = convert_user_name_or_id_to_id(user, context)
    except:
        return {'success': False}

    if pkg.creator_user_id == user_id:
        return {'success': True}

    # Check if the user has editor rights to this dataset through an organization
    package = get_package_object(context, data_dict)
    if authz.has_user_permission_for_group_or_org(package.owner_org, user, 'delete_dataset'):
        return {'success': True}

    return {'success': False}
开发者ID:kata-csc,项目名称:ckanext-kata,代码行数:34,代码来源:auth_functions.py

示例5: accessreq_show

# 需要导入模块: from ckan.model import Package [as 别名]
# 或者: from ckan.model.Package import get [as 别名]
def accessreq_show(context, data_dict):
    ret = {}
    ret['title'] = _('Request edit rights')
    smtp = config.get('smtp.server', '')
    if not len(smtp):
        ret['ret'] = 'Yes'
        return ret
    pkg = Package.get(data_dict['id'])
    selrole = False
    ret['id'] = pkg.id
    for role in pkg.roles:
        if role.role == "admin":
            selrole = True
    ret['no_owner'] = not selrole
    if c.userobj:
        if 'id' in data_dict:
            req = KataAccessRequest.is_requesting(c.userobj.id, data_dict['id'])
            if req:
                ret['ret'] = 'Yes'
                return ret
            else:
                ret['ret'] = 'No'
                return ret
        else:
            ret['ret'] = 'No'
            return ret
    ret['ret'] = 'No'
    return ret
开发者ID:ugeuder-kata,项目名称:ckanext-kata,代码行数:30,代码来源:actions.py

示例6: getRecord

# 需要导入模块: from ckan.model import Package [as 别名]
# 或者: from ckan.model.Package import get [as 别名]
 def getRecord(self, metadataPrefix, identifier):
     '''Simple getRecord for a dataset.
     '''
     package = Package.get(identifier)
     if not package:
         raise IdDoesNotExistError("No dataset with id %s" % identifier)
     return self._record_for_dataset(package)
开发者ID:LondonAppDev,项目名称:ckanext-oaipmh,代码行数:9,代码来源:oaipmh_server.py

示例7: is_owner

# 需要导入模块: from ckan.model import Package [as 别名]
# 或者: from ckan.model.Package import get [as 别名]
def is_owner(context, data_dict):
    '''
    This is used in "request edit rights" feature.
    Checks if the user is admin or editor of the
    package in question

    :param context: context
    :param data_dict: package data
    :type data_dict: dictionary

    :rtype: dictionary
    '''

    pkg = context.get('package', None)
    roles = pkg.roles if pkg else Package.get(data_dict['id']).roles
    user = context.get('user', False)
    if user:
        for role in roles:
            ruser = User.get(role.user.id)
            if user == ruser.name and role.role in ('admin', 'editor'):
                return {'success': True}

    # Check if the user has editor rights to this dataset through an organization
    package = get_package_object(context, data_dict)
    if new_authz.has_user_permission_for_group_or_org(package.owner_org, user, 'delete_dataset'):
        return {'success': True}

    return {'success': False}
开发者ID:atehwa,项目名称:ckanext-kata,代码行数:30,代码来源:auth_functions.py

示例8: _create_pkg

# 需要导入模块: from ckan.model import Package [as 别名]
# 或者: from ckan.model.Package import get [as 别名]
 def _create_pkg(self):
     model.repo.new_revision()
     pkg = Package.get("annakarenina")
     pkg.name = "fookarenina"
     pkg.add_resource("www.google.com", description="foo", name="foo")
     Session.add(pkg)
     Session.commit()
     return pkg
开发者ID:kata-csc,项目名称:ckanext-sitemap,代码行数:10,代码来源:test_sitemap.py

示例9: get_resources_licenses

# 需要导入模块: from ckan.model import Package [as 别名]
# 或者: from ckan.model.Package import get [as 别名]
def get_resources_licenses(session, pkg_dict):
    license_ids = []
    package = Package.get(pkg_dict['id'])
    for resource in package.resources:
        res_license = session.query(CeonResourceLicense).filter(CeonResourceLicense.resource_id == resource.id).first()
        if res_license:
            license_ids.append(res_license.license_id)
    return license_ids
开发者ID:monmaks,项目名称:ckanext-ceon,代码行数:10,代码来源:metadata.py

示例10: get_ancestral_license

# 需要导入模块: from ckan.model import Package [as 别名]
# 或者: from ckan.model.Package import get [as 别名]
def get_ancestral_license(session, package_id):
    license_id = None
    if package_id:
        package = Package.get(package_id)
        extras = package.extras
        if 'ancestral_license' in extras:
            license_id = extras['ancestral_license']
    return license_id
开发者ID:monmaks,项目名称:ckanext-ceon,代码行数:10,代码来源:metadata.py

示例11: package_show

# 需要导入模块: from ckan.model import Package [as 别名]
# 或者: from ckan.model.Package import get [as 别名]
def package_show(context, data_dict):
    '''
    Return the metadata of a dataset (package) and its resources.

    Called before showing the dataset in some interface (browser, API),
    or when adding package to Solr index (no validation / conversions then).

    :param id: the id or name of the dataset
    :type id: string

    :rtype: dictionary
    '''

    if data_dict.get('type') == 'harvest':
        context['schema'] = Schemas.harvest_source_show_package_schema()

    if not data_dict.get('id') and not data_dict.get('name'):
        # Get package by data PIDs
        data_dict['id'] = utils.get_package_id_by_data_pids(data_dict)

    pkg_dict1 = ckan.logic.action.get.package_show(context, data_dict)
    pkg_dict1 = utils.resource_to_dataset(pkg_dict1)

    # Remove empty agents that come from padding the agent list in converters
    if 'agent' in pkg_dict1:
        agents = filter(None, pkg_dict1.get('agent', []))
        pkg_dict1['agent'] = agents or []

    # Normally logic function should not catch the raised errors
    # but here it is needed so action package_show won't catch it instead
    # Hiding information from API calls
    try:
        check_access('package_update', context)
    except NotAuthorized:
        pkg_dict1 = utils.hide_sensitive_fields(pkg_dict1)

    pkg = Package.get(pkg_dict1['id'])
    if 'erelated' in pkg.extras:
        erelated = pkg.extras['erelated']
        if len(erelated):
            for value in erelated.split(';'):
                if len(Session.query(Related).filter(Related.title == value).all()) == 0:
                    data_dict = {'title': value,
                                 'type': _("Paper"),
                                 'dataset_id': pkg.id}
                    related_create(context, data_dict)

    # Update package.title to match package.extras.title_0
    extras_title = pkg.extras.get(u'title_0')
    if extras_title and extras_title != pkg.title:
        repo.new_revision()
        pkg.title = pkg.extras[u'title_0']
        pkg.save()
        rebuild(pkg.id)  # Rebuild solr-index for this dataset

    return pkg_dict1
开发者ID:atehwa,项目名称:ckanext-kata,代码行数:58,代码来源:actions.py

示例12: getMetadataDDI

# 需要导入模块: from ckan.model import Package [as 别名]
# 或者: from ckan.model.Package import get [as 别名]
 def getMetadataDDI(self,id):
     toolkit.response.content_type = 'application/xml'
     c.pkg = Package.get(id)
     if c.pkg is None:
         abort(404, 'Dataset not found')
     pkginfo = toolkit.get_action('package_show')({}, {'id': id})
     try:
         return createDDIXML(pkginfo,toolkit.request.url)
     except Exception,e:
         print str(e)
         return "[]"
开发者ID:riiko,项目名称:ckanext-dataportal,代码行数:13,代码来源:controller.py

示例13: googleanalytics_dataset_visits

# 需要导入模块: from ckan.model import Package [as 别名]
# 或者: from ckan.model.Package import get [as 别名]
def googleanalytics_dataset_visits(context=None, data_dict=None):
    """
    Fetch the amount of times a dataset hs been visited

    :param id: Dataset id
    :type id: string

    :returns: The number of times the dataset has been viewed
    :rtype: integer
    """
    package = Package.get(data_dict['id'])
    return PackageStats.get_all_visits(package.id)
开发者ID:yhteentoimivuuspalvelut,项目名称:ckanext-googleanalytics,代码行数:14,代码来源:get.py

示例14: is_owner

# 需要导入模块: from ckan.model import Package [as 别名]
# 或者: from ckan.model.Package import get [as 别名]
def is_owner(context, data_dict):
    pkg = context.get('package', None)
    roles = pkg.roles if pkg else Package.get(data_dict['id']).roles
    user = context.get('user', False)
    if user:
        for role in roles:
            ruser = User.get(role.user_id)
            if user == ruser.name and role.role in ('admin', 'editor'):
                return {'success': True}
    else:
        return {'success': False}
    return {'success': False}
开发者ID:ugeuder-kata,项目名称:ckanext-kata,代码行数:14,代码来源:auth_functions.py

示例15: show

# 需要导入模块: from ckan.model import Package [as 别名]
# 或者: from ckan.model.Package import get [as 别名]
    def show(self,id):
        package = Package.get(id)
        if package:
            graph = pkg_produce(package)
            
            doc = graph.serialize(format='pretty-xml')
            response.content_type = 'application/rdf+xml'
            response.headers['Content-Length'] = len(doc)

            return doc
        else:
            abort(404)
开发者ID:eccenca,项目名称:ckanext-rdf,代码行数:14,代码来源:controllers.py


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