Remove dependency of .user on .lexicon
This commit is contained in:
parent
7a2e1905ca
commit
1431dab8f8
|
@ -116,6 +116,16 @@ def get_all_lexicons():
|
||||||
return lexes
|
return lexes
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_lexicons(user):
|
||||||
|
"""
|
||||||
|
Loads each lexicon that the given user is a player in
|
||||||
|
"""
|
||||||
|
return [
|
||||||
|
lexicon
|
||||||
|
for lexicon in get_all_lexicons()
|
||||||
|
if user.id in lexicon.join.joined]
|
||||||
|
|
||||||
|
|
||||||
def valid_add(lex, player, password=None):
|
def valid_add(lex, player, password=None):
|
||||||
"""
|
"""
|
||||||
Checks whether the given player can join a lexicon
|
Checks whether the given player can join a lexicon
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
from flask import Blueprint, render_template, redirect, url_for
|
from flask import Blueprint, render_template, redirect, url_for
|
||||||
from flask_login import login_required
|
from flask_login import login_required, current_user
|
||||||
|
|
||||||
from amanuensis.config import json_ro, json_rw
|
from amanuensis.config import json_ro, json_rw
|
||||||
from amanuensis.lexicon import LexiconModel
|
from amanuensis.lexicon import LexiconModel
|
||||||
from amanuensis.lexicon.manage import create_lexicon
|
from amanuensis.lexicon.manage import create_lexicon, get_user_lexicons
|
||||||
from amanuensis.server.forms import LexiconCreateForm
|
from amanuensis.server.forms import LexiconCreateForm
|
||||||
from amanuensis.server.helpers import admin_required
|
from amanuensis.server.helpers import admin_required
|
||||||
from amanuensis.user import UserModel
|
from amanuensis.user import UserModel
|
||||||
|
@ -15,7 +15,10 @@ def get_bp():
|
||||||
|
|
||||||
@bp.route('/', methods=['GET'])
|
@bp.route('/', methods=['GET'])
|
||||||
def home():
|
def home():
|
||||||
return render_template('home/home.html')
|
lexicons = []
|
||||||
|
if current_user.is_authenticated:
|
||||||
|
lexicons = get_user_lexicons(current_user)
|
||||||
|
return render_template('home/home.html', lexicons=lexicons)
|
||||||
|
|
||||||
@bp.route('/admin/', methods=['GET'])
|
@bp.route('/admin/', methods=['GET'])
|
||||||
@login_required
|
@login_required
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% if current_user.is_authenticated %}
|
{% if current_user.is_authenticated %}
|
||||||
{% set lexicons = current_user.lexicons_in() %}
|
|
||||||
<h2>Your games</h2>
|
<h2>Your games</h2>
|
||||||
{% if lexicons %}
|
{% if lexicons %}
|
||||||
{% for lexicon in lexicons %}
|
{% for lexicon in lexicons %}
|
||||||
|
|
|
@ -6,7 +6,5 @@
|
||||||
|
|
||||||
<h1>Index</h1>
|
<h1>Index</h1>
|
||||||
|
|
||||||
{% set lexicons = current_user.lexicons_in() %}
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% set template_content_blocks = [self.main()] %}
|
{% set template_content_blocks = [self.main()] %}
|
|
@ -6,7 +6,5 @@
|
||||||
|
|
||||||
<h1>Rules</h1>
|
<h1>Rules</h1>
|
||||||
|
|
||||||
{% set lexicons = current_user.lexicons_in() %}
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% set template_content_blocks = [self.main()] %}
|
{% set template_content_blocks = [self.main()] %}
|
|
@ -6,7 +6,5 @@
|
||||||
|
|
||||||
<h1>Statistics</h1>
|
<h1>Statistics</h1>
|
||||||
|
|
||||||
{% set lexicons = current_user.lexicons_in() %}
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% set template_content_blocks = [self.main()] %}
|
{% set template_content_blocks = [self.main()] %}
|
|
@ -10,7 +10,7 @@ from amanuensis.errors import (
|
||||||
ArgumentError, MissingConfigError, IndexMismatchError)
|
ArgumentError, MissingConfigError, IndexMismatchError)
|
||||||
from amanuensis.config import prepend, json_ro, json_rw
|
from amanuensis.config import prepend, json_ro, json_rw
|
||||||
from amanuensis.resources import get_stream
|
from amanuensis.resources import get_stream
|
||||||
from amanuensis.lexicon.manage import get_all_lexicons
|
|
||||||
|
|
||||||
class UserModel(UserMixin):
|
class UserModel(UserMixin):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -64,13 +64,6 @@ class UserModel(UserMixin):
|
||||||
with json_ro(self.config_path) as j:
|
with 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 get_all_lexicons()
|
|
||||||
if self.id in lex.join.joined
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def valid_username(username):
|
def valid_username(username):
|
||||||
"""
|
"""
|
||||||
|
@ -82,6 +75,7 @@ def valid_username(username):
|
||||||
is_a_guid = re.match(r"^[A-Za-z0-9]{32}$", username)
|
is_a_guid = re.match(r"^[A-Za-z0-9]{32}$", username)
|
||||||
return length_and_characters and not is_a_guid
|
return length_and_characters and not is_a_guid
|
||||||
|
|
||||||
|
|
||||||
def valid_email(email):
|
def valid_email(email):
|
||||||
"""Vaguely RFC2822 email verifier"""
|
"""Vaguely RFC2822 email verifier"""
|
||||||
atom = r"[0-9A-Za-z!#$%&'*+-/=?^_`{|}~]{1,}"
|
atom = r"[0-9A-Za-z!#$%&'*+-/=?^_`{|}~]{1,}"
|
||||||
|
@ -89,6 +83,7 @@ def valid_email(email):
|
||||||
addrspec = "^" + dotatom + "@" + dotatom + "$"
|
addrspec = "^" + dotatom + "@" + dotatom + "$"
|
||||||
return re.match(addrspec, email)
|
return re.match(addrspec, email)
|
||||||
|
|
||||||
|
|
||||||
def create_user(username, displayname, email):
|
def create_user(username, displayname, email):
|
||||||
"""
|
"""
|
||||||
Creates a new user
|
Creates a new user
|
||||||
|
|
Loading…
Reference in New Issue