aurweb/aurweb/models/ban.py
Kevin Morris 888cf5118a use declarative_base for all ORM models
This rewrites the entire model base as declarative models.
This allows us to more easily customize overlay fields
in tables and is more common.

This effort also brought some DB violations to light which
this commit addresses.

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-06-10 13:54:27 -07:00

22 lines
563 B
Python

from fastapi import Request
from sqlalchemy import Column, String
from aurweb.models.declarative import Base
class Ban(Base):
__tablename__ = "Bans"
IPAddress = Column(String(45), primary_key=True)
__mapper_args__ = {"primary_key": [IPAddress]}
def __init__(self, **kwargs):
self.IPAddress = kwargs.get("IPAddress")
self.BanTS = kwargs.get("BanTS")
def is_banned(request: Request):
from aurweb.db import session
ip = request.client.host
return session.query(Ban).filter(Ban.IPAddress == ip).first() is not None