feat: switch all timezone naive datetimes to timezone aware
This commit is contained in:
parent
41fc0a73a5
commit
e22abb383c
30 changed files with 322 additions and 226 deletions
|
@ -1,39 +1,40 @@
|
|||
import datetime
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any, Optional
|
||||
|
||||
import requests
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.brm.brn import BRN
|
||||
from app.models import AbstractConfiguration
|
||||
from app.extensions import db
|
||||
from app.models import AbstractConfiguration
|
||||
|
||||
|
||||
class Activity(db.Model): # type: ignore
|
||||
id = db.Column(db.Integer(), primary_key=True)
|
||||
group_id = db.Column(db.Integer(), nullable=True)
|
||||
activity_type = db.Column(db.String(20), nullable=False)
|
||||
text = db.Column(db.Text(), nullable=False)
|
||||
added = db.Column(db.DateTime(), nullable=False)
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
group_id: Mapped[Optional[int]]
|
||||
activity_type: Mapped[str]
|
||||
text: Mapped[str]
|
||||
added: Mapped[datetime] = mapped_column(db.DateTime(timezone=True))
|
||||
|
||||
def __init__(self, *,
|
||||
id: Optional[int] = None,
|
||||
group_id: Optional[int] = None,
|
||||
activity_type: str,
|
||||
text: str,
|
||||
added: Optional[datetime.datetime] = None,
|
||||
added: Optional[datetime] = None,
|
||||
**kwargs: Any) -> None:
|
||||
if not isinstance(activity_type, str) or len(activity_type) > 20 or activity_type == "":
|
||||
raise TypeError("expected string for activity type between 1 and 20 characters")
|
||||
if not isinstance(text, str):
|
||||
raise TypeError("expected string for text")
|
||||
if added is None:
|
||||
added = datetime.now(tz=timezone.utc)
|
||||
super().__init__(id=id,
|
||||
group_id=group_id,
|
||||
activity_type=activity_type,
|
||||
text=text,
|
||||
added=added,
|
||||
**kwargs)
|
||||
if self.added is None:
|
||||
self.added = datetime.datetime.utcnow()
|
||||
|
||||
def notify(self) -> int:
|
||||
count = 0
|
||||
|
@ -47,8 +48,8 @@ class Activity(db.Model): # type: ignore
|
|||
|
||||
|
||||
class Webhook(AbstractConfiguration):
|
||||
format = db.Column(db.String(20))
|
||||
url = db.Column(db.String(255))
|
||||
format: Mapped[str]
|
||||
url: Mapped[str]
|
||||
|
||||
@property
|
||||
def brn(self) -> BRN:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue