Spaces:
Runtime error
Runtime error
File size: 1,939 Bytes
cc7f27e a0a863b cc7f27e 4d65d15 cc7f27e 984c8a5 cc7f27e 5819732 cc7f27e a0a863b 3bea94b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | from enum import Enum as PyEnum
from sqlalchemy import Column, DateTime, Enum, ForeignKey, Integer, String, func
from sqlalchemy.orm import relationship
from ._base import Base
class ContentDeliveryFrequency(PyEnum):
DAILY = "DAILY"
WEEKLY = "WEEKLY"
BI_WEEKLY = "BI_WEEKLY"
MONTHLY = "MONTHLY"
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
name = Column(String, nullable=False)
content_delivery_frequency = Column(
Enum(ContentDeliveryFrequency),
nullable=False,
default=ContentDeliveryFrequency.WEEKLY,
)
slack_id = Column(String, nullable=True)
slack_team_id = Column(
Integer,
ForeignKey("slack_teams.id"),
nullable=True,
)
email_id = Column(String, nullable=False, unique=True)
last_message_sent_at = Column(DateTime, nullable=True)
next_content_delivery_date = Column(DateTime, nullable=True)
created_at = Column(DateTime, nullable=False, default=func.now())
slack_team = relationship("SlackTeam", back_populates="users")
files = relationship("File", back_populates="user", cascade="all, delete-orphan")
personalized_contents = relationship(
"PersonalizedContent", back_populates="user", cascade="all, delete-orphan"
)
def __repr__(self):
return f"<User id={self.id}, name={self.name}, email_id={self.email_id}>"
def to_dict(self):
return {
"id": self.id,
"name": self.name,
"content_delivery_frequency": self.content_delivery_frequency,
"slack_id": self.slack_id,
"slack_team_id": self.slack_team_id,
"email_id": self.email_id,
"last_message_sent_at": self.last_message_sent_at,
"next_content_delivery_date": self.next_content_delivery_date,
"created_at": self.created_at,
}
|