mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-21 06:49:26 -04:00
Compare commits
3 Commits
04-09-2025
...
api-568_da
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af4ed4297c | ||
|
|
aef5064738 | ||
|
|
280bd86268 |
@@ -203,8 +203,10 @@ class AgreementType(StrEnum):
|
||||
|
||||
|
||||
class AgreementStatus(StrEnum):
|
||||
WAITING = "waiting"
|
||||
ACTIVE = "active"
|
||||
EXPIRED = "expired"
|
||||
UNKNOWN = "unknown"
|
||||
|
||||
|
||||
class StatisticsType(StrEnum):
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import datetime
|
||||
import itertools
|
||||
from re import I
|
||||
import uuid
|
||||
|
||||
from flask import current_app, url_for
|
||||
@@ -16,6 +17,7 @@ from sqlalchemy import CheckConstraint, Index, UniqueConstraint
|
||||
from sqlalchemy.dialects.postgresql import JSON, JSONB, UUID
|
||||
from sqlalchemy.ext.associationproxy import association_proxy
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
from sqlalchemy.ext.hybrid import hybrid_property
|
||||
from sqlalchemy.orm import validates
|
||||
from sqlalchemy.orm.collections import attribute_mapped_collection
|
||||
|
||||
@@ -368,12 +370,12 @@ class Organization(db.Model):
|
||||
created_at = db.Column(
|
||||
db.DateTime,
|
||||
nullable=False,
|
||||
default=datetime.datetime.utcnow,
|
||||
default=datetime.datetime.now(datetime.UTC),
|
||||
)
|
||||
updated_at = db.Column(
|
||||
db.DateTime,
|
||||
nullable=True,
|
||||
onupdate=datetime.datetime.utcnow,
|
||||
onupdate=datetime.datetime.now(datetime.UTC),
|
||||
)
|
||||
agreement_signed = db.Column(db.Boolean, nullable=True)
|
||||
agreement_signed_at = db.Column(db.DateTime, nullable=True)
|
||||
@@ -421,13 +423,12 @@ class Organization(db.Model):
|
||||
@property
|
||||
def agreement(self):
|
||||
try:
|
||||
active_agreements = [
|
||||
return next(
|
||||
agreement
|
||||
for agreement in self.agreements
|
||||
if agreement.status == AgreementStatus.ACTIVE
|
||||
]
|
||||
return active_agreements[0]
|
||||
except IndexError:
|
||||
)
|
||||
except StopIteration:
|
||||
return None
|
||||
|
||||
@property
|
||||
@@ -2317,9 +2318,8 @@ class Agreement(db.Model):
|
||||
)
|
||||
type = enum_column(AgreementType, index=False, unique=False, nullable=False)
|
||||
partner_name = db.Column(db.String(255), nullable=False, unique=True, index=True)
|
||||
status = enum_column(AgreementStatus, index=False, unique=False, nullable=False)
|
||||
start_time = db.Column(db.DateTime, nullable=True)
|
||||
end_time = db.Column(db.DateTime, nullable=True)
|
||||
start_time = db.Column(db.DateTime, nullable=True, index=True)
|
||||
end_time = db.Column(db.DateTime, nullable=True, index=True)
|
||||
url = db.Column(db.String(255), nullable=False, unique=True, index=True)
|
||||
budget_amount = db.Column(db.Float, nullable=True)
|
||||
organization_id = db.Column(
|
||||
@@ -2329,6 +2329,21 @@ class Agreement(db.Model):
|
||||
)
|
||||
organization = db.relationship("Organization", backref="agreements")
|
||||
|
||||
|
||||
@hybrid_property
|
||||
def status(self) -> AgreementStatus:
|
||||
"""Calculated status for the agreement, based on start_time and end_time."""
|
||||
current_time = datetime.datetime.now(datetime.UTC)
|
||||
if self.start_time is None or self.end_time is None:
|
||||
return AgreementStatus.UNKNOWN
|
||||
elif current_time > self.end_time:
|
||||
return AgreementStatus.EXPIRED
|
||||
elif current_time >= self.start_time:
|
||||
return AgreementStatus.ACTIVE
|
||||
else:
|
||||
return AgreementStatus.WAITING
|
||||
|
||||
|
||||
def serialize(self):
|
||||
return {
|
||||
"id": str(self.id),
|
||||
|
||||
27
poetry.lock
generated
27
poetry.lock
generated
@@ -1,5 +1,16 @@
|
||||
# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand.
|
||||
|
||||
[[package]]
|
||||
name = "aiofiles"
|
||||
version = "0.8.0"
|
||||
description = "File support for asyncio."
|
||||
optional = false
|
||||
python-versions = ">=3.6,<4.0"
|
||||
files = [
|
||||
{file = "aiofiles-0.8.0-py3-none-any.whl", hash = "sha256:7a973fc22b29e9962d0897805ace5856e6a566ab1f0c8e5c91ff6c866519c937"},
|
||||
{file = "aiofiles-0.8.0.tar.gz", hash = "sha256:8334f23235248a3b2e83b2c3a78a22674f39969b96397126cc93664d9a901e59"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aiohttp"
|
||||
version = "3.9.4"
|
||||
@@ -95,6 +106,20 @@ yarl = ">=1.0,<2.0"
|
||||
[package.extras]
|
||||
speedups = ["Brotli", "aiodns", "brotlicffi"]
|
||||
|
||||
[[package]]
|
||||
name = "aiopathlib"
|
||||
version = "0.5.0"
|
||||
description = "Pathlib support for asyncio"
|
||||
optional = false
|
||||
python-versions = ">=3.8,<4.0"
|
||||
files = [
|
||||
{file = "aiopathlib-0.5.0-py3-none-any.whl", hash = "sha256:f595fb7f159117961a5972e973ac3b54f8d47c7d677fd498856cf645c7030421"},
|
||||
{file = "aiopathlib-0.5.0.tar.gz", hash = "sha256:b48e8dc02f18bf4a577c88a3eb04455d5deead11a22899514d765a84a3bc3805"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
aiofiles = ">=0.8.0,<0.9.0"
|
||||
|
||||
[[package]]
|
||||
name = "aiosignal"
|
||||
version = "1.3.1"
|
||||
@@ -4803,4 +4828,4 @@ multidict = ">=4.0"
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.12.2"
|
||||
content-hash = "ac4a9cfb1ee9b5d8824385113cc825e55aefa8ad599649bde17b0333ed304dcd"
|
||||
content-hash = "9548c8ccbb4b5f11265a75a46b1de03f25ae165366c0d8a68de8a9793949a8d8"
|
||||
|
||||
@@ -52,6 +52,7 @@ sqlalchemy = "==1.4.40"
|
||||
werkzeug = "^3.0.2"
|
||||
faker = "^24.4.0"
|
||||
setuptools = "^69.2.0"
|
||||
aiopathlib = "^0.5.0"
|
||||
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
|
||||
Reference in New Issue
Block a user