Exemple #1
0
def add_media(request, repository, title, description):
    """Create and add media.
    
    ``request``
        webob request
    ``repository``
        cone.mdb.model.RepositoryAdapter
    ``title``
        repository title
    ``description``
        repository description
    """
    keys = MediaKeys(repository.model.__name__)
    key = keys.next()
    keys.dump(key)
    repository.model[key] = Media()
    media = repository[key]
    media.metadata.uid = str(uuid.uuid4())
    media.metadata.title = title
    media.metadata.description = description
    media.metadata.creator = authenticated_userid(request)
    media.metadata.created = timestamp()
    media()
    index_media(media)
    return media
Exemple #2
0
def update_repository(request, repository, title, description):
    """Update existing repository.
    
    ``repository``
        cone.mdb.model.RepositoryAdapter
    ``title``
        new title
    ``description``
        new description
    """
    metadata = repository.metadata
    metadata.title = title
    metadata.description = description
    metadata.modified = timestamp()
    metadata.modified_by = authenticated_userid(request)
    repository()
Exemple #3
0
def update_media(request, media, title, description):
    """Update existing media.
    
    ``media``
        cone.mdb.model.MediaAdapter
    ``title``
        new title
    ``description``
        new description
    """
    metadata = media.metadata
    metadata.title = title
    metadata.description = description
    metadata.modified = timestamp()
    metadata.modified_by = authenticated_userid(request)
    media()
    index_media(media)
Exemple #4
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
Exemple #5
0
def add_repository(request, repositories, id, title, description):
    """Create and add repository.
    
    ``request``
        webob request
    ``repositories``
        cone.mdb.model.Repositories
    ``id``
        new repository id
    ``title``
        repository title
    ``description``
        repository description
    """
    model = Repository(os.path.join(repositories.dbpath, id))
    repository = RepositoryAdapter(model, None, None)
    metadata = repository.metadata
    metadata.title = title
    metadata.description = description
    metadata.creator = authenticated_userid(request)
    metadata.created = timestamp()
    repository()
    return repository