Skip to content

Commit 190a274

Browse files
efratushyammesicka
andauthored
Feature/waze + Fix event (#313)
* add waze link and fix edit_event_datails_tab.hatml * Add documentation to the 'get_waze_link' function. * Fix: vc_link can be null * Fix CR: block title and + Change the order of the rows in the get_waze_link function Co-authored-by: Yam Mesicka <yammesicka@gmail.com>
1 parent 5a5b191 commit 190a274

File tree

7 files changed

+240
-15
lines changed

7 files changed

+240
-15
lines changed

app/database/models.py

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

app/routers/event.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
from operator import attrgetter
44
from typing import Any, Dict, List, Optional, Tuple
5+
import urllib
56

67
from fastapi import APIRouter, Depends, HTTPException, Request
78
from pydantic import BaseModel
@@ -160,6 +161,23 @@ async def create_new_event(
160161
)
161162

162163

164+
def get_waze_link(event: Event) -> str:
165+
"""Get a waze navigation link to the event location.
166+
167+
Returns:
168+
If there are coordinates, waze will navigate to the exact location.
169+
Otherwise, waze will look for the address that appears in the location.
170+
If there is no address, an empty string will be returned."""
171+
172+
if not event.location:
173+
return ""
174+
# if event.latitude and event.longitude:
175+
# coordinates = f"{event.latitude},{event.longitude}"
176+
# return f"https://waze.com/ul?ll={coordinates}&navigate=yes"
177+
url_location = urllib.parse.quote(event.location)
178+
return f"https://waze.com/ul?q={url_location}&navigate=yes"
179+
180+
163181
def raise_for_nonexisting_event(event_id: int) -> None:
164182
error_message = f"Event ID does not exist. ID: {event_id}"
165183
logger.exception(error_message)
@@ -180,6 +198,7 @@ async def eventview(
180198
if event.all_day:
181199
start_format = "%A, %d/%m/%Y"
182200
end_format = ""
201+
waze_link = get_waze_link(event)
183202
event_considering_privacy = event_to_show(event, db)
184203
if not event_considering_privacy:
185204
raise_for_nonexisting_event(event.id)
@@ -188,6 +207,7 @@ async def eventview(
188207
"eventview.html",
189208
{
190209
"request": request,
210+
"waze_link": waze_link,
191211
"event": event_considering_privacy,
192212
"comments": comments,
193213
"start_format": start_format,
@@ -597,11 +617,13 @@ async def view_comments(
597617
This essentially the same as `eventedit`, only with comments tab auto
598618
showed."""
599619
event, comments, end_format = get_event_data(db, event_id)
620+
waze_link = get_waze_link(event)
600621
return templates.TemplateResponse(
601622
"eventview.html",
602623
{
603624
"request": request,
604625
"event": event,
626+
"waze_link": waze_link,
605627
"comments": comments,
606628
"comment": True,
607629
"start_format": START_FORMAT,

app/static/images/icons/waze.svg

Lines changed: 172 additions & 0 deletions
Loading

app/templates/eventview.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
<link href="{{ url_for('static', path='event/eventview.css') }}" rel="stylesheet">
1+
{% extends 'base.html' %}
2+
3+
{% block head %}
4+
{{ super() }}
5+
{% block title %}
6+
View Event
7+
{% endblock %}
8+
<link href="{{ url_for('static', path='event/eventview.css') }}" rel="stylesheet">
9+
{% endblock head %}
10+
11+
{% block content %}
212
<div class = "event_view_wrapper container col col-12">
313
<!-- Temporary nav layout based on bootstrap -->
414
<ul class="nav nav-tabs" id="event_view_nav" role="tablist">
@@ -33,3 +43,4 @@
3343
</div> -->
3444
</div>
3545
</div>
46+
{% endblock content %}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<div class="form_row">
2-
<input id="say" type="text" name="title" placeholder="Event Title" required>
3-
<input type="button" id="speak" name="speak" value="Speak it!">
4-
</div
5-
>
2+
<input id="say" type="text" name="title" placeholder="Event Title" required>
3+
<input type="button" id="speak" name="speak" value="Speak it!">
4+
</div>
65
<div class="form_row">
6+
<!-- Voices gets its own row for being so wide! -->
77
<div class="field" id="voices">
88
<label for="voice">Voice</label>
99
<select id="voice" name="voice"></select>
@@ -40,18 +40,18 @@
4040
</div>
4141

4242
<div class="form_row">
43-
<label for="location">Location </label>
44-
<input type="text" id="location" name="location" placeholder="Location">
43+
<label for="location">Location </label>
44+
<input type="text" id="location" name="location" placeholder="Location">
4545
</div>
4646

4747
<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">
48+
<label for="vc_link">VC link: </label>
49+
<input type="text" id="vc_link" name="vc_link" placeholder="VC URL">
5050
</div>
5151

5252
<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">
53+
<label for="invited">Invited emails: </label>
54+
<input type="text" id="invited" name="invited" placeholder="Invited emails, separated by commas">
5555
</div>
5656

5757
<div class="form_row textarea">
@@ -77,8 +77,8 @@
7777

7878
<label for="availability">Availability:</label>
7979
<select id="availability" name="availability">
80-
<option value="free">Free</option>
81-
<option value="busy" selected>Busy</option>
80+
<option value="True">Free</option>
81+
<option value="False" selected>Busy</option>
8282
</select>
8383

8484
<label for="privacy">Privacy:</label>

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,18 @@ <h1>{{ event.title }}</h1>
2222
<!-- <span>Repeats every INTERVAL</span>-->
2323
<!--</div>-->
2424

25+
{% if event.location %}
2526
<div class="event_info_row">
26-
<span class="icon">ICON</span>
27+
<span class="icon"><a href="{{ waze_link }}" target="_blank"><img src="{{ url_for('static', path='images/icons/waze.svg') }}" alt="icon wase" width="30" height="30"></a></span>
2728
<address>{{ event.location }}</address>
29+
</div>
30+
{% endif %}
31+
{% if event.vc_link %}
32+
<div class="event_info_row">
33+
<span class="icon">ICON</span>
2834
<address>VC link<a href="{{ event.vc_link }}">VC URL</a></address>
2935
</div>
36+
{% endif %}
3037
{% if event.invitees %}
3138
<form method="POST" action="/event/{{event.id}}/owner">
3239
<div class="mb-3"></div>

tests/test_event.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,19 @@ def test_eventview_with_id(event_test_client, session, event):
164164
response = event_test_client.get(f"/event/{event_id}")
165165
assert response.ok
166166
assert b"Event Details" in response.content
167+
assert b"View Event" in response.content
168+
assert b"Some random location" in response.content
169+
waze_link = b"https://waze.com/ul?q=Some%20random%20location"
170+
assert waze_link in response.content
171+
assert b'VC link' not in response.content
172+
173+
174+
def test_eventview_without_location(event_test_client, session, event):
175+
event_id = event.id
176+
event.location = None
177+
session.commit()
178+
response = event_test_client.get(f"/event/{event_id}")
179+
assert b"https://waze.com/ul" not in response.content
167180

168181

169182
def test_all_day_eventview_with_id(event_test_client, session, all_day_event):

0 commit comments

Comments
 (0)