Add lexicon listings to home page
This commit is contained in:
parent
aa987a5b4b
commit
5c244855eb
|
@ -47,3 +47,11 @@ class LexiconModel():
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
with config.json_rw(self.config_path) as j:
|
with config.json_rw(self.config_path) as j:
|
||||||
j['log'].append([now, message])
|
j['log'].append([now, message])
|
||||||
|
|
||||||
|
def status(self):
|
||||||
|
if self.turn.current is None:
|
||||||
|
return "unstarted"
|
||||||
|
elif self.turn.current > lex.turn.max:
|
||||||
|
return "completed"
|
||||||
|
else:
|
||||||
|
return "ongoing"
|
|
@ -92,7 +92,7 @@ def get_all_lexicons():
|
||||||
lids = list(index.values())
|
lids = list(index.values())
|
||||||
|
|
||||||
# Load all of the lexicons
|
# Load all of the lexicons
|
||||||
lexes = map(lambda id: lexicon.LexiconModel.by(lid=id), lids)
|
lexes = list(map(lambda id: lexicon.LexiconModel.by(lid=id), lids))
|
||||||
|
|
||||||
return lexes
|
return lexes
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"lid": null,
|
"lid": null,
|
||||||
"name": null,
|
"name": null,
|
||||||
|
"title": null,
|
||||||
"editor": null,
|
"editor": null,
|
||||||
"prompt": null,
|
"prompt": null,
|
||||||
"time": {
|
"time": {
|
||||||
|
|
|
@ -97,6 +97,28 @@ textarea#configText {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
div.dashboard-lexicon-item {
|
||||||
|
margin: 0 10px;
|
||||||
|
padding: 0 10px;
|
||||||
|
border-left: 3px solid black;
|
||||||
|
}
|
||||||
|
div.dashboard-lexicon-unstarted {
|
||||||
|
border-left-color: blue;
|
||||||
|
}
|
||||||
|
div.dashboard-lexicon-ongoing {
|
||||||
|
border-left-color: goldenrod;
|
||||||
|
}
|
||||||
|
div.dashboard-lexicon-completed {
|
||||||
|
border-left-color: green;
|
||||||
|
}
|
||||||
|
div.dashboard-lexicon-item span.dashboard-lexicon-item-title {
|
||||||
|
font-size: 1.5em;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
div.dashboard-lexicon-item p {
|
||||||
|
margin-block-start: 0.5em;
|
||||||
|
margin-block-end: 0.5em;
|
||||||
|
}
|
||||||
@media only screen and (max-width: 816px) {
|
@media only screen and (max-width: 816px) {
|
||||||
div#wrapper {
|
div#wrapper {
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
|
|
|
@ -6,6 +6,7 @@ from flask_login import LoginManager
|
||||||
import config
|
import config
|
||||||
from server.auth import get_bp as get_auth_bp
|
from server.auth import get_bp as get_auth_bp
|
||||||
from server.home import get_bp as get_home_bp
|
from server.home import get_bp as get_home_bp
|
||||||
|
from server.lexicon import get_bp as get_lex_bp
|
||||||
|
|
||||||
# Flask app init
|
# Flask app init
|
||||||
static_root = os.path.abspath(config.get("static_root"))
|
static_root = os.path.abspath(config.get("static_root"))
|
||||||
|
@ -22,3 +23,6 @@ app.register_blueprint(auth_bp)
|
||||||
|
|
||||||
home_bp = get_home_bp()
|
home_bp = get_home_bp()
|
||||||
app.register_blueprint(home_bp)
|
app.register_blueprint(home_bp)
|
||||||
|
|
||||||
|
lex_bp = get_lex_bp()
|
||||||
|
app.register_blueprint(lex_bp)
|
|
@ -0,0 +1,22 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
from flask import Blueprint, render_template, url_for, redirect
|
||||||
|
from flask_login import login_required, current_user
|
||||||
|
# from flask_wtf import FlaskForm
|
||||||
|
# from wtforms import TextAreaField, SubmitField, StringField
|
||||||
|
|
||||||
|
import config
|
||||||
|
import user
|
||||||
|
import lexicon
|
||||||
|
|
||||||
|
|
||||||
|
def get_bp():
|
||||||
|
"""Create a blueprint for lexicon pages"""
|
||||||
|
bp = Blueprint('lexicon', __name__, url_prefix='/lexicon/<name>')
|
||||||
|
|
||||||
|
@bp.route('/session/', methods=['GET'])
|
||||||
|
@login_required
|
||||||
|
def session(name):
|
||||||
|
return "Lexicon " + str(name)
|
||||||
|
|
||||||
|
return bp
|
|
@ -12,6 +12,27 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
<h1>Home Page</h1>
|
|
||||||
|
<h1>Open games</h1>
|
||||||
|
|
||||||
|
{% set lexicons = current_user.lexicons_in() %}
|
||||||
|
<h1>Your games</h1>
|
||||||
|
{% if lexicons %}
|
||||||
|
{% for lexicon in lexicons %}
|
||||||
|
|
||||||
|
<div class="dashboard-lexicon-item dashboard-lexicon-{{ lexicon.status() }}">
|
||||||
|
<p>
|
||||||
|
<span class="dashboard-lexicon-item-title">
|
||||||
|
<a href="{{ url_for('lexicon.session', name=lexicon.name) }}">Lexicon {{ lexicon.name }}</a>
|
||||||
|
</span>
|
||||||
|
[{{ lexicon.status().capitalize() }}]
|
||||||
|
</p>
|
||||||
|
<p><i>{{ lexicon.prompt }}</i></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
<p>You haven't joined a game yet.</p>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% set template_content_blocks = [self.main()] %}
|
{% set template_content_blocks = [self.main()] %}
|
|
@ -9,6 +9,7 @@ from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
from errors import InternalMisuseError, MissingConfigError, IndexMismatchError
|
from errors import InternalMisuseError, MissingConfigError, IndexMismatchError
|
||||||
import config
|
import config
|
||||||
import resources
|
import resources
|
||||||
|
import lexicon.manage
|
||||||
|
|
||||||
class UserModel(UserMixin):
|
class UserModel(UserMixin):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -56,6 +57,14 @@ class UserModel(UserMixin):
|
||||||
with config.json_ro(self.config_path) as j:
|
with config.json_ro(self.config_path) as j:
|
||||||
return check_password_hash(j['password'], pw)
|
return check_password_hash(j['password'], pw)
|
||||||
|
|
||||||
|
def lexicons_in(self):
|
||||||
|
return [
|
||||||
|
lex
|
||||||
|
for lex in lexicon.manage.get_all_lexicons()
|
||||||
|
if self.id in lex.join.joined
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def valid_username(username):
|
def valid_username(username):
|
||||||
return re.match(r"^[A-Za-z0-9-_]{3,}$", username) is not None
|
return re.match(r"^[A-Za-z0-9-_]{3,}$", username) is not None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue