Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
469900d
Version 1.00
Eliory09 Feb 2, 2021
f7942ac
add: geolocation support for events
Eliory09 Feb 2, 2021
42f8540
fix: minor fix to eventview page
Eliory09 Feb 2, 2021
924331a
fix: minor changes
Eliory09 Feb 2, 2021
ec804c8
fix: minor fixes
Eliory09 Feb 3, 2021
1da45a6
fix: flake8 typo fixes
Eliory09 Feb 3, 2021
142d32d
fix: update requirements.txt
Eliory09 Feb 3, 2021
3459d19
fix: minor changes
Eliory09 Feb 3, 2021
a7c1244
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
Eliory09 Feb 5, 2021
8a51777
fix: minor typo changes, event color support
Eliory09 Feb 5, 2021
340f316
fix: minor changes, tests fixes
Eliory09 Feb 5, 2021
b7991bd
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
Eliory09 Feb 7, 2021
3ce26aa
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
Eliory09 Feb 8, 2021
fff5c85
fix: minor changes
Eliory09 Feb 8, 2021
ae10219
fix: requirements file
Eliory09 Feb 8, 2021
5164230
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
Eliory09 Feb 10, 2021
7564610
fix: minor changes, location func is now internal
Eliory09 Feb 10, 2021
5f4a98b
fix: .DS_Store is now ignored
Eliory09 Feb 10, 2021
6d05224
fix: .DS_Store is now ignored
Eliory09 Feb 10, 2021
d22336e
feat: event update now support geolocation
Eliory09 Feb 10, 2021
5fff47c
Merge branch 'develop' into feature/geolocation
yammesicka Feb 11, 2021
6a47c98
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
Eliory09 Feb 12, 2021
cabc13d
fix: typo changes, async support
Eliory09 Feb 13, 2021
07c5620
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
Eliory09 Feb 13, 2021
f83e939
fix: minor changes
Eliory09 Feb 13, 2021
da783b2
fix: minor typo changes
Eliory09 Feb 13, 2021
de0bb59
fix: minor typo changes
Eliory09 Feb 13, 2021
850b773
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
Eliory09 Feb 14, 2021
b1874cc
fix: minor change.
Eliory09 Feb 14, 2021
4809563
fix: minor changes.
Eliory09 Feb 14, 2021
e104964
Merge branch 'feature/geolocation' of https://github.com/Eliory09/cal…
Eliory09 Feb 14, 2021
b46e737
fix: typo change.
Eliory09 Feb 14, 2021
79e5bad
fix: updated requirements.txt
Eliory09 Feb 14, 2021
69a22d6
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
Eliory09 Feb 20, 2021
d263102
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
Eliory09 Feb 20, 2021
8d847f9
fix: minor fixes, async support
Eliory09 Feb 20, 2021
2474c14
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
Eliory09 Feb 20, 2021
c082ee2
fix: minor tests fixes
Eliory09 Feb 20, 2021
2b59fb0
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
Eliory09 Feb 22, 2021
489fbbc
fix: minor code changes, improve async support
Eliory09 Feb 22, 2021
8f69b28
fix: aiohttp added to requirements.txt
Eliory09 Feb 22, 2021
3d9ebec
fix: requirements.txt
Eliory09 Feb 22, 2021
555d577
fix: minor fixes
Eliory09 Feb 22, 2021
392a07e
fix: bug fixes
Eliory09 Feb 22, 2021
8041d90
fix: typo
Eliory09 Feb 22, 2021
f33dcee
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
Eliory09 Feb 23, 2021
9d4e1c3
fix: reordered imports
Eliory09 Feb 24, 2021
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
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,7 @@ app/routers/stam
.idea

junit/

# .DS_Store
.DS_Store
DS_Store
2 changes: 2 additions & 0 deletions app/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class Event(Base):
end = Column(DateTime, nullable=False)
Copy link
Member

Choose a reason for hiding this comment

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

Remove the .DS_Store file and add it to the .gitignore

