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


Python Repository.get_object方法代码示例

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


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

示例1: handle

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import get_object [as 别名]
    def handle(self, *args, **options):
        self.options = options
        self.repaired_count = 0
        self.unrepaired_count = 0

        repo = Repository()
        self.pidman = DjangoPidmanRestClient()

        # populate list of objects to be processed
        objects = []
        for pid in args:
            try:
                obj = repo.get_object(pid=pid, type=CollectionObject)
                if obj.has_requisite_content_models:
                    objects.append(obj)
                else:
                    obj = repo.get_object(pid=pid, type=AudioObject)
                    if obj.has_requisite_content_models:
                        objects.append(obj)
            except Exception:
                self.log(message="Could not find Collection or Audio object for: %s" % pid)

        # get list of all collections from the repository
        # limited to the COLLECTION_CONTENT_MODEL as well as returns a Keep specific collection object
        if not args:
            objects = repo.get_objects_with_cmodel(CollectionObject.COLLECTION_CONTENT_MODEL, type=CollectionObject)

        if not objects:
            self.log(message="No Collections were found.")

        for obj in objects:
            self.repair_ark(obj)

        self.log(message="\n\n%s ARKs repaired\n%s ARKs were not repaired" % (self.repaired_count, self.unrepaired_count), no_label=True)
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:36,代码来源:repair_arks.py

示例2: englishdocs_collection

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import get_object [as 别名]
 def englishdocs_collection():
     repo = Repository()
     obj = repo.get_object(type=CollectionObject)
     obj.label = 'English documents collection'
     obj.mods.content.title = 'English documents collection'
     obj.mods.content.source_id = '309'
     obj.collection = repo.get_object(FedoraFixtures.archives()[1].uri)
     obj.mods.content.create_origin_info()
     obj.mods.content.origin_info.created.append(mods.DateCreated(date=1509, point='start'))
     obj.mods.content.origin_info.created.append(mods.DateCreated(date=1805, point='end'))
     return obj
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:13,代码来源:fixtures.py

示例3: esterbrook_collection

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import get_object [as 别名]
 def esterbrook_collection():
     repo = Repository()
     obj = repo.get_object(type=CollectionObject)
     obj.label = 'Thomas Esterbrook letter books'
     obj.mods.content.title = 'Thomas Esterbrook letter books'
     obj.mods.content.source_id = '123'
     obj.collection = repo.get_object(FedoraFixtures.archives()[2].uri)
     obj.mods.content.create_origin_info()
     obj.mods.content.origin_info.created.append(mods.DateCreated(date=1855, point='start'))
     obj.mods.content.origin_info.created.append(mods.DateCreated(date=1861, point='end'))
     obj.mods.content.create_name()
     obj.mods.content.name.name_parts.append(mods.NamePart(text='Thomas Esterbrook'))
     return obj
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:15,代码来源:fixtures.py

示例4: rushdie_collection

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import get_object [as 别名]
 def rushdie_collection():
     repo = Repository()
     obj = repo.get_object(type=CollectionObject)
     obj.label = 'Salman Rushdie Collection'
     obj.mods.content.title = 'Salman Rushdie Collection'
     obj.mods.content.source_id = '1000'
     obj.collection = repo.get_object(FedoraFixtures.archives()[1].uri)
     obj.mods.content.create_origin_info()
     obj.mods.content.origin_info.created.append(mods.DateCreated(date=1947, point='start'))
     obj.mods.content.origin_info.created.append(mods.DateCreated(date=2008, point='end'))
     obj.mods.content.create_name()
     obj.mods.content.name.name_parts.append(mods.NamePart(text='Salman Rushdie'))
     return obj
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:15,代码来源:fixtures.py

