Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions app/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ class User(Base):

events = relationship("UserEvent", back_populates="participants")

speedy_meetings_enabled = Column(Boolean, default=False)

events = relationship(
"Event", cascade="all, delete", back_populates="owner")

def has_speedy_meetings_enabled(self) -> bool:
return self.speedy_meetings_enabled
def __repr__(self):
return f'<User {self.id}>'

Expand All @@ -48,6 +55,7 @@ class Event(Base):
title = Column(String, nullable=False)
start = Column(DateTime, nullable=False)
end = Column(DateTime, nullable=False)
default_end = get_default_end_time()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is part of the ORM, it must be of type Column or a relationship.

You can check the SQLAlchemy docs to see how to add default value to the end column.

content = Column(String)
location = Column(String)

Expand All @@ -70,6 +78,24 @@ def __repr__(self):
return f'<Event {self.id}>'


owner = relationship("User", back_populates="events")

user = get_user_by_id(owner_id)

def get_user_by_id(self, owner_id):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it needed? can't we just call user.owner?

return owner

def get_default_end_time(self):
return start + get_event_duration()

def get_event_duration(self):
default_duration = get_default_duration()
if user.has_speedy_meetings_enabled():
return default_duration * .75
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is 0.75?

return default_duration

def get_default_duration(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it's part of the table model?

return 60
class PSQLEnvironmentError(Exception):
pass

Expand Down Expand Up @@ -116,3 +142,4 @@ class Quote(Base):
id = Column(Integer, primary_key=True, index=True)
text = Column(String, nullable=False)
author = Column(String)