mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
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>
22 lines
563 B
Python
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
|