Skip to content

Commit 46e0deb

Browse files
authored
fix: event backend and frontend creation (#329)
1 parent d7450b6 commit 46e0deb

File tree

4 files changed

+63
-43
lines changed

4 files changed

+63
-43
lines changed

app/database/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class Event(Base):
9393
content = Column(String)
9494
location = Column(String, nullable=True)
9595
is_google_event = Column(Boolean, default=False)
96-
vc_link = Column(String)
96+
vc_link = Column(String, nullable=True)
9797
color = Column(String, nullable=True)
9898
all_day = Column(Boolean, default=False)
9999
invitees = Column(String)

app/internal/event.py

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,55 @@
99

1010
from app.database.models import Event
1111

12-
ZOOM_REGEX = re.compile(r'https://.*?\.zoom.us/[a-z]/.[^.,\b\s]+')
12+
ZOOM_REGEX = re.compile(r"https://.*?\.zoom.us/[a-z]/.[^.,\b\s]+")
1313

1414

1515
def raise_if_zoom_link_invalid(vc_link):
1616
if ZOOM_REGEX.search(vc_link) is None:
17-
raise HTTPException(status_code=HTTP_400_BAD_REQUEST,
18-
detail="VC type with no valid zoom link")
17+
raise HTTPException(
18+
status_code=HTTP_400_BAD_REQUEST,
19+
detail="VC type with no valid zoom link",
20+
)
1921

2022

2123
def get_invited_emails(invited_from_form: str) -> List[str]:
2224
invited_emails = []
23-
for invited_email in invited_from_form.split(','):
25+
if not invited_from_form:
26+
return [""]
27+
for invited_email in invited_from_form.split(","):
2428
invited_email = invited_email.strip()
2529
try:
2630
validate_email(invited_email, check_deliverability=False)
2731
except EmailSyntaxError:
28-
logging.exception(f'{invited_email} is not a valid email address')
29-
continue
30-
invited_emails.append(invited_email)
32+
logging.exception(
33+
f"{invited_email} is not a valid email address",
34+
)
35+
else:
36+
invited_emails.append(invited_email)
3137

3238
return invited_emails
3339

3440

35-
def get_uninvited_regular_emails(session: Session,
36-
owner_id: int,
37-
title: str,
38-
invited_emails: List[str]) -> Set[str]:
41+
def get_uninvited_regular_emails(
42+
session: Session,
43+
owner_id: int,
44+
title: str,
45+
invited_emails: List[str],
46+
) -> Set[str]:
3947
invitees_query = session.query(Event).with_entities(Event.invitees)
40-
similar_events_invitees = invitees_query.filter(Event.owner_id == owner_id,
41-
Event.title == title).all()
48+
similar_events_invitees = invitees_query.filter(
49+
Event.owner_id == owner_id,
50+
Event.title == title,
51+
).all()
4252
regular_invitees = set()
4353
for record in similar_events_invitees:
4454
if record:
45-
regular_invitees.update(record[0].split(','))
55+
regular_invitees.update(record[0].split(","))
4656

4757
return regular_invitees - set(invited_emails)
4858

4959

50-
def check_diffs(checked_event: Event,
51-
all_events: List[Event]):
60+
def check_diffs(checked_event: Event, all_events: List[Event]):
5261
"""Returns the repeated events and the week difference"""
5362
diffs = []
5463
for event in all_events:
@@ -65,22 +74,30 @@ def check_diffs(checked_event: Event,
6574

6675

6776
def find_pattern(session, event):
68-
all_events_with_same_name = session.query(Event).filter(
69-
Event.owner_id == event.owner_id, Event.title == event.title).all()
77+
all_events_with_same_name = (
78+
session.query(Event)
79+
.filter(Event.owner_id == event.owner_id, Event.title == event.title)
80+
.all()
81+
)
7082

7183
return check_diffs(event, all_events_with_same_name)
7284

7385

74-
def get_messages(session: Session,
75-
event: Event,
76-
uninvited_contacts: Set[str]) -> List[str]:
86+
def get_messages(
87+
session: Session,
88+
event: Event,
89+
uninvited_contacts: Set[str],
90+
) -> List[str]:
7791
messages = []
7892
if uninvited_contacts:
79-
messages.append(f'Forgot to invite '
80-
f'{", ".join(uninvited_contacts)} maybe?')
93+
messages.append(
94+
f"Forgot to invite " f'{", ".join(uninvited_contacts)} maybe?',
95+
)
8196

8297
pattern = find_pattern(session, event)
8398
for weeks_diff in pattern:
84-
messages.append(f'Same event happened {weeks_diff} weeks before too. '
85-
f'Want to create another one {weeks_diff} after too?')
99+
messages.append(
100+
f"Same event happened {weeks_diff} weeks before too. "
101+
f"Want to create another one {weeks_diff} after too?",
102+
)
86103
return messages

app/routers/event.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def create_event_api(event: EventModel, session=Depends(get_db)):
7272
db=session,
7373
title=event.title,
7474
start=event.start,
75-
end=event.start,
75+
end=event.end,
7676
content=event.content,
7777
owner_id=event.owner_id,
7878
location=event.location,
@@ -117,7 +117,7 @@ async def create_new_event(
117117
location = data["location"]
118118
all_day = data["event_type"] and data["event_type"] == "on"
119119

120-
vc_link = data["vc_link"]
120+
vc_link = data.get("vc_link")
121121
category_id = data.get("category_id")
122122
privacy = data["privacy"]
123123
privacy_kinds = [kind.name for kind in PrivacyKinds]
@@ -132,7 +132,7 @@ async def create_new_event(
132132
invited_emails,
133133
)
134134

135-
if vc_link is not None:
135+
if vc_link:
136136
raise_if_zoom_link_invalid(vc_link)
137137

138138
event = create_event(

app/templates/partials/calendar/event/edit_event_details_tab.html

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,22 @@
4040
</div>
4141

4242
<div class="form_row">
43-
<label for="location_type">Location Type:</label>
44-
<select id="location_type" name="location_type" required>
45-
<option value="" disabled selected>Type</option>
46-
<option value="vc_url">VC URL</option>
47-
<option value="address">Address</option>
48-
</select>
49-
<input type="text" name="location" placeholder="VC URL/Location">
43+
<label for="location">Location </label>
44+
<input type="text" id="location" name="location" placeholder="Location">
5045
</div>
5146

52-
<div class="form_row textarea">
53-
<textarea id="say" name="description" placeholder="Description"></textarea>
47+
<div class="form_row">
48+
<label for="vc_link">VC link: </label>
49+
<input type="text" id="vc_link" name="vc_link" placeholder="VC URL">
5450
</div>
5551

5652
<div class="form_row">
57-
<label for="event_type">All-day:</label>
58-
<select id="event_type" name="event_type" required>
59-
<option value="on">Yes</option>
60-
<option value="off" selected>No</option>
61-
</select>
53+
<label for="invited">Invited emails: </label>
54+
<input type="text" id="invited" name="invited" placeholder="Invited emails, separated by commas">
55+
</div>
56+
57+
<div class="form_row textarea">
58+
<textarea id="say" name="description" placeholder="Description"></textarea>
6259
</div>
6360

6461
<div class="form_row">
@@ -72,6 +69,12 @@
7269
</div>
7370

7471
<div class="form_row_end">
72+
<label for="event_type">All-day:</label>
73+
<select id="event_type" name="event_type" required>
74+
<option value="on">Yes</option>
75+
<option value="off" selected>No</option>
76+
</select>
77+
7578
<label for="availability">Availability:</label>
7679
<select id="availability" name="availability">
7780
<option value="free">Free</option>

0 commit comments

Comments
 (0)