Copy link
Author

Choose a reason for hiding this comment

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

It seems I can't delete the file already uploaded for some reason.
Can you help?

Copy link
Member

Choose a reason for hiding this comment

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

git rm .DS_Store

content = Column(String)
location = Column(String, nullable=True)
latitude = Column(String, nullable=True)
longitude = Column(String, nullable=True)
vc_link = Column(String, nullable=True)
is_google_event = Column(Boolean, default=False)
color = Column(String, nullable=True)
Expand Down
38 changes: 37 additions & 1 deletion app/internal/event.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import logging
import re
from typing import List, Set
from typing import List, NamedTuple, Set, Union

from email_validator import EmailSyntaxError, validate_email
from fastapi import HTTPException
from geopy.adapters import AioHTTPAdapter
from geopy.exc import GeocoderTimedOut, GeocoderUnavailable
from geopy.geocoders import Nominatim
from loguru import logger
from sqlalchemy.orm import Session
from starlette.status import HTTP_400_BAD_REQUEST

from app.database.models import Event


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


class Location(NamedTuple):
# Location type hint class.
latitude: str
longitude: str
name: str


def raise_if_zoom_link_invalid(vc_link):
if ZOOM_REGEX.search(vc_link) is None:
raise HTTPException(
Expand Down Expand Up @@ -101,3 +113,27 @@ def get_messages(
f"Want to create another one {weeks_diff} after too?",
)
return messages


async def get_location_coordinates(
address: str,
) -> Union[Location, str]:
"""Return location coordinates and accurate
address of the specified location."""
try:
async with Nominatim(
user_agent="Pylendar",
adapter_factory=AioHTTPAdapter,
) as geolocator:
geolocation = await geolocator.geocode(address)
except (GeocoderTimedOut, GeocoderUnavailable) as e:
logger.exception(str(e))
else:
if geolocation is not None:
location = Location(
latitude=geolocation.latitude,
longitude=geolocation.longitude,
name=geolocation.raw["display_name"],
)
return location
return address
19 changes: 17 additions & 2 deletions app/routers/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@

from app.database.models import Comment, Event, User, UserEvent
from app.dependencies import get_db, logger, templates
from app.internal import comment as cmt
from app.internal.emotion import get_emotion
from app.internal.event import (
get_invited_emails,
get_location_coordinates,
get_messages,
get_uninvited_regular_emails,
raise_if_zoom_link_invalid,
)
from app.internal import comment as cmt
from app.internal.emotion import get_emotion
from app.internal.privacy import PrivacyKinds
from app.internal.utils import create_model, get_current_user
from app.routers.categories import get_user_categories


EVENT_DATA = Tuple[Event, List[Dict[str, str]], str]
TIME_FORMAT = "%Y-%m-%d %H:%M"
START_FORMAT = "%A, %d/%m/%Y %H:%M"
Expand Down Expand Up @@ -132,9 +134,16 @@ async def create_new_event(
title,
invited_emails,
)
latitude, longitude = None, None

if vc_link:
raise_if_zoom_link_invalid(vc_link)
else:
location_details = await get_location_coordinates(location)
if not isinstance(location_details, str):
location = location_details.name
latitude = location_details.latitude
longitude = location_details.longitude

event = create_event(
db=session,
Expand All @@ -145,6 +154,8 @@ async def create_new_event(
owner_id=owner_id,
content=content,
location=location,
latitude=latitude,
longitude=longitude,
vc_link=vc_link,
invitees=invited_emails,
category_id=category_id,
Expand Down Expand Up @@ -411,6 +422,8 @@ def create_event(
content: Optional[str] = None,
location: Optional[str] = None,
vc_link: str = None,
latitude: Optional[str] = None,
longitude: Optional[str] = None,
color: Optional[str] = None,
invitees: List[str] = None,
category_id: Optional[int] = None,
Expand All @@ -432,6 +445,8 @@ def create_event(
content=content,
owner_id=owner_id,
location=location,
latitude=latitude,
longitude=longitude,
vc_link=vc_link,
color=color,
emotion=get_emotion(title, content),
Expand Down
10 changes: 5 additions & 5 deletions app/static/event/eventview.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ div.event_info_row,
margin-block-end: 0.2em;
}

.title {
Copy link
Contributor

Choose a reason for hiding this comment

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

No one uses that?

Copy link
Author

Choose a reason for hiding this comment

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

It was used in view_event_details_tab.html and nowhere else.
The event color was set to blue by default in class .title.
I removed the class and switched it with a class for each color, according to the events color in the db.

border-bottom: 4px solid blue;
}

.title h1 {
white-space: nowrap;
margin-block-start: 0.2em;
Expand All @@ -72,4 +68,8 @@ div.event_info_row,

button {
height: 100%;
}
}

.google_maps_object {
width: 100%;
}
53 changes: 34 additions & 19 deletions app/templates/partials/calendar/event/view_event_details_tab.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div class="event_info_row title" style="border-bottom: 4px solid {{ event.color }}">
<div class="event_info_row_start">
<h1>{{ event.title }}</h1>
</div>
<div class="event_info_row_end">
<!-- <span class="icon">AVAILABILITY</span>-->
<!-- <span class="icon">PRIVACY</span>-->
</div>
<div class="event_info_row_start">
<h1>{{ event.title }}</h1>
</div>
<div class="event_info_row_end">
<!-- <span class="icon">AVAILABILITY</span>-->
<!-- <span class="icon">PRIVACY</span>-->
</div>
</div>
<div class="event_info_row">
<span class="icon">ICON</span>
Expand Down Expand Up @@ -35,24 +35,39 @@ <h1>{{ event.title }}</h1>
<address>VC link<a href="{{ event.vc_link }}">VC URL</a></address>
</div>
{% endif %}

{% if event.latitude is not none and event.longitude is not none %}
<div class="google_maps_object">
<iframe
width="600"
height="400"
frameborder="0"
scrolling="no"
marginheight="0"
marginwidth="0"
src="https://maps.google.com/maps?q={{event.latitude}},{{event.longitude}}&hl=es;z=14&amp;output=embed">
</iframe>
</div>
{% endif %}

{% if event.invitees %}
<form method="POST" action="/event/{{event.id}}/owner">
<div class="mb-3"></div>
<label for="username">{{ gettext('Choose user') }}</label>
<select id="username" name="username">
{% for username in event.invitees.split(',') %}
<option value="{{username}}">{{username}}</option>
{% endfor %}
</select>
<input type="submit" class="btn btn-primary" value="Change owner">
<div class="mb-3"></div>
<label for="username">{{ gettext('Choose user') }}</label>
<select id="username" name="username">
{% for username in event.invitees.split(',') %}
<option value="{{username}}">{{username}}</option>
{% endfor %}
</select>
<input type="submit" class="btn btn-primary" value="Change owner">
</form>
{% endif %}
<p class="event_info_row">
{{event.owner.username}}
{{event.owner.username}}
</p>

<div class="event_info_buttons_row event_info_row_end">
<!-- Buttons could and should be replaced with button-like anchors if need so -->
<button type="button">Duplicate</button>
<button type="button">Edit</button>
<!-- Buttons could and should be replaced with button-like anchors if need so -->
<button type="button">Duplicate</button>
<button type="button">Edit</button>
</div>
10 changes: 8 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
aiofiles==0.6.0
aiohttp==3.7.3
aioredis==1.3.1
aiosmtpd==1.2.2
aiosmtplib==1.1.4
Expand All @@ -24,7 +25,7 @@ cachetools==4.2.0
certifi==2020.12.5
cffi==1.14.4
cfgv==3.2.0
chardet==4.0.0
chardet==3.0.4
click==7.1.2
colorama==0.4.4
coverage==5.3.1
Expand All @@ -44,6 +45,8 @@ fastapi-mail==0.3.3.1
filelock==3.0.12
flake8==3.8.4
frozendict==1.2
geographiclib==1.50
geopy==2.1.0
google-api-core==1.25.0
google-api-python-client==1.12.8
google-auth==1.24.0
Expand Down Expand Up @@ -77,13 +80,15 @@ mocker==1.1.1
multidict==5.1.0
mypy==0.790
mypy-extensions==0.4.3
nest-asyncio==1.5.1
Copy link
Member

Choose a reason for hiding this comment

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

You sure you need this?

Copy link
Author

@Eliory09 Eliory09 Feb 20, 2021

Choose a reason for hiding this comment

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

I think so. My tests encounter event loop errors if I don't use it.

nltk==3.5
nodeenv==1.5.0
oauth2client==4.1.3
oauthlib==3.1.0
outcome==1.1.0
packaging==20.8
passlib==1.7.4
pathspec==0.8.1
Pillow==8.1.0
pluggy==0.13.1
pre-commit==2.10.0
Expand Down Expand Up @@ -148,4 +153,5 @@ win32-setctime==1.0.3
word-forms==2.1.0
wsproto==1.0.0
yapf==0.30.0
zipp==3.4.0
yarl==1.6.3
zipp==3.4.0
2 changes: 2 additions & 0 deletions tests/asyncio_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def fake_user_events(session):
create_event(
db=session,
title='Cool today event',
color='red',
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I got that, are the colors related to your feature?

Copy link
Author

Choose a reason for hiding this comment

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

No. While coding, 30 tests were failed because "color" column added to User schema and was pushed but wasn't supported by all tests written so far. Fixed it and added colors to some tests to make sure everything works.

start=today_date,
end=today_date + timedelta(days=2),
all_day=False,
Expand All @@ -44,6 +45,7 @@ def fake_user_events(session):
create_event(
db=session,
title='Cool (somewhen in two days) event',
color='blue',
start=today_date + timedelta(days=1),
end=today_date + timedelta(days=3),
all_day=False,
Expand Down
8 changes: 6 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import calendar

import nest_asyncio
import pytest
from app.config import PSQL_ENVIRONMENT
from app.database.models import Base
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from app.config import PSQL_ENVIRONMENT
from app.database.models import Base

pytest_plugins = [
'tests.user_fixture',
Expand Down Expand Up @@ -80,3 +81,6 @@ def sqlite_engine():
@pytest.fixture
def Calendar():
return calendar.Calendar(0)


nest_asyncio.apply()
5 changes: 5 additions & 0 deletions tests/event_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def today_event_2(sender: User, session: Session) -> Event:
return create_event(
db=session,
title='event 2',
color='blue',
start=today_date + timedelta(hours=3),
end=today_date + timedelta(days=2, hours=3),
all_day=False,
Expand All @@ -55,6 +56,7 @@ def yesterday_event(sender: User, session: Session) -> Event:
return create_event(
db=session,
title='event 3',
color='green',
start=today_date - timedelta(hours=8),
end=today_date,
all_day=False,
Expand All @@ -68,6 +70,7 @@ def next_week_event(sender: User, session: Session) -> Event:
return create_event(
db=session,
title='event 4',
color='blue',
start=today_date + timedelta(days=7, hours=2),
end=today_date + timedelta(days=7, hours=4),
all_day=False,
Expand All @@ -81,6 +84,7 @@ def next_month_event(sender: User, session: Session) -> Event:
return create_event(
db=session,
title='event 5',
color="green",
start=today_date + timedelta(days=20, hours=4),
end=today_date + timedelta(days=20, hours=6),
all_day=False,
Expand All @@ -94,6 +98,7 @@ def old_event(sender: User, session: Session) -> Event:
return create_event(
db=session,
title='event 6',
color="red",
start=today_date - timedelta(days=5),
end=today_date - timedelta(days=1),
all_day=False,
Expand Down
Loading