Skip to content

Feature/all day events #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4666a8c
An initial version of the "All Day Event feature".
Feb 11, 2021
ada6d2a
Additional testing adjustments
Feb 11, 2021
981781d
All-day event feature : First push
Feb 12, 2021
2bd32d2
Apply automatic translateable string changes
TamarBerger Feb 12, 2021
8218807
without the unintentional changes in the "test_a_telegram_asyncio.py"…
Feb 12, 2021
2da589e
Merge branch 'feature/all-day-events' of https://github.com/TamarBerg…
Feb 12, 2021
f2b0478
Merge branch 'develop' into feature/all-day-events
Feb 13, 2021
b229c5c
flake8 fixes : number 1
Feb 13, 2021
aff1ec2
flake8 fixes: number 2
Feb 13, 2021
f70eea0
flake8 fixes: number 3
Feb 13, 2021
6817e24
trailing whitespace
Feb 13, 2021
f983904
trial to fix the tests1
Feb 13, 2021
9ae4937
trial to fix the tests2
Feb 13, 2021
581b8a3
with tests fixes
Feb 13, 2021
7e0c874
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
Feb 14, 2021
ac15058
trial to fix the tests3
Feb 14, 2021
4a095c1
With changes according to Yam's review
Feb 14, 2021
5d998f5
flake8 fixes: number 4
Feb 14, 2021
7349322
With changes according to Yam's review: round 2
Feb 15, 2021
d01f775
Merge branch 'develop' into feature/all-day-events
TamarBerger Feb 15, 2021
207c809
Merge branch 'develop' into feature/all-day-events
TamarBerger Feb 16, 2021
8a4c2a0
With changes according to Yam's and Gonzom's reviews: round 3
Feb 17, 2021
ef25155
Merge branch 'feature/all-day-events' of https://github.com/TamarBerg…
Feb 17, 2021
a3ec088
with flake8 fixes: number 5
Feb 17, 2021
cac8b8c
with flake8 fixes: number 6
Feb 17, 2021
c98007b
with flake8 fixes: number 7
Feb 17, 2021
703a8c0
Merge branch 'develop' into feature/all-day-events
TamarBerger Feb 18, 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
1 change: 1 addition & 0 deletions app/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Event(Base):
is_google_event = Column(Boolean, default=False)
vc_link = Column(String)
color = Column(String, nullable=True)
all_day = Column(Boolean, default=False)
invitees = Column(String)
emotion = Column(String, nullable=True)
availability = Column(Boolean, default=True, nullable=False)
Expand Down
Binary file modified app/locales/en/LC_MESSAGES/base.mo
Binary file not shown.
Binary file modified app/locales/he/LC_MESSAGES/base.mo
Binary file not shown.
44 changes: 38 additions & 6 deletions app/routers/dayview.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,27 @@ def _check_multiday_event(self) -> Tuple[bool]:
return (start_multiday, end_multiday)


def event_in_day(event: Event, day: datetime, day_end: datetime) -> bool:
def is_specific_time_event_in_day(
event: Event, day: datetime, day_end: datetime
) -> bool:
if event.all_day:
return False
return (
(event.start >= day and event.start < day_end) or
(event.end >= day and event.end < day_end) or
(event.start < day_end < event.end)
(event.start >= day and event.start < day_end)
or (event.end >= day and event.end < day_end)
or (event.start < day_end < event.end)
)


def is_all_day_event_in_day(
event: Event, day: datetime, day_end: datetime
) -> bool:
if not event.all_day:
return False
return (
(event.start >= day and event.start < day_end)
or (event.end >= day and event.end < day_end)
or (event.start < day_end < event.end)
)


Expand All @@ -118,16 +134,28 @@ def get_events_and_attributes(
events = get_all_user_events(session, user_id)
day_end = day + timedelta(hours=24)
for event in events:
if event_in_day(event=event, day=day, day_end=day_end):
if is_specific_time_event_in_day(
event=event, day=day, day_end=day_end
):
yield (event, DivAttributes(event, day))


def get_all_day_events(
day: datetime, session, user_id: int,
) -> Event:
events = get_all_user_events(session, user_id)
day_end = day + timedelta(hours=24)
for event in events:
if is_all_day_event_in_day(event=event, day=day, day_end=day_end):
yield (event)


@router.get('/day/{date}', include_in_schema=False)
async def dayview(
request: Request, date: str, session=Depends(get_db), view='day',
):
# TODO: add a login session
user = session.query(User).filter_by(username='test_username').first()
user = session.query(User).first()
try:
day = datetime.strptime(date, '%Y-%m-%d')
except ValueError as err:
Expand All @@ -136,10 +164,14 @@ async def dayview(
events_n_attrs = get_events_and_attributes(
day=day, session=session, user_id=user.id,
)
all_day_events = get_all_day_events(
day=day, session=session, user_id=user.id,
)
month = day.strftime("%B").upper()
return templates.TemplateResponse("dayview.html", {
"request": request,
"events": events_n_attrs,
"all_day_events": all_day_events,
"month": month,
"day": day.day,
"zodiac": zodiac_obj,
Expand Down
13 changes: 11 additions & 2 deletions app/routers/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'start': dt,
'end': dt,
'availability': bool,
'all_day': bool,
'is_google_event': bool,
'content': (str, type(None)),
'location': (str, type(None)),
Expand Down Expand Up @@ -94,6 +95,8 @@ async def create_new_event(request: Request,
owner_id = get_current_user(session).id
availability = data.get('availability', 'True') == 'True'
location = data['location']
all_day = data['event_type'] and data['event_type'] == 'on'

vc_link = data['vc_link']
category_id = data.get('category_id')
is_google_event = data.get('is_google_event', 'True') == 'True'
Expand All @@ -106,7 +109,7 @@ async def create_new_event(request: Request,
raise_if_zoom_link_invalid(vc_link)

event = create_event(db=session, title=title, start=start, end=end,
owner_id=owner_id, content=content,
owner_id=owner_id, all_day=all_day, content=content,
location=location, vc_link=vc_link,
invitees=invited_emails,
category_id=category_id,
Expand All @@ -123,12 +126,16 @@ async def create_new_event(request: Request,
async def eventview(request: Request, event_id: int,
db: Session = Depends(get_db)) -> Response:
event, comments, end_format = get_event_data(db, event_id)
start_format = START_FORMAT
if event.all_day:
start_format = '%A, %d/%m/%Y'
end_format = ""
messages = request.query_params.get('messages', '').split("---")
return templates.TemplateResponse("event/eventview.html",
{"request": request,
"event": event,
"comments": comments,
"start_format": START_FORMAT,
"start_format": start_format,
"end_format": end_format,
"messages": messages})

Expand Down Expand Up @@ -267,6 +274,7 @@ def update_event(event_id: int, event: Dict, db: Session


def create_event(db: Session, title: str, start, end, owner_id: int,
all_day: bool = False,
content: Optional[str] = None,
location: Optional[str] = None,
vc_link: str = None,
Expand All @@ -292,6 +300,7 @@ def create_event(db: Session, title: str, start, end, owner_id: int,
color=color,
emotion=get_emotion(title, content),
invitees=invitees_concatenated,
all_day=all_day,
category_id=category_id,
availability=availability,
is_google_event=is_google_event
Expand Down
5 changes: 5 additions & 0 deletions app/templates/dayview.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<span class="fw-bold text-white date-nums">{{day}} / {{month}}</span>
{% endif %}
</div>
<div class="all_day_events">
{% for event in all_day_events %}
<p class="text-truncate my-0 {{size}}">{{ event.title }}</p>
{% endfor %}
</div>
<div class="schedule">
<div class="container times bg-primeary position">
{% if view == 'day'%}
Expand Down
7 changes: 7 additions & 0 deletions app/templates/event/partials/edit_event_details_tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
<div class="form_row textarea">
<textarea id="say" name="description" placeholder="Description"></textarea>
</div>
<div class="form_row">
<label for="event_type">All-day:</label>
<select name="event_type" required>
<option value="on">Yes</option>
<option value="off" selected>No</option>
</select>
</div>
<div class="form_row">
<div class="form_row_start">
<label for="color">Color:</label>
Expand Down
4 changes: 3 additions & 1 deletion app/templates/event/partials/view_event_details_tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ <h1>{{ event.title }}</h1>
<div class="event_info_row">
<span class="icon">ICON</span>
<time datetime="{{ event.start }}">{{ event.start.strftime(start_format )}}</time>
{% if end_format != "" %}
-
<time datetime="{{ event.end }}">{{ event.end.strftime(end_format) }}</time>
<time datetime="{{event.end}}">{{event.end.strftime(end_format)}}</time>
{% endif %}
<div>{{ 'Busy' if event.availability == True else 'Free' }}</div>
</div>

Expand Down
2 changes: 2 additions & 0 deletions tests/asyncio_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def fake_user_events(session):
title='Cool today event',
start=today_date,
end=today_date + timedelta(days=2),
all_day=False,
content='test event',
owner_id=user.id,
location="Here",
Expand All @@ -45,6 +46,7 @@ def fake_user_events(session):
title='Cool (somewhen in two days) event',
start=today_date + timedelta(days=1),
end=today_date + timedelta(days=3),
all_day=False,
content='this week test event',
owner_id=user.id,
location="Here",
Expand Down
8 changes: 8 additions & 0 deletions tests/dayview_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ def event3():
start=start, end=end, owner_id=1)


@pytest.fixture
def all_day_event1():
start = datetime(year=2021, month=2, day=3, hour=7, minute=5)
end = datetime(year=2021, month=2, day=3, hour=9, minute=15)
return Event(title='test3', content='test', all_day=True,
start=start, end=end, owner_id=1)


@pytest.fixture
def small_event():
start = datetime(year=2021, month=2, day=3, hour=7)
Expand Down
21 changes: 21 additions & 0 deletions tests/event_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def today_event(sender: User, session: Session) -> Event:
title='event 1',
start=today_date + timedelta(hours=7),
end=today_date + timedelta(hours=9),
all_day=False,
content='test event',
owner_id=sender.id,
)
Expand All @@ -43,6 +44,7 @@ def today_event_2(sender: User, session: Session) -> Event:
title='event 2',
start=today_date + timedelta(hours=3),
end=today_date + timedelta(days=2, hours=3),
all_day=False,
content='test event',
owner_id=sender.id,
)
Expand All @@ -55,6 +57,7 @@ def yesterday_event(sender: User, session: Session) -> Event:
title='event 3',
start=today_date - timedelta(hours=8),
end=today_date,
all_day=False,
content='test event',
owner_id=sender.id,
)
Expand All @@ -67,6 +70,7 @@ def next_week_event(sender: User, session: Session) -> Event:
title='event 4',
start=today_date + timedelta(days=7, hours=2),
end=today_date + timedelta(days=7, hours=4),
all_day=False,
content='test event',
owner_id=sender.id,
)
Expand All @@ -79,6 +83,7 @@ def next_month_event(sender: User, session: Session) -> Event:
title='event 5',
start=today_date + timedelta(days=20, hours=4),
end=today_date + timedelta(days=20, hours=6),
all_day=False,
content='test event',
owner_id=sender.id,
)
Expand All @@ -91,6 +96,22 @@ def old_event(sender: User, session: Session) -> Event:
title='event 6',
start=today_date - timedelta(days=5),
end=today_date - timedelta(days=1),
all_day=False,
content='test event',
owner_id=sender.id,
)


@pytest.fixture
def all_day_event(sender: User, category: Category, session: Session) -> Event:
return create_event(
db=session,
title='event',
start=today_date,
end=today_date,
all_day=True,
content='test event',
owner_id=sender.id,
location="Some random location",
category_id=category.id,
)
32 changes: 31 additions & 1 deletion tests/test_dayview.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import pytest

from app.database.models import Event
from app.routers.dayview import DivAttributes
from app.routers.dayview import (
DivAttributes, is_all_day_event_in_day,
is_specific_time_event_in_day
)

from app.routers.event import create_event


Expand Down Expand Up @@ -64,6 +68,32 @@ def test_div_attr_multiday(multiday_event):
assert DivAttributes(multiday_event, day).grid_position == '1 / 57'


def test_is_specific_time_event_in_day(all_day_event1, event3):
day = datetime(year=2021, month=2, day=3, hour=0, minute=0)
day_end = day + timedelta(hours=24)
function_returns_true = is_specific_time_event_in_day(
event=event3, day=day, day_end=day_end
)
function_returns_false = is_specific_time_event_in_day(
event=all_day_event1, day=day, day_end=day_end
)
assert function_returns_true
assert not function_returns_false


def test_is_all_day_event_in_day(all_day_event1, event3):
day = datetime(year=2021, month=2, day=3, hour=0, minute=0)
day_end = day + timedelta(hours=24)
function_returns_true = is_all_day_event_in_day(
event=all_day_event1, day=day, day_end=day_end
)
function_returns_false = is_all_day_event_in_day(
event=event3, day=day, day_end=day_end
)
assert function_returns_true
assert not function_returns_false


def test_div_attributes_with_costume_color(event2):
div_attr = DivAttributes(event2)
assert div_attr.color == 'blue'
Expand Down
12 changes: 6 additions & 6 deletions tests/test_emotion.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@

create_event_tests = [
(HAPPY_MESSAGE, datetime.datetime(2019, 5, 21, 0, 0),
datetime.datetime(2019, 5, 22, 0, 0), 1, HAPPY_MESSAGE, "location",
datetime.datetime(2019, 5, 22, 0, 0), False, 1, HAPPY_MESSAGE, "location",
"&#128515"),
(SAD_MESSAGE, datetime.datetime(2019, 5, 21, 0, 0),
datetime.datetime(2019, 5, 22, 0, 0), 1, HAPPY_MESSAGE, "location",
datetime.datetime(2019, 5, 22, 0, 0), False, 1, HAPPY_MESSAGE, "location",
"&#128577"),
(" ", datetime.datetime(2019, 5, 21, 0, 0),
datetime.datetime(2019, 5, 22, 0, 0), 1, " ", "location",
datetime.datetime(2019, 5, 22, 0, 0), False, 1, " ", "location",
None)
]

Expand Down Expand Up @@ -89,10 +89,10 @@ def test_get_emotion(title, content, result):
assert get_emotion(title, content) == result


@pytest.mark.parametrize("title, start, end, owner_id, content, " +
@pytest.mark.parametrize("title, start, end, all_day, owner_id, content, " +
"location, result", create_event_tests)
def test_create_event(title, start, end,
def test_create_event(title, start, end, all_day,
owner_id, content, location, result, session):
event = create_event(session, title, start,
end, owner_id, content, location)
end, all_day, owner_id, content, location)
assert event.emotion == result
Loading