Skip to content

Commit 3f88f17

Browse files
committed
fix: event backend and frontend creation
1 parent ab1d671 commit 3f88f17

File tree

4 files changed

+63
-40
lines changed

4 files changed

+63
-40
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: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,56 @@
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(','):
24-
invited_email = invited_email.strip()
25-
try:
26-
validate_email(invited_email, check_deliverability=False)
27-
except EmailSyntaxError:
28-
logging.exception(f'{invited_email} is not a valid email address')
29-
continue
30-
invited_emails.append(invited_email)
25+
if not invited_from_form:
26+
invited_emails.append("")
27+
else:
28+
for invited_email in invited_from_form.split(","):
29+
invited_email = invited_email.strip()
30+
try:
31+
validate_email(invited_email, check_deliverability=False)
32+
except EmailSyntaxError:
33+
logging.exception(
34+
f"{invited_email} is not a valid email address",
35+
)
36+
continue
37+
invited_emails.append(invited_email)
3138

3239
return invited_emails
3340

3441

35-
def get_uninvited_regular_emails(session: Session,
36-
owner_id: int,
37-
title: str,
38-
invited_emails: List[str]) -> Set[str]:
42+
def get_uninvited_regular_emails(
43+
session: Session,
44+
owner_id: int,
45+
title: str,
46+
invited_emails: List[str],
47+
) -> Set[str]:
3948
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()
49+
similar_events_invitees = invitees_query.filter(
50+
Event.owner_id == owner_id,
51+
Event.title == title,
52+
).all()
4253
regular_invitees = set()
4354
for record in similar_events_invitees:
4455
if record:
45-
regular_invitees.update(record[0].split(','))
56+
regular_invitees.update(record[0].split(","))
4657

4758
return regular_invitees - set(invited_emails)
4859

4960

50-
def check_diffs(checked_event: Event,
51-
all_events: List[Event]):
61+
def check_diffs(checked_event: Event, all_events: List[Event]):
5262
"""Returns the repeated events and the week difference"""
5363
diffs = []
5464
for event in all_events:
@@ -65,22 +75,30 @@ def check_diffs(checked_event: Event,
6575

6676

6777
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()
78+
all_events_with_same_name = (
79+
session.query(Event)
80+
.filter(Event.owner_id == event.owner_id, Event.title == event.title)
81+
.all()
82+
)
7083

7184
return check_diffs(event, all_events_with_same_name)
7285

7386

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

8298
pattern = find_pattern(session, event)
8399
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?')
100+
messages.append(
101+
f"Same event happened {weeks_diff} weeks before too. "
102+
f"Want to create another one {weeks_diff} after too?",
103+
)
86104
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: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,18 @@
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">
45+
</div>
46+
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">
50+
</div>
51+
52+
<div class="form_row">
53+
<label for="invited">Invited emails: </label>
54+
<input type="text" id="invited" name="invited" placeholder="Invited emails, separated by commas">
5055
</div>
5156

5257
<div class="form_row textarea">

0 commit comments

Comments
 (0)