示例5: view

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import get_object [as 别名]
def view(request, pid):
    '''View a single :class:`~keep.video.models.Video`.
    User must either have general view video permissions, or if they have
    view researcher view, the object must be researcher accessible
    (based on rights codes).
    '''
    repo = Repository(request=request)
    obj = repo.get_object(pid=pid, type=Video)
    # # user either needs view video permissions OR
    # # if they can view researcher audio and object must be researcher-accessible

    viewable = request.user.has_perm('video.view_video') or \
        (request.user.has_perm('video.view_researcher_video') and
         bool(obj.researcher_access))

    if not viewable:
        return prompt_login_or_403(request)

    try:
        if not obj.has_requisite_content_models:
            raise Http404
    except:
        raise Http404


    return render(request, 'video/view.html', {"resource": obj})
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:28,代码来源:views.py

示例6: Command

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import get_object [as 别名]
class Command(BaseCommand):
    '''Generate access copies for PIDs specified on the command line.'''
    help = __doc__

    def handle(self, *args, **options):
        self.verbosity = options['verbosity']
        self.repo = Repository()

        for pid in args:
            self.process_pid(pid)

    def process_pid(self, pid):
        '''Process a single PID by looking it up in the repository, figuring
        out what kind of processing it needs based on its object type, and
        doing that.
        '''

        obj = self.repo.get_object(pid=pid, type=self.repo.infer_object_subtype)
        if not obj.exists:
            if self.verbosity >= 1:
                print "No such PID; skipped:", pid
                return

        if isinstance(obj, AudioObject):
            if self.verbosity >= 2:
                print "Generating audio access copy:", pid
            queue_access_copy(obj)
        else:
            if self.verbosity >= 1:
                print "Unhandled  object type; skipped:", pid
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:32,代码来源:generate_access_copy.py

示例7: archives

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import get_object [as 别名]
 def archives(format=None):
     if format == dict:
         return [{'title': nick, 'pid': pid}
                 for nick,pid in settings.PID_ALIASES.iteritems()]
         
     if not hasattr(FedoraFixtures, '_archives'):
         repo = Repository()
         FedoraFixtures._archives = [repo.get_object(pid, type=CollectionObject)
                                     for pid in settings.PID_ALIASES.itervalues()]
     return FedoraFixtures._archives
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:12,代码来源:fixtures.py

示例8: download

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import get_object [as 别名]
def download(request, pid):
    'Download disk image datastream contents'
    repo = Repository(request=request)
    obj = repo.get_object(pid, type=DiskImage)
    extra_headers = {
        'Content-Disposition': "attachment; filename=%s.%s" % \
            (obj.noid, obj.provenance.content.object.latest_format.name)
    }
    return raw_datastream(request, pid, DiskImage.content.id,
        repo=repo, headers=extra_headers)
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:12,代码来源:views.py

示例9: simple_collection

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import get_object [as 别名]
 def simple_collection(label=None, status=None, pid=None):
     repo = Repository()
     obj = repo.get_object(type=SimpleCollection)
     if label is not None:
         obj.label = label
     obj.mods.content.create_restrictions_on_access()
     if status is not None:
         obj.mods.content.restrictions_on_access.text = status
     if pid is not None:
         obj.pid = pid
     return obj
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:13,代码来源:fixtures.py

示例10: _objects_by_type

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import get_object [as 别名]
def _objects_by_type(type_uri, type=None):
    """
    Returns a list of objects with the specified type_uri as objects of the specified type
    :param type_uri: The uri of the type being searched
    :param type: The type of object that should be returned
    """
    repo = Repository()

    pids = repo.risearch.get_subjects(RDF.type, type_uri)
    pids_list = list(pids)

    for pid in pids_list:
        yield repo.get_object(pid=pid, type=type)
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:15,代码来源:views.py

