-
Notifications
You must be signed in to change notification settings - Fork 52
Feature/out of office #311
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
Open
YairEn
wants to merge
24
commits into
PythonFreeCourse:develop
Choose a base branch
from
YairEn:feature/out-of-office
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
07ad396
Add new table out of office
YairEn 3603fc6
Change requirements
YairEn 4c0ef83
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
YairEn ab738c9
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
YairEn c67115b
Merge branch 'develop' into feature/out-of-office
YairEn 6758cfb
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
YairEn d547f24
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
YairEn b33002f
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
YairEn 185d37f
Merge branch 'develop' into feature/out-of-office
YairEn 7a03352
Add out of office file
YairEn 9ff90a7
Add out of office.py file
YairEn c4a41e3
Check Profile.html
YairEn cea872c
Fix Pylint
YairEn dde0739
Fix Pylint
YairEn d52f52f
Fix Js Out of office
YairEn 75f5b9b
Add js script to html
YairEn bc69873
Merge branch 'develop' into feature/out-of-office
YairEn b0c3b22
Fix profile.html
YairEn 83c7755
Change comments and typing , add date format function
YairEn 1989a54
Merge branch 'develop' into feature/out-of-office
YairEn b29196b
Change user to user_db and user.id
YairEn a0856e2
Change indent to 2 spaces
YairEn c7478a4
Remove if main
YairEn 3413899
Merge branch 'feature/out-of-office' of https://github.com/YairEn/cal…
YairEn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
from datetime import datetime | ||
from sqlalchemy.orm import Session | ||
from typing import List | ||
|
||
from app.database.models import User, OutOfOffice | ||
|
||
DATETIME_FORMAT = "%Y-%m-%d %H:%M" | ||
START_DATE = "start_date" | ||
END_DATE = "end_date" | ||
START_TIME = "start_time" | ||
END_TIME = "end_time" | ||
|
||
|
||
def get_who_is_out_of_office( | ||
session: Session, | ||
event_start_date: datetime, | ||
invited_emails: List[str], | ||
): | ||
""" | ||
Get who is out of office | ||
|
||
Args: | ||
session: db session | ||
event_start_date: event start date | ||
invited_emails: invited emails | ||
|
||
Returns: | ||
Users who are out of office at the event date | ||
""" | ||
out_of_office_users = ( | ||
session.query(User.username, User.email) | ||
.join(OutOfOffice) | ||
.filter(User.email.in_(invited_emails)) | ||
.filter( | ||
OutOfOffice.start_date <= event_start_date, | ||
OutOfOffice.end_date >= event_start_date, | ||
) | ||
.filter(OutOfOffice.status == "On") | ||
.all() | ||
) | ||
return out_of_office_users | ||
|
||
|
||
def insert_new_out_of_office(out_of_office_data, user: User, session: Session): | ||
out = get_out_of_office_template( | ||
user_id=user.id, | ||
start_date=get_date_formatted( | ||
out_of_office_data, | ||
START_DATE, | ||
START_TIME, | ||
DATETIME_FORMAT, | ||
), | ||
end_date=get_date_formatted( | ||
out_of_office_data, | ||
END_DATE, | ||
END_TIME, | ||
DATETIME_FORMAT, | ||
), | ||
status="On", | ||
) | ||
session.add(out) | ||
YairEn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def get_out_of_office_template( | ||
user_id, | ||
start_date=None, | ||
end_date=None, | ||
status="Off", | ||
): | ||
return OutOfOffice( | ||
user_id=user_id, | ||
start_date=start_date, | ||
end_date=end_date, | ||
status=status, | ||
) | ||
|
||
|
||
def get_date_formatted(out_of_office_data, date, time, date_format): | ||
return datetime.strptime( | ||
out_of_office_data[date] + " " + out_of_office_data[time], | ||
date_format, | ||
) | ||
|
||
|
||
def update_out_of_office( | ||
out_of_office_data_from_req, | ||
out_of_office_data_from_db, | ||
): | ||
activate_out_of_office = "1" | ||
|
||
if out_of_office_data_from_req["outOfOffice"] == activate_out_of_office: | ||
out_of_office_data_from_db.start_date = get_date_formatted( | ||
out_of_office_data_from_req, | ||
START_DATE, | ||
START_TIME, | ||
DATETIME_FORMAT, | ||
) | ||
out_of_office_data_from_db.end_date = get_date_formatted( | ||
out_of_office_data_from_req, | ||
END_DATE, | ||
END_TIME, | ||
DATETIME_FORMAT, | ||
) | ||
out_of_office_data_from_db.status = "On" | ||
else: | ||
out_of_office_data_from_db.status = "Off" | ||
|
||
|
||
def update_out_of_office_status_to_off(out_of_office_data, session: Session): | ||
""" | ||
Update out of office status to off if out of office date passed | ||
|
||
Args: | ||
out_of_office_data: Out of office data from db | ||
session: db session | ||
|
||
Returns: | ||
out_of_office_data object | ||
""" | ||
if out_of_office_data: | ||
if out_of_office_data.status == "On": | ||
if out_of_office_data.end_date < datetime.now(): | ||
out_of_office_data.status = "Off" | ||
session.commit() | ||
return out_of_office_data | ||
YairEn marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.