diff --git a/amanuensis/cli/__init__.py b/amanuensis/cli/__init__.py index eb9e111..1fa9234 100644 --- a/amanuensis/cli/__init__.py +++ b/amanuensis/cli/__init__.py @@ -50,7 +50,7 @@ def add_subcommand(subparsers, module) -> None: command_parser: ArgumentParser = subparsers.add_parser( command_name, help=command_help ) - command_parser.set_defaults(func=lambda args: command_parser.print_usage()) + command_parser.set_defaults(func=lambda args: command_parser.print_help()) # Add all subcommands in the command module subcommands = command_parser.add_subparsers(metavar="SUBCOMMAND") @@ -97,7 +97,7 @@ def main(): parser = ArgumentParser() parser.set_defaults( parser=parser, - func=lambda args: parser.print_usage(), + func=lambda args: parser.print_help(), get_db=None, ) parser.add_argument("--verbose", "-v", action="store_true", help="Verbose output") diff --git a/amanuensis/server/lexicon.jinja b/amanuensis/server/lexicon.jinja index 9c976eb..8393fc1 100644 --- a/amanuensis/server/lexicon.jinja +++ b/amanuensis/server/lexicon.jinja @@ -9,6 +9,10 @@ {% block sb_logo %}{% endblock %} {% block sb_home %}Home {% endblock %} +{% block sb_characters %}Characters{% endblock %} {% block sb_contents %}= g.lexicon.cfg.join.chars_per_player: +# flash("Can't create more characters") +# return redirect(url_for('session.session', name=name)) + +# if not form.is_submitted(): +# # GET, populate with default values +# return render_template( +# 'session.character.jinja', form=form.for_new()) + +# if not form.validate(): +# # POST with invalid data, return unchanged +# return render_template('session.character.jinja', form=form) + +# # POST with valid data, create character +# char_name = form.characterName.data +# cid = create_character_in_lexicon(current_user, g.lexicon, char_name) +# with g.lexicon.ctx.edit_config() as cfg: +# cfg.character[cid].signature = form.defaultSignature.data +# flash('Character created') +# return redirect(url_for('session.session', name=name)) + diff --git a/amanuensis/server/lexicon/characters/characters.jinja b/amanuensis/server/lexicon/characters/characters.jinja new file mode 100644 index 0000000..560fe93 --- /dev/null +++ b/amanuensis/server/lexicon/characters/characters.jinja @@ -0,0 +1,26 @@ +{% extends "lexicon.jinja" %} +{% block title %}Character | {{ lexicon_title }}{% endblock %} + +{% block main %} + +

Character

+{#
+ {{ form.hidden_tag() }} +

+ {{ form.characterName.label }}
{{ form.characterName(size=32) }} +

+ {% for error in form.characterName.errors %} + {{ error }}
+ {% endfor %}

+

+ {{ form.defaultSignature.label }}
{{ form.defaultSignature(class_='fullwidth') }} +

+

{{ form.submit() }}

+
#} + +{# {% for message in get_flashed_messages() %} +{{ message }}
+{% endfor %} #} + +{% endblock %} +{% set template_content_blocks = [self.main()] %} \ No newline at end of file diff --git a/amanuensis/server/session/__init__.py b/amanuensis/server/session/__init__.py index 743754d..2f1fdff 100644 --- a/amanuensis/server/session/__init__.py +++ b/amanuensis/server/session/__init__.py @@ -68,77 +68,6 @@ def session(name): publish_form=form) -def edit_character(name, form, character): - if not form.is_submitted(): - # GET, populate with values - return render_template( - 'session.character.jinja', form=form.for_character(character)) - - if not form.validate(): - # POST with invalid data, return unchanged - return render_template('session.character.jinja', form=form) - - # POST with valid data, update character - with g.lexicon.ctx.edit_config() as cfg: - char = cfg.character[character.cid] - char.name = form.characterName.data - char.signature = form.defaultSignature.data - flash('Character updated') - return redirect(url_for('session.session', name=name)) - - -def create_character(name: str, form: LexiconCharacterForm): - # Characters can't be created if the game has already started - if g.lexicon.status != LexiconModel.PREGAME: - flash("Characters can't be added after the game has started") - return redirect(url_for('session.session', name=name)) - # Characters can't be created beyond the per-player limit - player_characters = get_player_characters(g.lexicon, current_user.uid) - if len(list(player_characters)) >= g.lexicon.cfg.join.chars_per_player: - flash("Can't create more characters") - return redirect(url_for('session.session', name=name)) - - if not form.is_submitted(): - # GET, populate with default values - return render_template( - 'session.character.jinja', form=form.for_new()) - - if not form.validate(): - # POST with invalid data, return unchanged - return render_template('session.character.jinja', form=form) - - # POST with valid data, create character - char_name = form.characterName.data - cid = create_character_in_lexicon(current_user, g.lexicon, char_name) - with g.lexicon.ctx.edit_config() as cfg: - cfg.character[cid].signature = form.defaultSignature.data - flash('Character created') - return redirect(url_for('session.session', name=name)) - - -@bp_session.route('/character/', methods=['GET', 'POST']) -@lexicon_param -@player_required -def character(name): - form = LexiconCharacterForm() - cid = request.args.get('cid') - if not cid: - # No character specified, creating a new character - return create_character(name, form) - - character = g.lexicon.cfg.character.get(cid) - if not character: - # Bad character id, abort - flash('Character not found') - return redirect(url_for('session.session', name=name)) - if current_user.uid not in (character.player, g.lexicon.cfg.editor): - # Only its owner and the editor can edit a character - flash('Access denied') - return redirect(url_for('session.session', name=name)) - # Edit allowed - return edit_character(name, form, character) - - @bp_session.route('/settings/', methods=['GET', 'POST']) @lexicon_param @editor_required diff --git a/amanuensis/server/session/session.character.jinja b/amanuensis/server/session/session.character.jinja deleted file mode 100644 index 81b3036..0000000 --- a/amanuensis/server/session/session.character.jinja +++ /dev/null @@ -1,26 +0,0 @@ -{% extends "lexicon.jinja" %} -{% block title %}Character | {{ lexicon_title }}{% endblock %} - -{% block main %} - -

Character

-
- {{ form.hidden_tag() }} -

- {{ form.characterName.label }}
{{ form.characterName(size=32) }} -

- {% for error in form.characterName.errors %} - {{ error }}
- {% endfor %}

-

- {{ form.defaultSignature.label }}
{{ form.defaultSignature(class_='fullwidth') }} -

-

{{ form.submit() }}

-
- -{% for message in get_flashed_messages() %} -{{ message }}
-{% endfor %} - -{% endblock %} -{% set template_content_blocks = [self.main()] %} \ No newline at end of file