Add get_draft
This commit is contained in:
parent
d580949de0
commit
5ead3c02a8
@ -5,6 +5,7 @@ from .admin import (
|
||||
from .gameloop import (
|
||||
get_player_characters,
|
||||
get_player_drafts,
|
||||
get_draft,
|
||||
attempt_publish)
|
||||
from .setup import (
|
||||
player_can_join_lexicon,
|
||||
@ -17,6 +18,7 @@ __all__ = [member.__name__ for member in [
|
||||
load_all_lexicons,
|
||||
get_player_characters,
|
||||
get_player_drafts,
|
||||
get_draft,
|
||||
attempt_publish,
|
||||
player_can_join_lexicon,
|
||||
add_player_to_lexicon,
|
||||
|
@ -2,7 +2,7 @@
|
||||
Submodule of functions for managing lexicon games during the core game
|
||||
loop of writing and publishing articles.
|
||||
"""
|
||||
from typing import Iterable, Any, List
|
||||
from typing import Iterable, Any, List, Optional
|
||||
|
||||
from amanuensis.config import ReadOnlyOrderedDict
|
||||
from amanuensis.models import LexiconModel
|
||||
@ -45,6 +45,21 @@ def get_player_drafts(
|
||||
return drafts
|
||||
|
||||
|
||||
def get_draft(lexicon: LexiconModel, aid: str) -> Optional[ReadOnlyOrderedDict]:
|
||||
"""
|
||||
Loads an article from its id
|
||||
"""
|
||||
article_fn = None
|
||||
for filename in lexicon.ctx.draft.ls():
|
||||
if filename.endswith(f'{aid}.json'):
|
||||
article_fn = filename
|
||||
break
|
||||
if not article_fn:
|
||||
return None
|
||||
with lexicon.ctx.draft.read(article_fn) as article:
|
||||
return article
|
||||
|
||||
|
||||
def attempt_publish(lexicon: LexiconModel) -> None:
|
||||
"""
|
||||
If the lexicon's publsh policy allows the current set of approved
|
||||
|
Loading…
Reference in New Issue
Block a user