示例11: create_from_findingaid

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import get_object [as 别名]
def create_from_findingaid(request):
    form = FindCollection(request.POST)
    if not form.is_valid():
        messages.error(request, 'Form is not valid; please try again.')
    else:
        data = form.cleaned_data
        q = CollectionObject.item_collection_query()
        # submitted value is pid alias; lookup pid for solr query
        archive_id = settings.PID_ALIASES[data['archive']]
        q = q.query(archive_id=archive_id,
                    source_id=data['collection'])
        # if collection is found, redirect to collection view with message
        if q.count():
            messages.info(request, 'Found %d collection%s for %s %s.' %
                          (q.count(), 's' if q.count() != 1 else '',
                           data['archive'].upper(), data['collection']))
            return HttpResponseSeeOtherRedirect(reverse('collection:view',
                kwargs={'pid': q[0]['pid']}))

        else:
            # otherwise, create the new record and redirect to new
            # collection edit page
            repo = Repository(request=request)
            coll_id = data['collection']
            coll = None
            try:
                archive = repo.get_object(archive_id, type=CollectionObject)
                fa = FindingAid.find_by_unitid(unicode(coll_id),
                                               archive.mods.content.title)
                coll = fa.generate_collection()
                coll.collection = archive
                coll.save()
                messages.info(request, 'Added %s for collection %s: %s'
                              % (coll, coll_id, coll.mods.content.title))

                return HttpResponseSeeOtherRedirect(
                    reverse('collection:edit', kwargs={'pid': coll.pid}))

            except DoesNotExist:
                messages.error(request, 'No EAD found for %s in %s' %
                               (coll_id, data['archive'].upper()))
            except ReturnedMultiple:
                messages.error(request, 'Multiple EADs found for %s in %s' %
                               (coll_id, data['archive'].upper()))
            except RequestFailed as err:
                print err
                messages.error(request, 'Failed to save new collection')

    return HttpResponseSeeOtherRedirect(reverse('repo-admin:dashboard'))
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:51,代码来源:views.py

示例12: tasks

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import get_object [as 别名]
def tasks(request, pid):
    '''Manage tasks associated with an :class:`~keep.audio.models.AudioObject`.
    Currently, the only supported functionality is to queue access
    copy conversion; this should be done by POSTing the type of task to
    be queued, i.e. **generate access copy**.

    Supported tasks:

        * **generate access copy** - queue access copy conversion for an audio
            item by pid.  Returns a status message as the body of a plain/text response

    :param pid: the pid of the object for which tasks should be queued

    '''
    if request.method == 'POST':
        status = "queued"
        task_type = request.POST.get('task', None)

        # TODO May want to prevent queuing of more than one at a time or within a time period.
        # TODO For now javascript disables the link until the page is refreshed.

        # currently the only supported task is
        if task_type == 'generate access copy':
            try:
                repo = Repository(request=request)
                obj = repo.get_object(pid, type=AudioObject)

                # if object doesn't exist or isn't an audio item, 404
                if not obj.exists or not obj.has_requisite_content_models:
                    raise Http404

                queue_access_copy(obj)
                status = 'Successfully queued access copy conversion'

            except Exception as err:
                # re-raise any 404 error
                if isinstance(err, Http404):
                    raise

                logger.error('Error queueing access copy conversion for %s : %s' % \
                    (pid, err))
                status = 'Error queueing access copy conversion (%s)' % err

            return HttpResponse(status, content_type='text/plain')

        # unsupported task
        else:
            return HttpResponse('Task "%s" is not supported' % task_type,
                content_type='text/plain', status=500)
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:51,代码来源:views.py

示例13: find_by_field

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import get_object [as 别名]
    def find_by_field(field, value, repo=None):
        '''
        Static method to find a single :class:`EmailMessage` by an indexed
        value.  Looks for the item in Solr and
        returns an :class:`EmailMessage` instance initialized
        from the repository if a single match is found for the
        requested field and value.

        Raises :class:`django.core.exceptions.MultipleObjectsReturned`
        if more than one match is found; raises
        :class:`django.core.exceptions.ObjectDoesNotExist` if no
        matches are found in the Solr index.

        :param field: solr field to search
        :param value: value to search on in the specified field

        :param repo: optional :class:`eulfedora.server.Repository`
            to use an existing connection with specific credentials

        :returns: :class:`EmailMessage`


        '''
        solr = solr_interface()
        search_terms = {
            field: value,
            'content_model': ArrangementObject.ARRANGEMENT_CONTENT_MODEL
        }
        q = solr.query(**search_terms).field_limit('pid')

        # check that we found one and only one
        found = len(q)
        # borrowing custom django exceptions for not found / too many
        # matches
        if found > 1:
            raise MultipleObjectsReturned('Found %d records with %s %s' % \
                                          (found, field, value))
        if not found:
            raise ObjectDoesNotExist('No record found with %s %s' % (field, value))

        if repo is None:
            repo = Repository()

        return repo.get_object(q[0]['pid'], type=EmailMessage)
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:46,代码来源:models.py

示例14: disk_images

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import get_object [as 别名]
    def disk_images(self):
        self.stderr.write('Disk images')
        ### disk images
        # representative sample of aff and ad1
        # DO NOT include anything in these collections:
        # Trethewey (ghsdj), Rushdie (94k9k), Mackey (g1btw),
        # Clifton (94kf4), and Grennan (9k0st)

        solr = solr_interface()
        repo = Repository()
        q = solr.query(content_model=DiskImage.DISKIMAGE_CONTENT_MODEL) \
                .exclude(collection_id=self.collections['trethewey']) \
                .exclude(collection_id=self.collections['rushdie']) \
                .exclude(collection_id=self.collections['mackey']) \
                .exclude(collection_id=self.collections['clifton']) \
                .exclude(collection_id=self.collections['grennan']) \
                .field_limit('pid')
        if self.verbosity >= self.v_normal:
            self.stderr.write('Found %d disk images not in restricted collections' % q.count())

        # currently there is no way to filter on format or size in either
        # solr or fedora risearch
        # so, go through individually and group them by type,
        # then sort by size and pick the smallest ones
        diskimgs_by_type = defaultdict(list)
        for result in q:
            diskimg = repo.get_object(result['pid'], type=DiskImage)
            if not diskimg.exists:
                if self.verbosity >= self.v_normal:
                    self.stderr.write('Referenced disk image %s does not exist or is inaccessible' \
                        % result['pid'])
                continue

            fmt = diskimg.provenance.content.object.format.name
            diskimgs_by_type[fmt].append(diskimg)

        for fmt, diskimages in diskimgs_by_type.iteritems():
            if self.verbosity >= self.v_normal:
                self.stderr.write('Selecting %s disk images' % fmt)
            # sort on binary file size so we sync the smallest ones
            diskimages = sorted(diskimages, key=lambda diskimg: diskimg.content.size)
            # use the first 10 of each type
            for d in diskimages[:10]:
                self.stdout.write(d.pid)
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:46,代码来源:select_test_pids.py

示例15: playlist

# 需要导入模块: from keep.common.fedora import Repository [as 别名]
# 或者: from keep.common.fedora.Repository import get_object [as 别名]
def playlist(request, pid):
    # FIXME: this needs last-modified so browser can cache!!!

    # NOTE: preliminary logic duplicated from view above
    repo = Repository(request=request)
    obj = repo.get_object(pid, type=CollectionObject)
    # if pid doesn't exist or isn't a collection, 404
    if not obj.exists or not obj.has_requisite_content_models:
        raise Http404

    # search for all items that belong to this collection
    q = obj.solr_items_query()
    q = q.sort_by('date_created') \
         .sort_by('date_issued') \
         .sort_by('title_exact')
    # filter by logged-in user permissions
    # (includes researcher-accessible content filter when appropriate)
    q = filter_by_perms(q, request.user)

    # if current user can only view researcher-accesible collections and
    # no items were found, they don't have permission to view this collection
    if not request.user.has_perm('collection.view_collection') and \
           request.user.has_perm('collection.view_researcher_collection') and \
           q.count() == 0:
       return prompt_login_or_403(request)

    playlist = []
    for result in q:
        # skip non-audio or audio without access copies
        if result['object_type'] != 'audio' or not result['has_access_copy']:
            continue
        data = {
            'title': result['title'],
            'free': False  # explicitly mark as not downloadable
        }
        if result['access_copy_mimetype'] == 'audio/mp4':
            audio_type = 'm4a'
        else:
            audio_type = 'mp3'
        data[audio_type] = reverse('audio:download-compressed-audio',
            kwargs={'pid': result['pid'], 'extension': audio_type})
        playlist.append(data)

    return HttpResponse(json.dumps(playlist), content_type='application/json')
开发者ID:emory-libraries,项目名称:TheKeep,代码行数:46,代码来源:views.py


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