05/19 Enhance codes 2
This commit is contained in:
@@ -48,6 +48,15 @@ class SharedItem(db.Model):
|
||||
|
||||
accepted = db.Column(db.Boolean, default=False, nullable=False)
|
||||
created_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc).replace(tzinfo=None), nullable=False)
|
||||
# Optional expiry — NULL means the share never expires.
|
||||
# Expired unaccepted shares are hidden from the inbox; accepted shares remain.
|
||||
expires_at = db.Column(db.DateTime, nullable=True)
|
||||
|
||||
def is_expired(self) -> bool:
|
||||
"""Return True if the share has an expiry and it has passed."""
|
||||
if not self.expires_at:
|
||||
return False
|
||||
return datetime.now(timezone.utc).replace(tzinfo=None) >= self.expires_at
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
@@ -64,4 +73,6 @@ class SharedItem(db.Model):
|
||||
'iv_name': self.iv_name,
|
||||
'accepted': self.accepted,
|
||||
'created_at': self.created_at.isoformat() if self.created_at else None,
|
||||
'expires_at': self.expires_at.isoformat() if self.expires_at else None,
|
||||
'is_expired': self.is_expired(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user