feat: Add lore pack, UI adjustments, requirements.txt and INSTALL.md
This commit is contained in:
+26
-5
@@ -20,7 +20,7 @@ from app.schemas import GameCheckRequest, SuggestionCreateRequest, GameStartRequ
|
||||
|
||||
load_dotenv()
|
||||
|
||||
app = FastAPI(title="Magisches Harry-Potter-Escape-Quiz")
|
||||
app = FastAPI(title="PotterTrivia – Das Harry-Potter-Wissensquiz")
|
||||
|
||||
SECRET_KEY = os.getenv("SECRET_KEY", "hogwarts_secret_default_key_2026")
|
||||
app.add_middleware(SessionMiddleware, secret_key=SECRET_KEY, session_cookie="quiz_session")
|
||||
@@ -154,16 +154,37 @@ async def index(request: Request, db: Session = Depends(get_db)):
|
||||
context={"question_count": active_count}
|
||||
)
|
||||
|
||||
VALID_CATEGORIES = ["all", "books", "movies", "creatures", "spells", "characters", "hogwarts", "quidditch", "lore", "general"]
|
||||
|
||||
@app.post("/api/game/start")
|
||||
async def start_game(payload: GameStartRequest = None, db: Session = Depends(get_db)):
|
||||
lang = payload.lang if payload and payload.lang in ["de", "en"] else "de"
|
||||
difficulty = payload.difficulty if payload and payload.difficulty in ["easy", "medium", "hard"] else "all"
|
||||
category = payload.category if payload and payload.category in VALID_CATEGORIES else "all"
|
||||
|
||||
base_query = db.query(Question).filter(Question.status == "active")
|
||||
if category != "all":
|
||||
if category == "books":
|
||||
cat_query = base_query.filter((Question.category == "books") | (Question.question.like("%Kröter%")))
|
||||
else:
|
||||
cat_query = base_query.filter(Question.category == category)
|
||||
else:
|
||||
cat_query = base_query
|
||||
|
||||
query = db.query(Question).filter(Question.status == "active")
|
||||
if difficulty != "all":
|
||||
query = query.filter(Question.difficulty == difficulty)
|
||||
strict_pool = cat_query.filter(Question.difficulty == difficulty).all()
|
||||
if len(strict_pool) >= 10 or category == "all":
|
||||
pool = strict_pool
|
||||
else:
|
||||
# Keep all difficulty matches in this category and top up from the same category
|
||||
cat_all = cat_query.all()
|
||||
strict_ids = {q.id for q in strict_pool}
|
||||
extra = [q for q in cat_all if q.id not in strict_ids]
|
||||
random.shuffle(extra)
|
||||
pool = strict_pool + extra[:max(0, 10 - len(strict_pool))]
|
||||
else:
|
||||
pool = cat_query.all()
|
||||
|
||||
pool = query.all()
|
||||
if not pool:
|
||||
pool = db.query(Question).filter(Question.status == "active").all()
|
||||
if not pool:
|
||||
@@ -538,7 +559,7 @@ async def submit_suggestion(payload: SuggestionCreateRequest, db: Session = Depe
|
||||
opts.append(opt.strip())
|
||||
options_json = json.dumps(opts, ensure_ascii=False)
|
||||
|
||||
chosen_cat = payload.category if payload.category in ["hogwarts", "characters", "spells", "creatures", "quidditch", "lore", "general"] else "general"
|
||||
chosen_cat = payload.category if payload.category in ["books", "movies", "hogwarts", "characters", "spells", "creatures", "quidditch", "lore", "general"] else "general"
|
||||
diff = payload.difficulty if payload.difficulty in ["easy", "medium", "hard"] else "medium"
|
||||
|
||||
new_suggestion = Question(
|
||||
|
||||
Reference in New Issue
Block a user