diff --git a/QuizTheWord/admin/admin.py b/QuizTheWord/admin/admin.py
index 4824b51..567e5aa 100644
--- a/QuizTheWord/admin/admin.py
+++ b/QuizTheWord/admin/admin.py
@@ -11,7 +11,8 @@ Admin = Blueprint("admin", __name__, url_prefix="/admin", template_folder="templ
@Admin.route("/")
@roles_required("admin")
def index():
- return render_template("admin/index.html", title="admin")
+ questions = database.get_unhealthy_questions()
+ return render_template("admin/index.html", title="admin", questions=questions)
@Admin.route("/questions/")
diff --git a/QuizTheWord/admin/templates/admin/index.html b/QuizTheWord/admin/templates/admin/index.html
index dd5b984..757af79 100644
--- a/QuizTheWord/admin/templates/admin/index.html
+++ b/QuizTheWord/admin/templates/admin/index.html
@@ -1,5 +1,9 @@
{% extends "admin/base.html" %}
{% block body %}
-
This is the admin home page
+
{% endblock %}
diff --git a/QuizTheWord/database.py b/QuizTheWord/database.py
index f22c8b7..6a2b7cb 100644
--- a/QuizTheWord/database.py
+++ b/QuizTheWord/database.py
@@ -1,16 +1,22 @@
+import os
from flask import current_app, g
from flask_security import UserMixin, RoleMixin
import sqlalchemy
from typing import Union, Optional, Literal, Type, List, Tuple
import random
from sqlalchemy import Column, JSON, String, Integer, create_engine, ForeignKey, func, Boolean, UnicodeText, DateTime
+from sqlalchemy.sql.expression import or_, and_
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.orm import sessionmaker, relationship, scoped_session
+from werkzeug.utils import import_string
+
+
+config = import_string(os.environ.get("CONFIGURATION_SETUP"))
+engine = create_engine(config.DB_URL, pool_size=20)
def get_scoped_session():
- engine = create_engine(current_app.config["DB_URL"])
session_factory = sessionmaker(bind=engine)
Base.query = scoped_session(session_factory).query_property() # This is for compatibility with Flask-Security-Too which assumes usage of Flask-Sqlalchemy
return scoped_session(session_factory)
@@ -226,7 +232,7 @@ def get_category_count(category: Union[Type[MultipleChoice], Type[HiddenAnswer],
def get_question(category: Union[Type[MultipleChoice], Type[HiddenAnswer], Type[AllQuestions]], question_id: int) -> \
-Optional[Union[MultipleChoice, HiddenAnswer, AllQuestions]]:
+ Optional[Union[MultipleChoice, HiddenAnswer, AllQuestions]]:
session = get_session()
return session.query(category).filter(category.question_id == question_id).one_or_none()
@@ -281,6 +287,18 @@ def query_all_questions(offset, limit, query: dict = None, sort=None, order=None
return questions, count
+def get_unhealthy_questions() -> List[AllQuestions]:
+ session = get_session()
+ questions = []
+ missing_category_questions = session.query(AllQuestions).filter(and_(AllQuestions.hidden_answer == None, AllQuestions.multiple_choice == None)).all()
+ multiple_choice_difficulty = session.query(AllQuestions).filter(AllQuestions.multiple_choice.has(MultipleChoice.multiple_choice_difficulty == None)).all()
+ hidden_answer_difficulty = session.query(AllQuestions).filter(AllQuestions.hidden_answer.has(HiddenAnswer.hidden_answer_difficulty == None)).all()
+ questions.extend(missing_category_questions)
+ questions.extend(multiple_choice_difficulty)
+ questions.extend(hidden_answer_difficulty)
+ return questions
+
+
def update_question(question_id, data):
session = get_session()
question: AllQuestions = session.query(AllQuestions).get(question_id)
diff --git a/app.yaml b/app.yaml
index 7867ebb..9ed2ed7 100644
--- a/app.yaml
+++ b/app.yaml
@@ -1,2 +1,4 @@
runtime: python39
-entrypoint: gunicorn -b :$PORT QuizTheWord.app:app
\ No newline at end of file
+entrypoint: gunicorn -b :$PORT QuizTheWord.app:app
+env_variables:
+ CONFIGURATION_SETUP: "QuizTheWord.config.Production"
\ No newline at end of file