rDrama/files/classes/ip_logs.py

31 lines
735 B
Python
Raw Normal View History

2024-02-06 01:00:40 +00:00
import time
2024-02-15 13:17:23 +00:00
from typing import TYPE_CHECKING
2024-02-06 01:00:40 +00:00
2024-02-15 21:50:18 +00:00
from sqlalchemy.orm import Mapped, relationship
2024-02-06 01:00:40 +00:00
from sqlalchemy.sql.sqltypes import *
from files.classes import Base
2024-02-15 21:50:18 +00:00
from files.helpers.types import str_pk, user_id_fk_pk
2024-02-06 01:00:40 +00:00
2024-02-15 13:17:23 +00:00
if TYPE_CHECKING:
from files.classes import User
2024-02-06 01:00:40 +00:00
class IPLog(Base):
__tablename__ = "ip_logs"
2024-02-15 21:50:18 +00:00
user_id: Mapped[user_id_fk_pk]
ip: Mapped[str_pk]
2024-02-15 13:17:23 +00:00
created_utc: Mapped[int]
last_used: Mapped[int]
2024-02-06 01:00:40 +00:00
2024-02-15 13:17:23 +00:00
user: Mapped["User"] = relationship()
2024-02-06 01:19:38 +00:00
2024-02-06 01:00:40 +00:00
def __init__(self, *args, **kwargs):
if "created_utc" not in kwargs:
kwargs["created_utc"] = int(time.time())
kwargs["last_used"] = kwargs["created_utc"]
super().__init__(*args, **kwargs)
def __repr__(self):
return f"<{self.__class__.__name__}(id={self.id})>"