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


Python model.Package类代码示例

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


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

示例1: test_zaincremental_harvester

    def test_zaincremental_harvester(self):

        client = CKANServer()
        metadata_registry = metadata.MetadataRegistry()
        metadata_registry.registerReader('oai_dc', oai_dc_reader)
        metadata_registry.registerWriter('oai_dc', oai_dc_writer)
        serv = BatchingServer(client, metadata_registry=metadata_registry)
        oaipmh.client.Client = mock.Mock(return_value=ServerClient(serv, metadata_registry))
        harv = OAIPMHHarvester()
        harvest_job = HarvestJob()
        harvest_job.source = HarvestSource()
        harvest_job.source.title = "Test"
        harvest_job.source.url = "http://helda.helsinki.fi/oai/request"
        harvest_job.gather_started = ((datetime.now() + timedelta(days=1)))
        harvest_job.source.config = '{"incremental":"True"}'
        harvest_job.source.type = "OAI-PMH"
        Session.add(harvest_job)
        rev = model.repo.new_revision()
        rev.timestamp = ((datetime.now() + timedelta(days=2)))
        pkg = Package(name='footest', revision=rev)
        Session.add(pkg)
        pkg.save()
        roger = Group.get('roger')
        roger.add_package_by_name('footest')
        Session.add(roger)
        roger.save()
        gathered = harv.gather_stage(harvest_job)
        harvest_object = HarvestObject.get(gathered[0])
        harv.fetch_stage(harvest_object)
        harvobj = json.loads(harvest_object.content)
        self.assert_(harvobj['records'])
开发者ID:florenthemmi,项目名称:ckanext-oaipmh,代码行数:31,代码来源:test_oai.py

示例2: test_zfaulty_xml_unknown_errors

    def test_zfaulty_xml_unknown_errors(self):
        harv, job = self._create_harvester()
        res = "http://www.fsd.uta.fi/fi/aineistot/luettelo/FSD0115/FSD0115.xml"
        urllib2.urlopen = mock.Mock(return_value=StringIO(res))
        gathered = harv.gather_stage(job)

        urllib2.urlopen = mock.Mock(return_value=open("FSD2355.xml"))
        harvest_obj = HarvestObject.get(gathered[0])
        self.assert_(harv.fetch_stage(harvest_obj))
        self.assert_(harv.import_stage(harvest_obj))
        print Package.text_search(\
                            Session.query(Package),
                            'Kansalaiskeskustelu ydinvoimasta 2006').all()
        self.assert_(len(Package.text_search(\
                            Session.query(Package),
                            'Kansalaiskeskustelu ydinvoimasta 2006').all()) >= 1)

        res = "http://www.fsd.uta.fi/fi/aineistot/luettelo/FSD0115/FSD0115.xml"
        urllib2.urlopen = mock.Mock(return_value=StringIO(res))
        gathered = harv.gather_stage(job)
        urllib2.urlopen = mock.Mock(return_value=open("FSD2362.xml"))
        harvest_obj = HarvestObject.get(gathered[0])
        self.assert_(harv.fetch_stage(harvest_obj))
        self.assert_(harv.import_stage(harvest_obj))
        self.assert_(len(Package.text_search(\
                                Session.query(Package),
                                'Energia-asennetutkimus 2004').all()) >= 1)
开发者ID:ugeuder-kata,项目名称:ckanext-ddi,代码行数:27,代码来源:test_ddiharvester.py

示例3: alert

    def alert(self, dataset_name):
        '''
        Put an alert aka. a signalement on a dataset.
        '''
        if not toolkit.request.method == 'POST':
            raise toolkit.abort(400, 'Expected POST method')

        user = toolkit.c.userobj
        if not user:
            raise toolkit.NotAuthorized('Alert creation requires an user')

        dataset = Package.by_name(dataset_name)

        alert_type = toolkit.request.POST['type']
        comment = toolkit.request.POST['comment']
        alert = DatasetAlert(dataset, user, alert_type, comment)
        DB.add(alert)
        DB.commit()

        alert.notify_admins()

        return self.json_response({
            'id': alert.id,
            'user_id': alert.user_id,
            'dataset_id': alert.dataset_id,
            'type': alert.type,
            'comment': alert.comment,
            'created': alert.created
        })
开发者ID:etalab,项目名称:ckanext-youckan,代码行数:29,代码来源:dataset.py

示例4: send

 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,代码行数:27,代码来源:controllers.py

示例5: accessreq_show

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,代码行数:28,代码来源:actions.py

示例6: getRecord

 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,代码行数:7,代码来源:oaipmh_server.py

示例7: test_new

    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,代码行数:27,代码来源:test_package.py

示例8: is_owner

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,代码行数:32,代码来源:auth_functions.py

示例9: get_licenses

def get_licenses():
    licenses = [('', '')]
    register = Package.get_license_register()
    for l in register.values():
        if l.status == 'active':
            licenses.append((l.title, l.id))
    return licenses
开发者ID:monmaks,项目名称:ckanext-ceon,代码行数:7,代码来源:metadata.py

示例10: is_owner

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,代码行数:28,代码来源:auth_functions.py

示例11: send_email

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,代码行数:25,代码来源:utils.py

示例12: _create_pkg

 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,代码行数:8,代码来源:test_sitemap.py

示例13: get_resources_licenses

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,代码行数:8,代码来源:metadata.py

示例14: get_ancestral_license

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,代码行数:8,代码来源:metadata.py

示例15: validate_config

 def validate_config(self,config):
     super(GuiaHarvesterPlugin, self).validate_config(config)
     config_obj = json.loads(config)
     if 'license_id' in config:
         license_id = config_obj.get('license_id', None)
         if license_id not in Package.get_license_register().keys():
             raise ValueError('license_id not found')
     return config
开发者ID:ParadigmaXis,项目名称:dadosabertos_cmporto_pt,代码行数:8,代码来源:guiaharvester.py


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