update logging etc
This commit is contained in:
12
app/crud.py
12
app/crud.py
@@ -102,18 +102,21 @@ def create_or_update_comment(db, song_id, session_name, comment):
|
|||||||
|
|
||||||
def activate_session(db, session_name):
|
def activate_session(db, session_name):
|
||||||
ip = context.data[HeaderKeys.forwarded_for]
|
ip = context.data[HeaderKeys.forwarded_for]
|
||||||
|
user_agent = context.data[HeaderKeys.user_agent]
|
||||||
|
|
||||||
session_entry = db.query(models.Session).filter(and_(
|
session_entry = db.query(models.Session).filter(and_(
|
||||||
models.Session.session_name == session_name, models.Session.ip == ip)).first()
|
models.Session.session_name == session_name)).first() # , models.Session.ip == ip, models.Session.user_agent == user_agent
|
||||||
if session_entry:
|
if session_entry:
|
||||||
print(session_entry.__dict__)
|
if ip not in session_entry.ips:
|
||||||
|
session_entry.ips.append(ip)
|
||||||
session_entry.active = True
|
session_entry.active = True
|
||||||
else:
|
else:
|
||||||
session_entry = models.Session(
|
session_entry = models.Session(
|
||||||
session_name=session_name, active=True, ip=ip)
|
session_name=session_name, active=True, ips=[ip]) # , ip=ip, user_agent=user_agent
|
||||||
db.add(session_entry)
|
db.add(session_entry)
|
||||||
|
|
||||||
flag_modified(session_entry, "active")
|
flag_modified(session_entry, "active")
|
||||||
|
flag_modified(session_entry, "ips")
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
return session_entry
|
return session_entry
|
||||||
@@ -121,9 +124,10 @@ def activate_session(db, session_name):
|
|||||||
|
|
||||||
def deactivate_session(db, session_name):
|
def deactivate_session(db, session_name):
|
||||||
ip = context.data[HeaderKeys.forwarded_for]
|
ip = context.data[HeaderKeys.forwarded_for]
|
||||||
|
user_agent = context.data[HeaderKeys.user_agent]
|
||||||
|
|
||||||
session_entry = db.query(models.Session).filter(and_(
|
session_entry = db.query(models.Session).filter(and_(
|
||||||
models.Session.session_name == session_name, models.Session.ip == ip)).first()
|
models.Session.session_name == session_name)).first() # , models.Session.ip == ip, models.Session.user_agent == user_agent
|
||||||
if session_entry:
|
if session_entry:
|
||||||
session_entry.active = False
|
session_entry.active = False
|
||||||
flag_modified(session_entry, "active")
|
flag_modified(session_entry, "active")
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.orm import sessionmaker, DeclarativeBase
|
from sqlalchemy.orm import sessionmaker, DeclarativeBase
|
||||||
from sqlalchemy.types import PickleType
|
from sqlalchemy.types import PickleType, JSON
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -23,5 +23,5 @@ class Base(DeclarativeBase):
|
|||||||
type_annotation_map = {
|
type_annotation_map = {
|
||||||
dict[str, bool]: PickleType,
|
dict[str, bool]: PickleType,
|
||||||
object: PickleType,
|
object: PickleType,
|
||||||
set: PickleType
|
list[str]: JSON
|
||||||
}
|
}
|
||||||
9
app/init_tools.py
Normal file
9
app/init_tools.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
from app.routers import admin
|
||||||
|
from app.database import engine, Base, get_db, SessionLocal
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
def reset():
|
||||||
|
#Base.metadata.drop_all(engine)
|
||||||
|
#Base.metadata.create_all(engine)
|
||||||
|
with SessionLocal() as db:
|
||||||
|
asyncio.run(admin.create_upload_file(include_non_singable=True, db=db))
|
||||||
@@ -22,6 +22,7 @@ middleware = [
|
|||||||
RawContextMiddleware,
|
RawContextMiddleware,
|
||||||
plugins=(
|
plugins=(
|
||||||
plugins.ForwardedForPlugin(),
|
plugins.ForwardedForPlugin(),
|
||||||
|
plugins.UserAgentPlugin()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class Session(Base):
|
|||||||
id: Mapped[int] = mapped_column(primary_key=True)
|
id: Mapped[int] = mapped_column(primary_key=True)
|
||||||
session_name: Mapped[str]
|
session_name: Mapped[str]
|
||||||
active: Mapped[bool]
|
active: Mapped[bool]
|
||||||
ip: Mapped[str]
|
ips: Mapped[list[str]]
|
||||||
first_seen: Mapped[datetime] = mapped_column(server_default=func.now())
|
first_seen: Mapped[datetime] = mapped_column(server_default=func.now())
|
||||||
last_seen: Mapped[Optional[datetime]
|
last_seen: Mapped[Optional[datetime]
|
||||||
] = mapped_column(onupdate=func.now())
|
] = mapped_column(onupdate=func.now())
|
||||||
|
|||||||
@@ -15,6 +15,9 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
margin-top: 0.3em;
|
margin-top: 0.3em;
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
|
border: 1px solid white;
|
||||||
|
border-radius: 0.2em;
|
||||||
|
padding: 0.1em;
|
||||||
}
|
}
|
||||||
.not_singable {
|
.not_singable {
|
||||||
background-color: color-mix(in srgb, #e1412f 30%, #f0f0f0);
|
background-color: color-mix(in srgb, #e1412f 30%, #f0f0f0);
|
||||||
@@ -218,8 +221,8 @@
|
|||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
{% if veto_mode %}
|
{% if veto_mode %}
|
||||||
<input type="text" class="comment"
|
<input type="text" class="comment"
|
||||||
value="{% if song.vote_comment %}{{ song.vote_comment }}{% else %}{% if song.comment %}{{ song.comment }}{% else %}{% endif %}{% endif %}"
|
value="{% if song.vote_comment %}{{ song.vote_comment }}{% else %}{% endif %}"
|
||||||
placeholder="Kommentar" onchange="updateComment({{ song.id }}, this);">
|
placeholder="{% if song.comment %}{{ song.comment }}{% else %}Kommentar{% endif %}" onchange="updateComment({{ song.id }}, this);">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
Reference in New Issue
Block a user