patch internal tooling for prod
This commit is contained in:
3 files changed
+28
-6
No files matched your search
+1
-1
@@ -10,7 +10,7 @@ DEFAULT_DATABASE_URL = f"sqlite:///{BASE_DIR / 'data' / 'boker-dev.sqlite3'}"
|
|||||||
DEFAULT_SECRET_KEY = "change-this-before-deploying"
|
DEFAULT_SECRET_KEY = "change-this-before-deploying"
|
||||||
|
|
||||||
ELIGIBLE_MIN_SESSIONS = 3
|
ELIGIBLE_MIN_SESSIONS = 3
|
||||||
APP_VERSION = "2.5.29"
|
APP_VERSION = "2.5.30"
|
||||||
|
|
||||||
|
|
||||||
def load_local_env(env_path: Path) -> None:
|
def load_local_env(env_path: Path) -> None:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import string
|
|||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
|
|
||||||
from flask import Blueprint, current_app, flash, redirect, render_template, request, url_for
|
from flask import Blueprint, current_app, flash, redirect, render_template, request, url_for
|
||||||
from sqlalchemy import or_
|
from sqlalchemy import extract, or_
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
||||||
from boker.auth import (
|
from boker.auth import (
|
||||||
@@ -205,19 +205,25 @@ def _top_leagues(limit: int = 8):
|
|||||||
return [(league, count) for league, count in rows]
|
return [(league, count) for league, count in rows]
|
||||||
|
|
||||||
|
|
||||||
|
def _session_weekday_expression(dialect_name: str | None = None):
|
||||||
|
dialect_name = dialect_name or db.session.get_bind().dialect.name
|
||||||
|
if dialect_name == "sqlite":
|
||||||
|
return db.func.strftime("%w", PokerSession.session_date)
|
||||||
|
return extract("dow", PokerSession.session_date)
|
||||||
|
|
||||||
|
|
||||||
def _sessions_by_weekday() -> dict:
|
def _sessions_by_weekday() -> dict:
|
||||||
from sqlalchemy import func as f
|
|
||||||
rows = (
|
rows = (
|
||||||
db.session.query(
|
db.session.query(
|
||||||
f.strftime("%w", PokerSession.session_date).label("dow"),
|
_session_weekday_expression().label("dow"),
|
||||||
f.count(PokerSession.id).label("cnt"),
|
db.func.count(PokerSession.id).label("cnt"),
|
||||||
)
|
)
|
||||||
.group_by("dow")
|
.group_by("dow")
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
counts = {str(i): 0 for i in range(7)}
|
counts = {str(i): 0 for i in range(7)}
|
||||||
for row in rows:
|
for row in rows:
|
||||||
counts[str(row.dow)] = row.cnt
|
counts[str(int(row.dow))] = row.cnt
|
||||||
return {
|
return {
|
||||||
"labels": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
"labels": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
||||||
"data": [counts[str(i)] for i in range(7)],
|
"data": [counts[str(i)] for i in range(7)],
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ import unittest
|
|||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
from app import create_app
|
from app import create_app
|
||||||
from boker.auth import hash_password
|
from boker.auth import hash_password
|
||||||
from boker.db import db
|
from boker.db import db
|
||||||
@@ -107,6 +110,19 @@ class InternalAdminAccessTests(unittest.TestCase):
|
|||||||
self.assertIn(b"Ledger events", response.data)
|
self.assertIn(b"Ledger events", response.data)
|
||||||
self.assertIn(b"Totals at a glance", response.data)
|
self.assertIn(b"Totals at a glance", response.data)
|
||||||
|
|
||||||
|
def test_session_weekday_expression_uses_postgresql_extract(self):
|
||||||
|
with self.app.app_context():
|
||||||
|
from boker.routes.internal import _session_weekday_expression
|
||||||
|
|
||||||
|
compiled = str(
|
||||||
|
select(_session_weekday_expression("postgresql")).compile(
|
||||||
|
dialect=postgresql.dialect()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertIn("EXTRACT(dow FROM", compiled)
|
||||||
|
self.assertNotIn("strftime", compiled)
|
||||||
|
|
||||||
def test_admin_can_search_users(self):
|
def test_admin_can_search_users(self):
|
||||||
self.login_as(self.admin_id)
|
self.login_as(self.admin_id)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user