-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from Connexions/collate
Collation
- Loading branch information
Showing
12 changed files
with
558 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- coding: utf-8 -*- | ||
# ### | ||
# Copyright (c) 2016, Rice University | ||
# This software is subject to the provisions of the GNU Affero General | ||
# Public License version 3 (AGPLv3). | ||
# See LICENCE.txt for details. | ||
# ### | ||
"""Provides a means of collating a binder and persisting it to the archive.""" | ||
import cnxepub | ||
from cnxepub.collation import collate as collate_models | ||
|
||
from .db import with_db_cursor | ||
from .publish import ( | ||
publish_collated_document, | ||
publish_collated_tree, | ||
publish_composite_model, | ||
) | ||
|
||
|
||
@with_db_cursor | ||
def collate(binder, publisher, message, cursor): | ||
"""Given a `Binder` as `binder`, collate the contents and | ||
persist those changes alongside the published content. | ||
""" | ||
collate_models(binder) | ||
|
||
def flatten_filter(model): | ||
return isinstance(model, cnxepub.CompositeDocument) | ||
|
||
def only_documents_filter(model): | ||
return isinstance(model, cnxepub.Document) \ | ||
and not isinstance(model, cnxepub.CompositeDocument) | ||
|
||
for doc in cnxepub.flatten_to(binder, flatten_filter): | ||
publish_composite_model(cursor, doc, binder, publisher, message) | ||
|
||
for doc in cnxepub.flatten_to(binder, only_documents_filter): | ||
publish_collated_document(cursor, doc, binder) | ||
|
||
tree = cnxepub.model_to_tree(binder) | ||
publish_collated_tree(cursor, tree) | ||
|
||
return [] | ||
|
||
|
||
__all__ = ('collate',) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.