Skip to content

Commit 05c90a1

Browse files
committed
merging changes from pulled code
2 parents e8571f1 + 1048956 commit 05c90a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3292
-2141
lines changed

app/config.py.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ CALENDAR_HOME_PAGE = "calendar.pythonic.guru"
7272
# link to the application registration page
7373
CALENDAR_REGISTRATION_PAGE = r"calendar.pythonic.guru/registration"
7474

75-
# import
75+
# IMPORT
7676
MAX_FILE_SIZE_MB = 5 # 5MB
7777
VALID_FILE_EXTENSION = (".txt", ".csv", ".ics") # Can import only these files.
7878
# Events must be within 20 years range from the current year.
7979
EVENT_VALID_YEARS = 20
80-
EVENT_HEADER_NOT_EMPTY = 1 # 1- for not empty, 0- for empty.
80+
EVENT_HEADER_NOT_EMPTY = True
8181
EVENT_HEADER_LIMIT = 50 # Max characters for event header.
8282
EVENT_CONTENT_LIMIT = 500 # Max characters for event content.
8383
MAX_EVENTS_START_DATE = 10 # Max Events with the same start date.

app/database/models.py

Lines changed: 111 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,31 @@
44
from typing import Any, Dict
55

66
from sqlalchemy import (
7-
Boolean, Column, DateTime, DDL, event, Float, ForeignKey, Index, Integer,
8-
JSON, String, Time, UniqueConstraint)
7+
Boolean,
8+
Column,
9+
DateTime,
10+
DDL,
11+
event,
12+
Float,
13+
ForeignKey,
14+
Index,
15+
Integer,
16+
JSON,
17+
String,
18+
Time,
19+
UniqueConstraint,
20+
)
921
from sqlalchemy.dialects.postgresql import TSVECTOR
1022
from sqlalchemy.exc import IntegrityError, SQLAlchemyError
11-
from sqlalchemy.ext.declarative.api import declarative_base
23+
from sqlalchemy.ext.declarative.api import declarative_base, DeclarativeMeta
1224
from sqlalchemy.orm import relationship, Session
1325
from sqlalchemy.sql.schema import CheckConstraint
1426

1527
from app.config import PSQL_ENVIRONMENT
1628
from app.dependencies import logger
1729
import app.routers.salary.config as SalaryConfig
1830

19-
Base = declarative_base()
31+
Base: DeclarativeMeta = declarative_base()
2032

2133

2234
class User(Base):
@@ -38,28 +50,36 @@ class User(Base):
3850
availability = Column(Boolean, default=True, nullable=False)
3951

4052
owned_events = relationship(
41-
"Event", cascade="all, delete", back_populates="owner",
53+
"Event",
54+
cascade="all, delete",
55+
back_populates="owner",
4256
)
4357
events = relationship(
44-
"UserEvent", cascade="all, delete", back_populates="participants",
58+
"UserEvent",
59+
cascade="all, delete",
60+
back_populates="participants",
4561
)
4662
salary_settings = relationship(
47-
"SalarySettings", cascade="all, delete", back_populates="user",
63+
"SalarySettings",
64+
cascade="all, delete",
65+
back_populates="user",
4866
)
4967
comments = relationship("Comment", back_populates="user")
5068

5169
oauth_credentials = relationship(
52-
"OAuthCredentials", cascade="all, delete", back_populates="owner",
53-
uselist=False)
70+
"OAuthCredentials",
71+
cascade="all, delete",
72+
back_populates="owner",
73+
uselist=False,
74+
)
5475

5576
def __repr__(self):
56-
return f'<User {self.id}>'
77+
return f"<User {self.id}>"
5778

5879
@staticmethod
5980
async def get_by_username(db: Session, username: str) -> User:
6081
"""query database for a user by unique username"""
61-
return db.query(User).filter(
62-
User.username == username).first()
82+
return db.query(User).filter(User.username == username).first()
6383

6484

6585
class Event(Base):
@@ -70,7 +90,7 @@ class Event(Base):
7090
start = Column(DateTime, nullable=False)
7191
end = Column(DateTime, nullable=False)
7292
content = Column(String)
73-
location = Column(String)
93+
location = Column(String, nullable=True)
7494
is_google_event = Column(Boolean, default=False)
7595
vc_link = Column(String)
7696
color = Column(String, nullable=True)
@@ -85,37 +105,35 @@ class Event(Base):
85105

86106
owner = relationship("User", back_populates="owned_events")
87107
participants = relationship(
88-
"UserEvent", cascade="all, delete", back_populates="events",
108+
"UserEvent",
109+
cascade="all, delete",
110+
back_populates="events",
89111
)
90112
comments = relationship("Comment", back_populates="event")
91113

