Add character page and create/edit workflows #18

Merged
Jaculabilis merged 9 commits from tvb/character-page into develop 2021-08-29 15:15:45 +00:00
2 changed files with 33 additions and 0 deletions
Showing only changes of commit e480658ebe - Show all commits

View File

@ -5,6 +5,7 @@ import os
from typing import Callable
import amanuensis.cli.admin
import amanuensis.cli.character
import amanuensis.cli.lexicon
import amanuensis.cli.user
from amanuensis.db import DbContext
@ -108,6 +109,7 @@ def main():
# Add commands from cli submodules
subparsers = parser.add_subparsers(metavar="COMMAND")
add_subcommand(subparsers, amanuensis.cli.admin)
add_subcommand(subparsers, amanuensis.cli.character)
add_subcommand(subparsers, amanuensis.cli.lexicon)
add_subcommand(subparsers, amanuensis.cli.user)

View File

@ -0,0 +1,31 @@
import logging
from amanuensis.backend import lexiq, userq, charq
from amanuensis.db import DbContext, Character
from .helpers import add_argument
COMMAND_NAME = "char"
COMMAND_HELP = "Interact with characters."
LOG = logging.getLogger(__name__)
@add_argument("--lexicon", required=True)
@add_argument("--user", required=True)
@add_argument("--name", required=True)
def command_create(args) -> int:
"""
Create a character.
"""
db: DbContext = args.get_db()
lexicon = lexiq.try_from_name(db, args.lexicon)
if not lexicon:
raise ValueError("Lexicon does not exist")
user = userq.try_from_username(db, args.user)
if not user:
raise ValueError("User does not exist")
char: Character = charq.create(db, lexicon.id, user.id, args.name, signature=None)
LOG.info(f"Created {char.name} in {lexicon.full_title}")
return 0