From 92e12ae83ca39abdb0f7c318c916c0ac52476844 Mon Sep 17 00:00:00 2001
From: Tim Van Baak
Date: Thu, 30 Jan 2020 23:21:16 -0800
Subject: [PATCH] Fix CLI character creation
---
amanuensis/cli/lexicon.py | 25 ++++++++++++----------
amanuensis/cli/user.py | 2 +-
amanuensis/templates/lexicon/settings.html | 24 +++++++++++----------
3 files changed, 28 insertions(+), 23 deletions(-)
diff --git a/amanuensis/cli/lexicon.py b/amanuensis/cli/lexicon.py
index f6364c7..d0e21ba 100644
--- a/amanuensis/cli/lexicon.py
+++ b/amanuensis/cli/lexicon.py
@@ -1,3 +1,7 @@
+# Standard library imports
+import json
+
+# Module imports
from amanuensis.cli.helpers import (
add_argument, no_argument, requires_lexicon, requires_user, alias,
config_get, config_set, CONFIG_GET_ROOT_VALUE)
@@ -199,7 +203,7 @@ def command_player_list(args):
@alias('lcc')
@requires_lexicon
-# @requires_username
+@requires_user
@add_argument("--charname", required=True, help="The character's name")
def command_char_create(args):
"""
@@ -214,18 +218,17 @@ def command_char_create(args):
from amanuensis.user import UserModel
# Verify arguments
- u = UserModel.by(name=args.username)
- if u is None:
- logger.error("Could not find user '{}'".format(args.username))
+ if args.user.id not in args.lexicon.join.joined:
+ logger.error('"{0.username}" is not a player in lexicon "{1.name}"'
+ ''.format(args.user, args.lexicon))
return -1
- lex = LexiconModel.by(name=args.lexicon)
- if lex is None:
- logger.error("Could not find lexicon '{}'".format(args.lexicon))
- return -1
- # u in lx TODO
- # Internal call
- add_character(lex, u, {"name": args.charname})
+ # Perform command
+ add_character(args.lexicon, args.user, {"name": args.charname})
+
+ # Output
+ logger.info('Created character "{0.charname}" for "{0.user.username}" in '
+ '"{0.lexicon.name}"'.format(args))
return 0
diff --git a/amanuensis/cli/user.py b/amanuensis/cli/user.py
index acce9b6..e080f24 100644
--- a/amanuensis/cli/user.py
+++ b/amanuensis/cli/user.py
@@ -1,4 +1,4 @@
-# Standard imports
+# Standard library imports
import getpass
import os
import shutil
diff --git a/amanuensis/templates/lexicon/settings.html b/amanuensis/templates/lexicon/settings.html
index a606957..dae5b75 100644
--- a/amanuensis/templates/lexicon/settings.html
+++ b/amanuensis/templates/lexicon/settings.html
@@ -8,18 +8,20 @@
Created: {{ g.lexicon.time.created|asdate }}
Completed: {{ g.lexicon.time.completed|asdate }}
Players:
- {% for uid in g.lexicon.join.joined[:-1] %}
- {{ uid|user_attr('username') }},
- {% endfor %}
- {{ g.lexicon.join.joined[-1]|user_attr('username') }}
- Log:
-
- {% for log_entry in g.lexicon.log %}
- [{{ log_entry[0]|asdate }}] {{ log_entry[1] }}
- {% endfor %}
-
+ {% for uid in g.lexicon.join.joined %}
+ {{ uid|user_attr('username') }}{% if not loop.last %},{% endif %}
+ {% endfor %}
+ Characters:
+ {% for char in g.lexicon.character.values() %}
+ {{ char.name }} ({{ char.player|user_attr('username') }}){% if not loop.last %},{% endif %}
+ {% endfor %}
+
+ {% for log_entry in g.lexicon.log %}
+ [{{ log_entry[0]|asdate }}] {{ log_entry[1] }}
+ {% endfor %}
+
{% endblock %}
{% macro number_setting(field) %}