92114
# PostgreSQL
93115
if PSQL_ENVIRONMENT:
94116
events_tsv = Column(TSVECTOR)
95-
__table_args__ = (Index(
96-
'events_tsv_idx',
97-
'events_tsv',
98-
postgresql_using='gin'),
117+
__table_args__ = (
118+
Index("events_tsv_idx", "events_tsv", postgresql_using="gin"),
99119
)
100120

101121
def __repr__(self):
102-
return f'<Event {self.id}>'
122+
return f"<Event {self.id}>"
103123

104124

105125
class UserEvent(Base):
106126
__tablename__ = "user_event"
107127

108128
id = Column(Integer, primary_key=True, index=True)
109-
user_id = Column('user_id', Integer, ForeignKey(
110-
'users.id'), nullable=False)
111-
event_id = Column('event_id', Integer, ForeignKey(
112-
'events.id'), nullable=False)
129+
user_id = Column("user_id", Integer, ForeignKey("users.id"))
130+
event_id = Column("event_id", Integer, ForeignKey("events.id"))
113131

114132
events = relationship("Event", back_populates="participants")
115133
participants = relationship("User", back_populates="events")
116134

117135
def __repr__(self):
118-
return f'<UserEvent ({self.participants}, {self.events})>'
136+
return f"<UserEvent ({self.participants}, {self.events})>"
119137

120138

121139
class Language(Base):
@@ -128,17 +146,19 @@ class Language(Base):
128146
class Category(Base):
129147
__tablename__ = "categories"
130148

131-
__table_args__ = (
132-
UniqueConstraint('user_id', 'name', 'color'),
133-
)
149+
__table_args__ = (UniqueConstraint("user_id", "name", "color"),)
134150
id = Column(Integer, primary_key=True, index=True)
135151
name = Column(String, nullable=False)
136152
color = Column(String, nullable=False)
137153
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
138154

139155
@staticmethod
140-
def create(db_session: Session, name: str, color: str,
141-
user_id: int) -> Category:
156+
def create(
157+
db_session: Session,
158+
name: str,
159+
color: str,
160+
user_id: int,
161+
) -> Category:
142162
try:
143163
category = Category(name=name, color=color, user_id=user_id)
144164
db_session.add(category)
@@ -155,7 +175,7 @@ def to_dict(self) -> Dict[str, Any]:
155175
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
156176

157177
def __repr__(self) -> str:
158-
return f'<Category {self.id} {self.name} {self.color}>'
178+
return f"<Category {self.id} {self.name} {self.color}>"
159179

160180

161181
class PSQLEnvironmentError(Exception):
@@ -164,17 +184,19 @@ class PSQLEnvironmentError(Exception):
164184

165185
# PostgreSQL
166186
if PSQL_ENVIRONMENT:
167-
trigger_snippet = DDL("""
187+
trigger_snippet = DDL(
188+
"""
168189
CREATE TRIGGER ix_events_tsv_update BEFORE INSERT OR UPDATE
169190
ON events
170191
FOR EACH ROW EXECUTE PROCEDURE
171192
tsvector_update_trigger(events_tsv,'pg_catalog.english','title','content')
172-
""")
193+
""",
194+
)
173195

174196
event.listen(
175197
Event.__table__,
176-
'after_create',
177-
trigger_snippet.execute_if(dialect='postgresql')
198+
"after_create",
199+
trigger_snippet.execute_if(dialect="postgresql"),
178200
)
179201

180202

@@ -191,11 +213,7 @@ class Invitation(Base):
191213
event = relationship("Event")
192214

193215
def __repr__(self):
194-
return (
195-
f'<Invitation '
196-
f'({self.event.owner}'
197-
f'to {self.recipient})>'
198-
)
216+
return f"<Invitation " f"({self.event.owner}" f"to {self.recipient})>"
199217

200218

201219
class OAuthCredentials(Base):
@@ -220,60 +238,87 @@ class SalarySettings(Base):
220238
__tablename__ = "salary_settings"
221239

222240
user_id = Column(
223-
Integer, ForeignKey("users.id"), primary_key=True,
241+
Integer,
242+
ForeignKey("users.id"),
243+
primary_key=True,
224244
)
225245
# category_id = Column(
226246
# Integer, ForeignKey("categories.id"), primary_key=True,
227247
# )
228248
category_id = Column(
229-
Integer, primary_key=True,
249+
Integer,
250+
primary_key=True,
230251
)
231252
wage = Column(
232-
Float, nullable=False, default=SalaryConfig.MINIMUM_WAGE,
253+
Float,
254+
nullable=False,
255+
default=SalaryConfig.MINIMUM_WAGE,
233256
)
234257
off_day = Column(
235-
Integer, CheckConstraint("0<=off_day<=6"), nullable=False,
258+
Integer,
259+
CheckConstraint("0<=off_day<=6"),
260+
nullable=False,
236261
default=SalaryConfig.SATURDAY,
237262
)
238263
# holiday_category_id = Column(
239264
# Integer, ForeignKey("holiday_categories.id"), nullable=False,
240265
# default=SalaryConfig.ISRAELI_JEWISH,
241266
# )
242267
holiday_category_id = Column(
243-
Integer, nullable=False,
268+
Integer,
269+
nullable=False,
244270
default=SalaryConfig.ISRAELI_JEWISH,
245271
)
246272
regular_hour_basis = Column(
247-
Float, nullable=False, default=SalaryConfig.REGULAR_HOUR_BASIS,
273+
Float,
274+
nullable=False,
275+
default=SalaryConfig.REGULAR_HOUR_BASIS,
248276
)
249277
night_hour_basis = Column(
250-
Float, nullable=False, default=SalaryConfig.NIGHT_HOUR_BASIS,
278+
Float,
279+
nullable=False,
280+
default=SalaryConfig.NIGHT_HOUR_BASIS,
251281
)
252282
night_start = Column(
253-
Time, nullable=False, default=SalaryConfig.NIGHT_START,
283+
Time,
284+
nullable=False,
285+
default=SalaryConfig.NIGHT_START,
254286
)
255287
night_end = Column(
256-
Time, nullable=False, default=SalaryConfig.NIGHT_END,
288+
Time,
289+
nullable=False,
290+
default=SalaryConfig.NIGHT_END,
257291
)
258292
night_min_len = Column(
259-
Time, nullable=False, default=SalaryConfig.NIGHT_MIN_LEN,
293+
Time,
294+
nullable=False,
295+
default=SalaryConfig.NIGHT_MIN_LEN,
260296
)
261297
first_overtime_amount = Column(
262-
Float, nullable=False, default=SalaryConfig.FIRST_OVERTIME_AMOUNT,
298+
Float,
299+
nullable=False,
300+
default=SalaryConfig.FIRST_OVERTIME_AMOUNT,
263301
)
264302
first_overtime_pay = Column(
265-
Float, nullable=False, default=SalaryConfig.FIRST_OVERTIME_PAY,
303+
Float,
304+
nullable=False,
305+
default=SalaryConfig.FIRST_OVERTIME_PAY,
266306
)
267307
second_overtime_pay = Column(
268-
Float, nullable=False, default=SalaryConfig.SECOND_OVERTIME_PAY,
308+
Float,
309+
nullable=False,
310+
default=SalaryConfig.SECOND_OVERTIME_PAY,
269311
)
270312
week_working_hours = Column(
271-
Float, nullable=False, default=SalaryConfig.WEEK_WORKING_HOURS,
313+
Float,
314+
nullable=False,
315+
default=SalaryConfig.WEEK_WORKING_HOURS,
272316
)
273317
daily_transport = Column(
274-
Float, CheckConstraint(
275-
f"daily_transport<={SalaryConfig.MAXIMUM_TRANSPORT}"),
276-
nullable=False, default=SalaryConfig.STANDARD_TRANSPORT,
318+
Float,
319+
CheckConstraint(f"daily_transport<={SalaryConfig.MAXIMUM_TRANSPORT}"),
320+
nullable=False,
321+
default=SalaryConfig.STANDARD_TRANSPORT,
277322
)
278323

279324
user = relationship("User", back_populates="salary_settings")
@@ -283,7 +328,7 @@ class SalarySettings(Base):
283328
# back_populates="salary_settings")
284329

285330
def __repr__(self):
286-
return f'<SalarySettings ({self.user_id}, {self.category_id})>'
331+
return f"<SalarySettings ({self.user_id}, {self.category_id})>"
287332

288333

289334
class WikipediaEvents(Base):
@@ -317,7 +362,7 @@ class Comment(Base):
317362
event = relationship("Event", back_populates="comments")
318363

319364
def __repr__(self):
320-
return f'<Comment {self.id}>'
365+
return f"<Comment {self.id}>"
321366

322367

323368
class Zodiac(Base):
@@ -332,10 +377,10 @@ class Zodiac(Base):
332377

333378
def __repr__(self):
334379
return (
335-
f'<Zodiac '
336-
f'{self.name} '
337-
f'{self.start_day_in_month}/{self.start_month}-'
338-
f'{self.end_day_in_month}/{self.end_month}>'
380+
f"<Zodiac "
381+
f"{self.name} "
382+
f"{self.start_day_in_month}/{self.start_month}-"
383+
f"{self.end_day_in_month}/{self.end_month}>"
339384
)
340385

341386

@@ -346,7 +391,9 @@ def __repr__(self):
346391
def insert_data(target, session: Session, **kw):
347392
session.execute(
348393
target.insert(),
349-
{'id': 1, 'name': 'English'}, {'id': 2, 'name': 'עברית'})
394+
{"id": 1, "name": "English"},
395+
{"id": 2, "name": "עברית"},
396+
)
350397

351398

352-
event.listen(Language.__table__, 'after_create', insert_data)
399+
event.listen(Language.__table__, "after_create", insert_data)

0 commit comments

Comments
 (0)