Add a list of unhealthy questions to the admin homepage
This commit is contained in:
parent
cf85a316e3
commit
a0bac0ebf7
@ -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/")
|
||||
|
@ -1,5 +1,9 @@
|
||||
{% extends "admin/base.html" %}
|
||||
|
||||
{% block body %}
|
||||
<p>This is the admin home page</p>
|
||||
<ul>
|
||||
{% for question in questions %}
|
||||
<li><a href="{{ url_for("admin.edit_question", question_id=question.question_id) }}">{{ question.question_id }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user