Feature/geolocation#193
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #193 +/- ##
========================================
Coverage 95.40% 95.41%
========================================
Files 79 79
Lines 3549 3575 +26
========================================
+ Hits 3386 3411 +25
- Misses 163 164 +1
Continue to review full report at Codecov.
|
app/routers/event.py
Outdated
| def get_location_coordinates( | ||
| address: str, | ||
| timeout: float = LOCATION_TIMEOUT | ||
| ) -> Tuple[float, float, str]: |
There was a problem hiding this comment.
The type hinting is incorrect
| </div> | ||
|
|
||
| {% if event.latitude is not none and event.longitude is not none %} | ||
| <div style="width: 100%"> |
| @@ -1,4 +1,4 @@ | |||
| <div class="event_info_row title" style="border-bottom: 4px solid {{event.color}}"> | |||
| <div class="event_info_row title" style="border-bottom: 4px solid '{{event.color}}'"> | |||
|
Typo issues resolved. |
app/database/models.py
Outdated
| end = Column(DateTime, nullable=False) | ||
| content = Column(String) | ||
| location = Column(String) | ||
| latitude = Column(String) |
app/routers/event.py
Outdated
| '%Y-%m-%d %H:%M') | ||
| user = session.query(User).filter_by(id=1).first() | ||
| user = user if user else create_user("u", "p", "e@mail.com", session) | ||
| user = user if user else create_user( |
There was a problem hiding this comment.
Maybe add a function get_user_or_create_default?
app/routers/event.py
Outdated
| return location.latitude, location.longitude, acc_address | ||
| except (GeocoderTimedOut, GeocoderUnavailable) as e: | ||
| logger.exception(str(e)) | ||
| return None |
There was a problem hiding this comment.
You can return (None, None, location), and then you could remove if location_details is not None: in line 64
| margin-block-end: 0.2em; | ||
| } | ||
|
|
||
| .title { |
There was a problem hiding this comment.
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.
| create_event( | ||
| db=session, | ||
| title='Cool today event', | ||
| color='red', |
There was a problem hiding this comment.
Not sure I got that, are the colors related to your feature?
There was a problem hiding this comment.
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.
tests/test_geolocation.py
Outdated
|
|
||
|
|
||
| class TestGeolocation: | ||
|
|
There was a problem hiding this comment.
please remove blank line in line 7
tests/test_geolocation.py
Outdated
| assert response.ok | ||
| url = event_test_client.app.url_path_for('eventview', event_id=1) | ||
| response = event_test_client.get(url) | ||
| location = get_location_coordinates( |
There was a problem hiding this comment.
maybe _, loaction_name, _ = ..
tests/test_geolocation.py
Outdated
| assert response.ok | ||
| url = event_test_client.app.url_path_for('eventview', event_id=1) | ||
| response = event_test_client.get(url) | ||
| location = get_location_coordinates( |
app/routers/event.py
Outdated
|
|
||
|
|
||
| def get_user_or_create_default(user: User, session: Session) -> User: | ||
| """Check if the user is logged in, else create a fictive user |
There was a problem hiding this comment.
Add a blank line after the docstring's summary line :)
There was a problem hiding this comment.
I decided to remove the method, after it was edited by someone else.
app/static/event/eventview.css
Outdated
| } | ||
|
|
||
| .google_maps_object { | ||
| width: 100% |
There was a problem hiding this comment.
; (You missed it in 4 places :))
…into feature/geolocation
…into feature/geolocation
…into feature/geolocation
…endar into feature/geolocation
app/internal/event.py
Outdated
| """Return location coordinates and accurate | ||
| address of the specified location.""" | ||
| Location = namedtuple('Location', 'latitude, longitude, location') | ||
| geolocator = Nominatim(user_agent="calendar", timeout=timeout) |
There was a problem hiding this comment.
Fortunately, this module does support work with async.
Use async with
app/internal/event.py
Outdated
| if geolocation is not None: | ||
| location = Location(geolocation.latitude, | ||
| geolocation.longitude, | ||
| geolocation.raw["display_name"]) | ||
| return location |
There was a problem hiding this comment.
Are these lines can raise an exception? If not, put them outside the try/except
app/internal/event.py
Outdated
| @@ -1,15 +1,28 @@ | |||
| from collections import namedtuple | |||
There was a problem hiding this comment.
You're not using this anymore, please remove.
app/static/event/eventview.css
Outdated
| } | ||
|
|
||
| .google_maps_object { | ||
| width: 100%; |
There was a problem hiding this comment.
Please set the indentation in the CSS to 2 spaces
| mccabe==0.6.1 | ||
| mypy==0.790 | ||
| mypy-extensions==0.4.3 | ||
| nest-asyncio==1.5.1 |
There was a problem hiding this comment.
I think so. My tests encounter event loop errors if I don't use it.
tests/__init__.py
Outdated
| @@ -0,0 +1,2 @@ | |||
| import nest_asyncio | |||
tests/test_geolocation.py
Outdated
| async def test_get_location_coordinates_correct(location): | ||
| # Test geolocation search using valid locations. | ||
| location = await get_location_coordinates(location) | ||
| assert all(list(location)) |
| <!-- <span class="icon">PRIVACY</span>--> | ||
| </div> | ||
| <div class="event_info_row title_color_{{event.color}}" > | ||
| <div class="event_info_row_start"> |
…into feature/geolocation
…into feature/geolocation
…into feature/geolocation
…into feature/geolocation
yammesicka
left a comment
There was a problem hiding this comment.
Great progress! I've added few further insights
app/internal/event.py
Outdated
| ) -> Union[Location, str]: | ||
| """Return location coordinates and accurate | ||
| address of the specified location.""" | ||
| Location = namedtuple("Location", "latitude, longitude, location") |
There was a problem hiding this comment.
Define outside, use typing.NamedTuple
app/routers/event.py
Outdated
| from fastapi import APIRouter, Depends, HTTPException, Request | ||
| from pydantic import BaseModel | ||
| from sqlalchemy.exc import SQLAlchemyError | ||
| from sqlalchemy.orm import Session | ||
| from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound | ||
| from sqlalchemy.sql.elements import Null | ||
| from starlette import status | ||
| from starlette.responses import RedirectResponse, Response | ||
| from starlette.templating import _TemplateResponse |
There was a problem hiding this comment.
These lines should appear on the 2nd paragraph. Please use git precommit hooks to order it.
There was a problem hiding this comment.
Actually, precommit hooks didn't fix it automatically. I separated the paragraphs.
app/routers/event.py
Outdated
| raise_if_zoom_link_invalid(vc_link) | ||
| else: | ||
| location_details = await get_location_coordinates(location) | ||
| if type(location_details) is not str: |
There was a problem hiding this comment.
not isinstance(location_details, str)
app/static/event/eventview.css
Outdated
| } | ||
|
|
||
| .google_maps_object { | ||
| width: 100%; |
…into feature/geolocation
| @@ -1,5 +1,5 @@ | |||
| from datetime import datetime as dt | |||
| import json | |||
| from datetime import datetime as dt | |||
Issue #185 : Events geolocation support: