Exemplo n.º 1
0
def search(request):
    root = get_root()
    config = solr_config(root)
    result = list()
    term = '%s*~' % request.matchdict['term']
    query = Term('type', 'Media') \
          & Group(Term('title', term) \
                | Term('description', term) \
                | Term('creator', term))
    fl = 'uid,title,description,repository'
    for md in Metadata(config, SOLR_FIELDS).query(q=query, fl=fl):
        suid = str(base62(int(uuid.UUID(md.uid))))
        result.append({
            'suid': suid,
            'uid': md.uid,
            'title': md.title,
            'description': md.description,
            'repository': md.repository,
            'revisions': list(),
        })
        rev_query = Term('suid', suid) & Term('visibility', 'anonymous')
        fl = revision_info_fl
        for rev_md in Metadata(config, SOLR_FIELDS).query(q=rev_query, fl=fl):
            if not chk_publication(rev_md):
                continue
            result[-1]['revisions'].append(revision_info(rev_md))
    return result
Exemplo n.º 2
0
def add_revision(request, media, data):
    """Add revision to media.
    
    ``request``
        webob request
    ``media``
        cone.mdb.model.Media
    ``data``
        revision data
    """
    keys = [int(key) for key in media.keys()]
    keys.sort()
    if keys:
        key = str(keys[-1] + 1)
    else:
        key = '0'
    revision = MDBRevision()
    mdb_media = media.model
    mdb_media[key] = revision
    metadata = MDBMetadata()
    revision['metadata'] = metadata
    metadata.revision = key
    uid = uuid.uuid4()
    metadata.uid = str(uid)
    metadata.suid = str(base62(int(uid)))
    metadata.created = timestamp()
    metadata.creator = authenticated_userid(request)
    set_binary(revision, data)
    set_metadata(metadata, data)
    metadata.size = size(len(revision['binary'].payload), system=alternative)
    
    revision_adapter = media[revision.__name__]
    wf_name = revision_adapter.properties.wf_name
    workflow = get_workflow(RevisionAdapter, wf_name)
    workflow.initialize(revision_adapter)
    
    media()
    index_revision(revision_adapter)
    return revision_adapter