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


Python Collection.from_identifier方法代码示例

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


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

示例1: signatures

# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_identifier [as 别名]
def signatures(collection_path, git_name, git_mail):
    """Identifies signature files for collection and entities.
    
    @param collection_path: Absolute path to collection repo.
    @param git_name: Username of git committer.
    @param git_mail: Email of git committer.
    @return collection_path: Absolute path to collection.
    """
    gitstatus.lock(settings.MEDIA_BASE, 'collection_signatures')
    collection = Collection.from_identifier(Identifier(path=collection_path))
    updates = signatures.find_updates(collection)
    files_written = signatures.write_updates(updates)

    # TODO move this code to webui.models.Collection
    status,msg = signatures.commit_updates(
        collection,
        files_written,
        git_name, git_mail, agent='ddr-local'
    )
    logger.debug('DONE')
    logger.debug('Updating Elasticsearch')
    if settings.DOCSTORE_ENABLED:
        collection = Collection.from_identifier(Identifier(path=collection_path))
        try:
            collection.post_json()
        except ConnectionError:
            logger.error('Could not update search index')
    
    return collection_path
开发者ID:densho,项目名称:ddr-local,代码行数:31,代码来源:collection.py

示例2: delete_file

# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_identifier [as 别名]
def delete_file( git_name, git_mail, collection_path, entity_id, file_basename, agent='' ):
    """
    @param collection_path: string
    @param entity_id: string
    @param file_basename: string
    @param git_name: Username of git committer.
    @param git_mail: Email of git committer.
    @param agent: (optional) Name of software making the change.
    """
    logger.debug('delete_file(%s,%s,%s,%s,%s,%s)' % (git_name, git_mail, collection_path, entity_id, file_basename, agent))
    gitstatus.lock(settings.MEDIA_BASE, 'delete_file')
    file_id = os.path.splitext(file_basename)[0]
    file_ = DDRFile.from_identifier(Identifier(file_id))
    entity = Entity.from_identifier(Identifier(entity_id))
    collection = Collection.from_identifier(Identifier(path=collection_path))
    logger.debug('delete from repository')
    rm_files,updated_files = entity.prep_rm_file(file_)
    status,message = commands.file_destroy(
        git_name, git_mail,
        collection, entity,
        rm_files, updated_files,
        agent
    )
    logger.debug('delete from search index')
    try:
        docstore.delete(settings.DOCSTORE_HOSTS, settings.DOCSTORE_INDEX, file_.id)
    except ConnectionError:
        logger.error('Could not delete document from Elasticsearch.')
    return status,message,collection_path,file_basename
开发者ID:,项目名称:,代码行数:31,代码来源:

示例3: collections

# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_identifier [as 别名]
def collections( request ):
    """
    We are displaying collection status vis-a-vis the project Gitolite server.
    It takes too long to run git-status on every repo so, if repo statuses are not
    cached they will be updated by jQuery after page load has finished.
    """
    collections = []
    collection_status_urls = []
    for object_id in gitolite.get_repos_orgs():
        identifier = Identifier(object_id)
        # TODO Identifier: Organization object instead of repo and org
        repo,org = identifier.parts.values()
        collection_paths = Collection.collection_paths(settings.MEDIA_BASE, repo, org)
        colls = []
        for collection_path in collection_paths:
            if collection_path:
                identifier = Identifier(path=collection_path)
                collection = Collection.from_identifier(identifier)
                colls.append(collection)
                gitstatus = collection.gitstatus()
                if gitstatus and gitstatus.get('sync_status'):
                    collection.sync_status = gitstatus['sync_status']
                else:
                    collection_status_urls.append( "'%s'" % collection.sync_status_url())
        collections.append( (object_id,repo,org,colls) )
    # load statuses in random order
    random.shuffle(collection_status_urls)
    return render_to_response(
        'webui/collections/index.html',
        {'collections': collections,
         'collection_status_urls': ', '.join(collection_status_urls),},
        context_instance=RequestContext(request, processors=[])
    )
开发者ID:,项目名称:,代码行数:35,代码来源:

示例4: csv_export

# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_identifier [as 别名]
def csv_export( request, cid, model=None ):
    """
    """
    if (not model) or (not (model in ['entity','file'])):
        raise Http404
    collection = Collection.from_identifier(Identifier(cid))
    things = {'entity':'objects', 'file':'files'}
    csv_path = settings.CSV_EXPORT_PATH[model] % collection.id
    csv_filename = os.path.basename(csv_path)
    if model == 'entity':
        file_url = reverse('webui-collection-csv-entities', args=[collection.id])
    elif model == 'file':
        file_url = reverse('webui-collection-csv-files', args=[collection.id])
    # do it
    result = collection_tasks.csv_export_model.apply_async(
        (collection.path,model),
        countdown=2
    )
    # add celery task_id to session
    celery_tasks = request.session.get(settings.CELERY_TASKS_SESSION_KEY, {})
    # IMPORTANT: 'action' *must* match a message in webui.tasks.TASK_STATUS_MESSAGES.
    task = {'task_id': result.task_id,
            'action': 'csv-export-model',
            'collection_id': collection.id,
            'collection_url': collection.absolute_url(),
            'things': things[model],
            'file_name': csv_filename,
            'file_url': file_url,
            'start': converters.datetime_to_text(datetime.now(settings.TZ)),}
    celery_tasks[result.task_id] = task
    request.session[settings.CELERY_TASKS_SESSION_KEY] = celery_tasks
    return HttpResponseRedirect(collection.absolute_url())
开发者ID:densho,项目名称:ddr-local,代码行数:34,代码来源:collections.py

示例5: csv_download

# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_identifier [as 别名]
def csv_download( request, cid, model=None ):
    """Offers CSV file in settings.CSV_TMPDIR for download.
    
    File must actually exist in settings.CSV_EXPORT_PATH and be readable.
    File must be readable by Python csv module.
    If all that is true then it must be a legal CSV file.
    """
    collection = Collection.from_identifier(Identifier(cid))
    path = settings.CSV_EXPORT_PATH[model] % collection.id
    filename = os.path.basename(path)
    if not os.path.exists(path):
        raise Http404
    import csv
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    writer = csv.writer(
        response,
        delimiter=fileio.CSV_DELIMITER,
        quotechar=fileio.CSV_QUOTECHAR,
        quoting=fileio.CSV_QUOTING
    )
    with open(path, 'rb') as f:
        reader = csv.reader(
            f,
            delimiter=fileio.CSV_DELIMITER,
            quotechar=fileio.CSV_QUOTECHAR,
            quoting=fileio.CSV_QUOTING
        )
        for row in reader:
            writer.writerow(row)
    return response
开发者ID:densho,项目名称:ddr-local,代码行数:33,代码来源:collections.py

示例6: after_return

# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_identifier [as 别名]
 def after_return(self, status, retval, task_id, args, kwargs, einfo):
     logger.debug('EntityNewExpertTask.after_return(%s, %s, %s, %s, %s)' % (status, retval, task_id, args, kwargs))
     collection_path = args[0]
     collection = Collection.from_identifier(Identifier(path=collection_path))
     lockstatus = collection.unlock(task_id)
     gitstatus.update(settings.MEDIA_BASE, collection.path)
     gitstatus.unlock(settings.MEDIA_BASE, 'entity_newexpert')
开发者ID:,项目名称:,代码行数:9,代码来源:

示例7: save

# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_identifier [as 别名]
def save(collection_path, cleaned_data, git_name, git_mail):
    """The time-consuming parts of collection-edit.
    
    @param collection_path: str Absolute path to collection
    @param cleaned_data: dict form.cleaned_data
    @param git_name: Username of git committer.
    @param git_mail: Email of git committer.
    """
    logger.debug('tasks.collection.save(%s,%s,%s)' % (
        git_name, git_mail, collection_path))
    
    collection = Collection.from_identifier(Identifier(path=collection_path))
    gitstatus.lock(settings.MEDIA_BASE, 'collection_edit')
    
    exit,status,updated_files = collection.save(
        git_name, git_mail,
        cleaned_data
    )
    
    dvcs_tasks.gitstatus_update.apply_async(
        (collection_path,),
        countdown=2
    )
    
    return status,collection_path
开发者ID:densho,项目名称:ddr-local,代码行数:27,代码来源:collection.py

示例8: sync

# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_identifier [as 别名]
def sync( git_name, git_mail, collection_path ):
    """Synchronizes collection repo with workbench server.
    
    @param git_name: Username of git committer.
    @param git_mail: Email of git committer.
    @param collection_path: Absolute path to collection repo.
    @return collection_path: Absolute path to collection.
    """
    gitstatus.lock(settings.MEDIA_BASE, 'collection_sync')
    ci = Identifier(path=collection_path)
    collection = Collection.from_identifier(ci)
    
    # TODO move this code to webui.models.Collection.sync
    exit,status = commands.sync(
        git_name, git_mail,
        collection
    )
    logger.debug('Updating Elasticsearch')
    if settings.DOCSTORE_ENABLED:
        try:
            collection.reindex()
        except ConnectionError:
            logger.error('Could not update search index')
    
    return collection_path
开发者ID:densho,项目名称:ddr-local,代码行数:27,代码来源:collection.py

示例9: entity_edit

# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_identifier [as 别名]
def entity_edit(collection_path, entity_id, form_data, git_name, git_mail, agent=''):
    """The time-consuming parts of entity-edit.
    
    @param collection_path: str Absolute path to collection
    @param entity_id: str
    @param form_data: dict
    @param git_name: Username of git committer.
    @param git_mail: Email of git committer.
    @param agent: (optional) Name of software making the change.
    """
    logger.debug('tasks.entity.entity_edit(%s,%s,%s,%s,%s)' % (
        git_name, git_mail, collection_path, entity_id, agent))
    collection = Collection.from_identifier(Identifier(path=collection_path))
    entity = Entity.from_identifier(Identifier(id=entity_id))
    gitstatus.lock(settings.MEDIA_BASE, 'entity_edit')
    
    exit,status,updated_files = entity.save(
        git_name, git_mail,
        collection,
        form_data
    )
    
    dvcs_tasks.gitstatus_update.apply_async(
        (collection.path,),
        countdown=2
    )
    return status,collection_path,entity_id
开发者ID:densho,项目名称:ddr-local,代码行数:29,代码来源:entity.py

示例10: sync_status_ajax

# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_identifier [as 别名]
def sync_status_ajax( request, cid ):
    collection = Collection.from_identifier(Identifier(cid))
    gitstatus = collection.gitstatus()
    if gitstatus:
        sync_status = gitstatus['sync_status']
        if sync_status.get('timestamp',None):
            sync_status['timestamp'] = converters.datetime_to_text(sync_status['timestamp'])
        return HttpResponse(json.dumps(sync_status), content_type="application/json")
    raise Http404
开发者ID:densho,项目名称:ddr-local,代码行数:11,代码来源:collections.py

示例11: after_return

# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_identifier [as 别名]
 def after_return(self, status, retval, task_id, args, kwargs, einfo):
     logger.debug('EntityReloadTask.after_return(%s, %s, %s, %s, %s)' % (status, retval, task_id, args, kwargs))
     collection_path = args[0]
     collection = Collection.from_identifier(Identifier(path=collection_path))
     entity_id = args[1]
     entity = Entity.from_identifier(Identifier(id=entity_id))
     lockstatus = entity.unlock(task_id)
     gitstatus.update(settings.MEDIA_BASE, collection_path)
     gitstatus.unlock(settings.MEDIA_BASE, 'reload_files')
开发者ID:densho,项目名称:ddr-local,代码行数:11,代码来源:entity.py

示例12: new_idservice

# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_identifier [as 别名]
def new_idservice( request, oid ):
    """Gets new EID from idservice, creates new entity record.
    
    If it messes up, goes back to collection.
    """
    git_name,git_mail = enforce_git_credentials(request)
    # note: oid could be either a Collection or an Entity
    collection = Collection.from_identifier(
        Identifier(oid).collection()
    )
    check_parent(collection)
    
    ic = idservice.IDServiceClient()
    # resume session
    auth_status,auth_reason = ic.resume(request.session['idservice_token'])
    if auth_status != 200:
        request.session['idservice_username'] = None
        request.session['idservice_token'] = None
        messages.warning(
            request,
            'Session resume failed: %s %s (%s)' % (
                auth_status,auth_reason,settings.IDSERVICE_API_BASE
            )
        )
        return HttpResponseRedirect(collection.absolute_url())
    
    # get new entity ID
    new_object_parent = Identifier(oid)
    model = request.GET.get('model', 'entity')
    ENTITY_MODELS = ['entity', 'segment']
    if model not in ENTITY_MODELS:
        raise Exception('Model "%s% not an entity model.' % model)
    http_status,http_reason,new_entity_id = ic.next_object_id(
        new_object_parent,
        model,
        register=True,
    )
    
    # abort!
    if http_status not in [200,201]:
        err = '%s %s' % (http_status, http_reason)
        msg = WEBUI_MESSAGES['VIEWS_ENT_ERR_NO_IDS'] % (settings.IDSERVICE_API_BASE, err)
        logger.error(msg)
        messages.error(request, msg)
        return HttpResponseRedirect(collection.absolute_url())
    
    # Create entity and redirect to edit page
    eidentifier = Identifier(id=new_entity_id)
    entity = _create_entity(request, eidentifier, collection, git_name, git_mail)
    if entity:
        return HttpResponseRedirect(reverse('webui-entity-edit', args=[entity.id]))
    
    # something happened...
    logger.error('Could not create new entity!')
    messages.error(request, WEBUI_MESSAGES['VIEWS_ENT_ERR_CREATE'])
    return HttpResponseRedirect(collection.absolute_url())
开发者ID:densho,项目名称:ddr-local,代码行数:58,代码来源:entities.py

示例13: detail

# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_identifier [as 别名]
def detail( request, cid ):
    collection = Collection.from_identifier(Identifier(cid))
    collection.model_def_commits()
    collection.model_def_fields()
    alert_if_conflicted(request, collection)
    return render(request, 'webui/collections/detail.html', {
        'collection': collection,
        'collection_unlock_url': collection.unlock_url(collection.locked()),
        # cache this for later
        'annex_info': annex_info(repository(collection.path_abs)),
    })
开发者ID:densho,项目名称:ddr-local,代码行数:13,代码来源:collections.py

示例14: unlock

# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_identifier [as 别名]
def unlock( request, cid, task_id ):
    """Provides a way to remove collection lockfile through the web UI.
    """
    git_name = request.session.get('git_name')
    git_mail = request.session.get('git_mail')
    if not git_name and git_mail:
        messages.error(request, WEBUI_MESSAGES['LOGIN_REQUIRED'])
    collection = Collection.from_identifier(Identifier(cid))
    if task_id and collection.locked() and (task_id == collection.locked()):
        collection.unlock(task_id)
        messages.success(request, 'Collection <b>%s</b> unlocked.' % collection.id)
    return HttpResponseRedirect(collection.absolute_url())
开发者ID:densho,项目名称:ddr-local,代码行数:14,代码来源:collections.py

示例15: collection_sync

# 需要导入模块: from webui.models import Collection [as 别名]
# 或者: from webui.models.Collection import from_identifier [as 别名]
def collection_sync( git_name, git_mail, collection_path ):
    """Synchronizes collection repo with workbench server.
    
    @param src_path: Absolute path to collection repo.
    @param git_name: Username of git committer.
    @param git_mail: Email of git committer.
    @return collection_path: Absolute path to collection.
    """
    gitstatus.lock(settings.MEDIA_BASE, 'collection_sync')
    collection = Collection.from_identifier(Identifier(path=collection_path))
    exit,status = commands.sync(
        git_name, git_mail,
        collection
    )
    # update search index
    collection = Collection.from_identifier(Identifier(path=collection_path))
    try:
        collection.post_json(settings.DOCSTORE_HOSTS, settings.DOCSTORE_INDEX)
    except ConnectionError:
        logger.error('Could not update search index')
    return collection_path
开发者ID:,项目名称:,代码行数:23,代码来源:


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