housekeep: centralize datetime generation

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2022-01-18 05:59:52 -08:00
parent 7bcc8d7ce7
commit 7f6c23d4cb
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
41 changed files with 146 additions and 179 deletions

View file

@ -1,9 +1,7 @@
from datetime import datetime
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import backref, relationship
from aurweb import schema
from aurweb import schema, time
from aurweb.models.declarative import Base
from aurweb.models.user import User as _User
@ -43,7 +41,7 @@ class PackageBase(Base):
# If no SubmittedTS/ModifiedTS is provided on creation, set them
# here to the current utc timestamp.
now = datetime.utcnow().timestamp()
now = time.utcnow()
if not self.SubmittedTS:
self.SubmittedTS = now
if not self.ModifiedTS:

View file

@ -1,11 +1,9 @@
import typing
from datetime import datetime
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import backref, relationship
from aurweb import schema
from aurweb import schema, time
from aurweb.models.declarative import Base
from aurweb.models.user import User as _User
@ -71,7 +69,7 @@ class TUVoteInfo(Base):
return attr
def is_running(self):
return self.End > int(datetime.utcnow().timestamp())
return self.End > time.utcnow()
def total_votes(self):
return self.Yes + self.No + self.Abstain

View file

@ -1,6 +1,5 @@
import hashlib
from datetime import datetime
from typing import List, Set
import bcrypt
@ -14,7 +13,7 @@ import aurweb.config
import aurweb.models.account_type
import aurweb.schema
from aurweb import db, logging, schema, util
from aurweb import db, logging, schema, time, util
from aurweb.models.account_type import AccountType as _AccountType
from aurweb.models.ban import is_banned
from aurweb.models.declarative import Base
@ -121,7 +120,7 @@ class User(Base):
exc = None
for i in range(tries):
exc = None
now_ts = datetime.utcnow().timestamp()
now_ts = time.utcnow()
try:
with db.begin():
self.LastLogin = now_ts