Add settings page and basic settings #20
@ -27,7 +27,7 @@ def article_link(title):
|
||||
"""Get the url for a lexicon by its title"""
|
||||
return url_for(
|
||||
'lexicon.article',
|
||||
name=g.lexicon.name,
|
||||
lexicon_name=g.lexicon.name,
|
||||
title=filesafe_title(title))
|
||||
|
||||
|
||||
|
@ -34,7 +34,7 @@ def lexicon_param(route):
|
||||
@wraps(route)
|
||||
def with_lexicon(*args, **kwargs):
|
||||
db: DbContext = g.db
|
||||
name: str = kwargs.get('name')
|
||||
name: str = kwargs.get('lexicon_name')
|
||||
lexicon: Optional[Lexicon] = lexiq.try_from_name(db, name)
|
||||
if lexicon is None:
|
||||
flash(f"Couldn't find a lexicon with the name \"{name}\"")
|
||||
@ -71,7 +71,7 @@ def player_required(route):
|
||||
if not mem:
|
||||
flash("You must be a player to view this page")
|
||||
if lexicon.public:
|
||||
return redirect(url_for('lexicon.contents', name=lexicon.name))
|
||||
return redirect(url_for('lexicon.contents', lexicon_name=lexicon.name))
|
||||
else:
|
||||
return redirect(url_for('home.home'))
|
||||
return route(*args, **kwargs)
|
||||
@ -108,6 +108,6 @@ def editor_required(route):
|
||||
mem: Optional[Membership] = memq.try_from_ids(db, user.id, lexicon.id)
|
||||
if not mem or not mem.is_editor:
|
||||
flash("You must be the editor to view this page")
|
||||
return redirect(url_for('lexicon.contents', name=lexicon.name))
|
||||
return redirect(url_for('lexicon.contents', lexicon_name=lexicon.name))
|
||||
return route(*args, **kwargs)
|
||||
return editor_route
|
||||
|
@ -9,23 +9,23 @@
|
||||
{% block sb_logo %}{% endblock %}
|
||||
{% block sb_characters %}<a
|
||||
{% if current_page == "characters" %}class="current-page"
|
||||
{% else %}href="{{ url_for('lexicon.characters.list', name=g.lexicon.name) }}"
|
||||
{% else %}href="{{ url_for('lexicon.characters.list', lexicon_name=g.lexicon.name) }}"
|
||||
{% endif %}>Characters</a>{% endblock %}
|
||||
{% block sb_contents %}<a
|
||||
{% if current_page == "contents" %}class="current-page"
|
||||
{% else %}href="{{ url_for('lexicon.contents', name=g.lexicon.name) }}"
|
||||
{% else %}href="{{ url_for('lexicon.contents', lexicon_name=g.lexicon.name) }}"
|
||||
{% endif %}>Contents</a>{% endblock %}
|
||||
{% block sb_rules %}<a
|
||||
{% if current_page == "rules" %}class="current-page"
|
||||
{% else %}href="{{ url_for('lexicon.rules', name=g.lexicon.name) }}"
|
||||
{% else %}href="{{ url_for('lexicon.rules', lexicon_name=g.lexicon.name) }}"
|
||||
{% endif %}>Rules</a>{% endblock %}
|
||||
{% block sb_session %}<a
|
||||
{% if current_page == "session" %}class="current-page"
|
||||
{% else %}href="#{#{ url_for('session.session', name=g.lexicon.name) }#}"
|
||||
{% else %}href="#{#{ url_for('session.session', lexicon_name=g.lexicon.name) }}"
|
||||
{% endif %}>Session</a>{% endblock %}
|
||||
{% block sb_stats %}<a
|
||||
{% if current_page == "statistics" %}class="current-page"
|
||||
{% else %}href="{{ url_for('lexicon.stats', name=g.lexicon.name) }}"
|
||||
{% else %}href="{{ url_for('lexicon.stats', lexicon_name=g.lexicon.name) }}"
|
||||
{% endif %}>Statistics</a>{% endblock %}
|
||||
|
||||
{% if current_user.is_authenticated and (
|
||||
|
@ -10,14 +10,16 @@ from .characters import bp as characters_bp
|
||||
from .forms import LexiconJoinForm
|
||||
|
||||
|
||||
bp = Blueprint("lexicon", __name__, url_prefix="/lexicon/<name>", template_folder=".")
|
||||
bp = Blueprint(
|
||||
"lexicon", __name__, url_prefix="/lexicon/<lexicon_name>", template_folder="."
|
||||
)
|
||||
bp.register_blueprint(characters_bp)
|
||||
|
||||
|
||||
@bp.route("/join/", methods=["GET", "POST"])
|
||||
@lexicon_param
|
||||
@login_required
|
||||
def join(name):
|
||||
def join(lexicon_name):
|
||||
lexicon: Lexicon = g.lexicon
|
||||
if not lexicon.joinable:
|
||||
flash("This game isn't open for joining")
|
||||
@ -27,7 +29,9 @@ def join(name):
|
||||
|
||||
if not form.validate_on_submit():
|
||||
# GET or POST with invalid form data
|
||||
return render_template("lexicon.join.jinja", form=form)
|
||||
return render_template(
|
||||
"lexicon.join.jinja", lexicon_name=lexicon_name, form=form
|
||||
)
|
||||
|
||||
# POST with valid data
|
||||
# If the game is passworded, check password
|
||||
@ -37,48 +41,48 @@ def join(name):
|
||||
):
|
||||
# Bad creds, try again
|
||||
flash("Incorrect password")
|
||||
return redirect(url_for("lexicon.join", name=name))
|
||||
return redirect(url_for("lexicon.join", lexicon_name=lexicon_name))
|
||||
|
||||
# If the password was correct, check if the user can join
|
||||
user: User = current_user
|
||||
try:
|
||||
memq.create(db, user.id, lexicon.id, is_editor=False)
|
||||
return redirect(url_for("session.session", name=name))
|
||||
return redirect(url_for("session.session", lexicon_name=lexicon_name))
|
||||
except ArgumentError:
|
||||
flash("Could not join game")
|
||||
return redirect(url_for("home.home", name=name))
|
||||
return redirect(url_for("home.home", lexicon_name=lexicon_name))
|
||||
|
||||
|
||||
@bp.get("/contents/")
|
||||
@lexicon_param
|
||||
@player_required_if_not_public
|
||||
def contents(name):
|
||||
def contents(lexicon_name):
|
||||
# indexed = sort_by_index_spec(info, g.lexicon.cfg.article.index.list)
|
||||
# for articles in indexed.values():
|
||||
# for i in range(len(articles)):
|
||||
# articles[i] = {
|
||||
# 'title': articles[i],
|
||||
# **info.get(articles[i])}
|
||||
return render_template("lexicon.contents.jinja")
|
||||
return render_template("lexicon.contents.jinja", lexicon_name=lexicon_name)
|
||||
|
||||
|
||||
@bp.get("/article/<title>")
|
||||
@lexicon_param
|
||||
@player_required_if_not_public
|
||||
def article(name, title):
|
||||
def article(lexicon_name, title):
|
||||
# article = {**a, 'html': Markup(a['html'])}
|
||||
return render_template("lexicon.article.jinja")
|
||||
return render_template("lexicon.article.jinja", lexicon_name=lexicon_name)
|
||||
|
||||
|
||||
@bp.get("/rules/")
|
||||
@lexicon_param
|
||||
@player_required_if_not_public
|
||||
def rules(name):
|
||||
return render_template("lexicon.rules.jinja")
|
||||
def rules(lexicon_name):
|
||||
return render_template("lexicon.rules.jinja", lexicon_name=lexicon_name)
|
||||
|
||||
|
||||
@bp.get("/statistics/")
|
||||
@lexicon_param
|
||||
@player_required_if_not_public
|
||||
def stats(name):
|
||||
return render_template("lexicon.statistics.jinja")
|
||||
def stats(lexicon_name):
|
||||
return render_template("lexicon.statistics.jinja", lexicon_name=lexicon_name)
|
||||
|
@ -18,18 +18,18 @@ bp = Blueprint("characters", __name__, url_prefix="/characters", template_folder
|
||||
@bp.get("/")
|
||||
@lexicon_param
|
||||
@player_required
|
||||
def list(name):
|
||||
return render_template("characters.jinja", name=name)
|
||||
def list(lexicon_name):
|
||||
return render_template("characters.jinja", lexicon_name=lexicon_name)
|
||||
|
||||
|
||||
@bp.route("/edit/<uuid:character_id>", methods=["GET", "POST"])
|
||||
@lexicon_param
|
||||
@player_required
|
||||
def edit(name, character_id: uuid.UUID):
|
||||
def edit(lexicon_name, character_id: uuid.UUID):
|
||||
character: Optional[Character] = charq.try_from_public_id(g.db, character_id)
|
||||
if not character:
|
||||
flash("Character not found")
|
||||
return redirect(url_for("lexicon.characters.list", name=name))
|
||||
return redirect(url_for("lexicon.characters.list", lexicon_name=lexicon_name))
|
||||
|
||||
form = CharacterCreateForm()
|
||||
|
||||
@ -37,7 +37,12 @@ def edit(name, character_id: uuid.UUID):
|
||||
# GET
|
||||
form.name.data = character.name
|
||||
form.signature.data = character.signature
|
||||
return render_template("characters.edit.jinja", character=character, form=form)
|
||||
return render_template(
|
||||
"characters.edit.jinja",
|
||||
lexicon_name=lexicon_name,
|
||||
character=character,
|
||||
form=form,
|
||||
)
|
||||
|
||||
else:
|
||||
# POST
|
||||
@ -46,24 +51,33 @@ def edit(name, character_id: uuid.UUID):
|
||||
character.name = form.name.data
|
||||
character.signature = form.signature.data
|
||||
g.db.session.commit()
|
||||
return redirect(url_for("lexicon.characters.list", name=name))
|
||||
return redirect(
|
||||
url_for("lexicon.characters.list", lexicon_name=lexicon_name)
|
||||
)
|
||||
|
||||
else:
|
||||
# POST submitted invalid data
|
||||
return render_template(
|
||||
"characters.edit.jinja", character=character, form=form
|
||||
"characters.edit.jinja",
|
||||
lexicon_name=lexicon_name,
|
||||
character=character,
|
||||
form=form,
|
||||
)
|
||||
|
||||
|
||||
@bp.get("/new/")
|
||||
@lexicon_param
|
||||
@player_required
|
||||
def new(name):
|
||||
def new(lexicon_name):
|
||||
dummy_name = f"{current_user.username}'s new character"
|
||||
dummy_signature = "~"
|
||||
char = charq.create(
|
||||
g.db, g.lexicon.id, current_user.id, dummy_name, dummy_signature
|
||||
)
|
||||
return redirect(
|
||||
url_for("lexicon.characters.edit", name=name, character_id=char.public_id)
|
||||
url_for(
|
||||
"lexicon.characters.edit",
|
||||
lexicon_name=lexicon_name,
|
||||
character_id=char.public_id,
|
||||
)
|
||||
)
|
||||
|
@ -13,7 +13,7 @@
|
||||
<ul class="blockitem-list">
|
||||
{% if characters|map(attribute="user_id")|select("equalto", current_user.id)|list|count < g.lexicon.character_limit %}
|
||||
<li>
|
||||
<h3><a href="{{ url_for('lexicon.characters.new', name=name) }}">Create a new character</a></h3>
|
||||
<h3><a href="{{ url_for('lexicon.characters.new', lexicon_name=lexicon_name) }}">Create a new character</a></h3>
|
||||
<p>You have created {{ characters|map(attribute="user_id")|select("equalto", current_user.id)|list|count }} out of {{ g.lexicon.character_limit }} allowed characters.</p>
|
||||
</li>
|
||||
{% endif %}
|
||||
@ -25,7 +25,7 @@
|
||||
{% endif %}
|
||||
<p>Player: {{ character.user.username }}</p>
|
||||
{% if character.user == current_user %}
|
||||
<p><a href="{{ url_for('lexicon.characters.edit', name=g.lexicon.name, character_id=character.public_id) }}">Edit this character</a></p>
|
||||
<p><a href="{{ url_for('lexicon.characters.edit', lexicon_name=lexicon_name, character_id=character.public_id) }}">Edit this character</a></p>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
@ -3,7 +3,7 @@
|
||||
<div class="dashboard-lexicon-item dashboard-lexicon-{{ status }}">
|
||||
<p>
|
||||
<span class="dashboard-lexicon-item-title">
|
||||
<a href="{{ url_for('lexicon.contents', name=lexicon.name) }}">{{ lexicon.full_title }}</a>
|
||||
<a href="{{ url_for('lexicon.contents', lexicon_name=lexicon.name) }}">{{ lexicon.full_title }}</a>
|
||||
</span>
|
||||
[{{ status.capitalize() }}]
|
||||
</p>
|
||||
@ -29,7 +29,7 @@
|
||||
Players: {{ lexicon.memberships|count }}{% if lexicon.player_limit is not none %} / {{ lexicon.player_limit }}{% endif -%}
|
||||
{%-
|
||||
if lexicon.public and lexicon.joinable
|
||||
%} / <a href="{{ url_for('lexicon.join', name=lexicon.name) }}">Join game</a>
|
||||
%} / <a href="{{ url_for('lexicon.join', lexicon_name=lexicon.name) }}">Join game</a>
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
</p>
|
||||
|
@ -32,12 +32,12 @@ def test_character_view(db: DbContext, app: Flask, make: ObjectFactory):
|
||||
assert mem
|
||||
|
||||
# The character page exists
|
||||
list_url = url_for("lexicon.characters.list", name=lexicon.name)
|
||||
list_url = url_for("lexicon.characters.list", lexicon_name=lexicon.name)
|
||||
response = client.get(list_url)
|
||||
assert response.status_code == 200
|
||||
assert charname.encode("utf8") not in response.data
|
||||
assert char_sig.encode("utf8") not in response.data
|
||||
new_url = url_for("lexicon.characters.new", name=lexicon.name)
|
||||
new_url = url_for("lexicon.characters.new", lexicon_name=lexicon.name)
|
||||
assert new_url.encode("utf8") in response.data
|
||||
|
||||
# The character creation endpoint works
|
||||
|
Loading…
Reference in New Issue
Block a user