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
|
||||
|
||||
|
||||
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):
|
||||
"""
|
||||
Checks whether the given player can join a lexicon
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
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.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.helpers import admin_required
|
||||
from amanuensis.user import UserModel
|
||||
|
@ -15,7 +15,10 @@ def get_bp():
|
|||
|
||||
@bp.route('/', methods=['GET'])
|
||||
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'])
|
||||
@login_required
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
{% endfor %}
|
||||
|
||||
{% if current_user.is_authenticated %}
|
||||
{% set lexicons = current_user.lexicons_in() %}
|
||||
<h2>Your games</h2>
|
||||
{% if lexicons %}
|
||||
{% for lexicon in lexicons %}
|
||||
|
|
|
@ -6,7 +6,5 @@
|
|||
|
||||
<h1>Index</h1>
|
||||
|
||||
{% set lexicons = current_user.lexicons_in() %}
|
||||
|
||||
{% endblock %}
|
||||
{% set template_content_blocks = [self.main()] %}
|
|
@ -6,7 +6,5 @@
|
|||
|
||||
<h1>Rules</h1>
|
||||
|
||||
{% set lexicons = current_user.lexicons_in() %}
|
||||
|
||||
{% endblock %}
|
||||
{% set template_content_blocks = [self.main()] %}
|
|
@ -6,7 +6,5 @@
|
|||
|
||||
<h1>Statistics</h1>
|
||||
|
||||
{% set lexicons = current_user.lexicons_in() %}
|
||||
|
||||
{% endblock %}
|
||||
{% set template_content_blocks = [self.main()] %}
|
|
@ -10,7 +10,7 @@ from amanuensis.errors import (
|
|||
ArgumentError, MissingConfigError, IndexMismatchError)
|
||||
from amanuensis.config import prepend, json_ro, json_rw
|
||||
from amanuensis.resources import get_stream
|
||||
from amanuensis.lexicon.manage import get_all_lexicons
|
||||
|
||||
|
||||
class UserModel(UserMixin):
|
||||
@staticmethod
|
||||
|
@ -64,13 +64,6 @@ class UserModel(UserMixin):
|
|||
with json_ro(self.config_path) as j:
|
||||
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):
|
||||
"""
|
||||
|
@ -82,6 +75,7 @@ def valid_username(username):
|
|||
is_a_guid = re.match(r"^[A-Za-z0-9]{32}$", username)
|
||||
return length_and_characters and not is_a_guid
|
||||
|
||||
|
||||
def valid_email(email):
|
||||
"""Vaguely RFC2822 email verifier"""
|
||||
atom = r"[0-9A-Za-z!#$%&'*+-/=?^_`{|}~]{1,}"
|
||||
|
@ -89,6 +83,7 @@ def valid_email(email):
|
|||
addrspec = "^" + dotatom + "@" + dotatom + "$"
|
||||
return re.match(addrspec, email)
|
||||
|
||||
|
||||
def create_user(username, displayname, email):
|
||||
"""
|
||||
Creates a new user
|
||||
|
|
Loading…
Reference in New Issue