Пример #1
0
def save_publication(publication, status='publishing'):
    """Save publication."""
    publication['projectId'] = publication['project']['value']['projectId']
    publication['created'] = datetime.datetime.now().isoformat()
    publication['status'] = status
    publication['version'] = 2
    publication['licenses'] = publication.pop('license', [])
    publication['license'] = ''
    try:
        pub = IndexedPublication.from_id(publication['projectId'])
        pub.update(**publication)
    except DocumentNotFound:
        pub = IndexedPublication(project_id=publication['projectId'],
                                 **publication)
        pub.save()
    pub.save()
    return pub
Пример #2
0
def initilize_publication(publication,
                          status='publishing',
                          revision=None,
                          revision_text=None,
                          revision_titles=None):
    """initilize publication."""
    publication['projectId'] = publication['project']['value']['projectId']
    publication['status'] = status
    publication['version'] = 2
    publication['licenses'] = publication.pop('license', [])
    publication['license'] = ''
    es_client = new_es_client()
    if revision:
        base_pub = IndexedPublication.from_id(publication['projectId'],
                                              revision=None,
                                              using=es_client)
        publication['created'] = base_pub['created']
        publication['revision'] = revision
        publication['revisionDate'] = datetime.datetime.now().isoformat()
        publication['revisionText'] = revision_text
        if revision_titles:
            publication['revisionTitles'] = revision_titles
    elif 'created' not in publication:
        publication['created'] = datetime.datetime.now().isoformat()
    try:
        pub = IndexedPublication.from_id(publication['projectId'],
                                         revision=revision,
                                         using=es_client)
        pub.update(using=es_client, **publication)
    except DocumentNotFound:
        pub = IndexedPublication(project_id=publication['projectId'],
                                 **publication)
        pub.save(using=es_client)
    pub.save(using=es_client)

    # Refresh index so that search works in subsequent pipeline operations.
    IndexedPublication._index.refresh(using=es_client)
    return pub