Compare commits
1 Commits
develop
...
nvb/create
Author | SHA1 | Date |
---|---|---|
Nikolai | 5b3e5663b7 |
|
@ -181,7 +181,7 @@ class Lexicon(ModelBase):
|
|||
################################
|
||||
|
||||
# Whether players can join the game
|
||||
joinable = Column(Boolean, nullable=False, default=False)
|
||||
joinable = Column(Boolean, nullable=False, default=True)
|
||||
|
||||
# Whether the game is listed on public pages
|
||||
public = Column(Boolean, nullable=False, default=False)
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
from flask import Blueprint, render_template, g
|
||||
from operator import le
|
||||
|
||||
from amanuensis.backend import userq, lexiq
|
||||
from sqlalchemy.sql.expression import true
|
||||
from amanuensis.db.models import Lexicon
|
||||
from flask import Blueprint, render_template, g, url_for, redirect
|
||||
|
||||
# from .forms import LexiconCreateForm
|
||||
from amanuensis.backend import userq, lexiq, memq
|
||||
|
||||
from .forms import LexiconCreateForm
|
||||
|
||||
bp = Blueprint("home", __name__, url_prefix="/home", template_folder=".")
|
||||
|
||||
|
@ -18,6 +22,34 @@ def home():
|
|||
def admin():
|
||||
return render_template("home.admin.jinja", userq=userq, lexiq=lexiq)
|
||||
|
||||
@bp.get("/admin/create/")
|
||||
def create():
|
||||
form = LexiconCreateForm()
|
||||
return render_template("home.create.jinja", form=form)
|
||||
|
||||
@bp.post("/admin/create/")
|
||||
def create_post():
|
||||
form = LexiconCreateForm()
|
||||
if form.validate():
|
||||
name = form.lexicon.data
|
||||
editor = userq.try_from_username(g.db, form.editor.data)
|
||||
prompt = form.prompt.data
|
||||
|
||||
assert editor is not None
|
||||
|
||||
lexicon = lexiq.create(g.db, name, None, prompt)
|
||||
new_membership = memq.create(g.db, editor.id, lexicon.id, is_editor=True)
|
||||
|
||||
lexicon.joinable = False
|
||||
g.db.session.commit()
|
||||
|
||||
return redirect(url_for("home.admin"))
|
||||
|
||||
else:
|
||||
return render_template("home.create.jinja", form=form)
|
||||
|
||||
|
||||
|
||||
|
||||
# @bp_home.route("/admin/create/", methods=['GET', 'POST'])
|
||||
# @login_required
|
||||
|
|
|
@ -2,16 +2,13 @@ from flask_wtf import FlaskForm
|
|||
from wtforms import StringField, SubmitField, TextAreaField
|
||||
from wtforms.validators import DataRequired
|
||||
|
||||
# from amanuensis.server.forms import User, Lexicon
|
||||
|
||||
|
||||
# class LexiconCreateForm(FlaskForm):
|
||||
# """/admin/create/"""
|
||||
# lexiconName = StringField(
|
||||
# 'Lexicon name',
|
||||
# validators=[DataRequired(), Lexicon(should_exist=False)])
|
||||
# editorName = StringField(
|
||||
# 'Username of editor',
|
||||
# validators=[DataRequired(), User(should_exist=True)])
|
||||
# promptText = TextAreaField('Prompt')
|
||||
# submit = SubmitField('Create')
|
||||
class LexiconCreateForm(FlaskForm):
|
||||
"""/admin/create/"""
|
||||
lexicon = StringField(
|
||||
'Lexicon name',
|
||||
validators=[DataRequired()])
|
||||
editor = StringField(
|
||||
'Username of editor',
|
||||
validators=[DataRequired()])
|
||||
prompt = TextAreaField('Prompt')
|
||||
submit = SubmitField('Create')
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
{% block title %}Admin | Amanuensis{% endblock %}
|
||||
{% block header %}<h2>Amanuensis - Admin Dashboard</h2>{% endblock %}
|
||||
|
||||
{# TODO #}
|
||||
{% block sb_home %}<a href="{{ url_for('home.home') }}">Home</a>{% endblock %}
|
||||
{% block sb_create %}<a href="#{#{ url_for('home.admin_create') }#}">Create a lexicon</a>{% endblock %}
|
||||
{% block sb_create %}<a href="{{ url_for('home.create') }}">Create a lexicon</a>{% endblock %}
|
||||
{% set template_sidebar_rows = [self.sb_home(), self.sb_create()] %}
|
||||
|
||||
{% block main %}
|
||||
|
|
|
@ -8,22 +8,24 @@
|
|||
{% set template_sidebar_rows = [self.sb_home(), self.sb_admin()] %}
|
||||
|
||||
{% block main %}
|
||||
|
||||
<form action="" method="post" novalidate>
|
||||
{{ form.hidden_tag() }}
|
||||
<p>{{ form.lexiconName.label }}<br>{{ form.lexiconName(size=32) }}
|
||||
{% for error in form.lexiconName.errors %}
|
||||
<p>{{ form.lexicon.label }}<br>{{ form.lexicon(size=32) }}
|
||||
{% for error in form.lexicon.errors %}
|
||||
<br><span style="color: #ff0000">{{ error }}</span>
|
||||
{% endfor %}</p>
|
||||
|
||||
<p>{{ form.editorName.label }}<br>{{ form.editorName(size=32) }}
|
||||
{% for error in form.editorName.errors %}
|
||||
<p>{{ form.editor.label }}<br>{{ form.editor(size=32) }}
|
||||
{% for error in form.editor.errors %}
|
||||
<br><span style="color: #ff0000">{{ error }}</span>
|
||||
{% endfor %}</p>
|
||||
|
||||
<p>{{ form.promptText.label }}<br>{{ form.promptText(class_="fullwidth") }}</p>
|
||||
<p>{{ form.prompt.label }}<br>{{ form.prompt(class_="fullwidth") }}</p>
|
||||
|
||||
<p>{{ form.submit() }}</p>
|
||||
</form>
|
||||
|
||||
{% for message in get_flashed_messages() %}
|
||||
<span style="color: #ff0000">{{ message }}</span><br>
|
||||
{% endfor %}
|
||||
|
|
Loading…
Reference in New Issue