-
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
base: develop
Are you sure you want to change the base?
Changes from 17 commits
07ad396
3603fc6
4c0ef83
ab738c9
c67115b
6758cfb
d547f24
b33002f
185d37f
7a03352
9ff90a7
c4a41e3
cea872c
dde0739
d52f52f
75f5b9b
bc69873
b0c3b22
83c7755
1989a54
b29196b
a0856e2
c7478a4
3413899
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import logging | ||
import re | ||
from typing import List, Set | ||
from typing import List, Set, Tuple | ||
|
||
from email_validator import EmailSyntaxError, validate_email | ||
from fastapi import HTTPException | ||
|
@@ -73,7 +73,8 @@ def find_pattern(session, event): | |
|
||
def get_messages(session: Session, | ||
event: Event, | ||
uninvited_contacts: Set[str]) -> List[str]: | ||
uninvited_contacts: Set[str], | ||
out_of_office_users: List[Tuple[str, str]]) -> List[str]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could it be none? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what did you mean? |
||
messages = [] | ||
if uninvited_contacts: | ||
messages.append(f'Forgot to invite ' | ||
|
@@ -83,4 +84,12 @@ def get_messages(session: Session, | |
for weeks_diff in pattern: | ||
messages.append(f'Same event happened {weeks_diff} weeks before too. ' | ||
f'Want to create another one {weeks_diff} after too?') | ||
|
||
if out_of_office_users: | ||
username = 0 | ||
email = 1 | ||
YairEn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
messages.append('Out of office:') | ||
for user in out_of_office_users: | ||
messages.append(f'Username: {user[username]}, ' | ||
f'Email: {user[email]}') | ||
return messages |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from datetime import datetime | ||
from sqlalchemy.orm import Session | ||
|
||
from app.database.models import User, OutOfOffice | ||
|
||
|
||
def get_who_is_out_of_office(session: Session, | ||
event_start_date, | ||
YairEn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
invited_emails): | ||
""" | ||
This func check who is out of office | ||
:param session: db session | ||
YairEn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:param event_start_date: event start date | ||
:param invited_emails: invited users | ||
:return: all users that cant be at the meeting | ||
""" | ||
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, | ||
session): | ||
out = get_out_of_office_template(1, | ||
YairEn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
user_id=user.id, | ||
start_date=datetime. | ||
strptime( | ||
out_of_office_data['start_date'] | ||
YairEn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
+ ' ' + | ||
out_of_office_data['start_time'], | ||
'%Y-%m-%d %H:%M'), | ||
end_date=datetime.strptime( | ||
out_of_office_data['end_date'] | ||
+ ' ' + | ||
out_of_office_data['end_time'], | ||
'%Y-%m-%d %H:%M'), | ||
status='On') | ||
session.add(out) | ||
YairEn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def get_out_of_office_template(out_of_office_id, | ||
user_id, | ||
start_date=None, | ||
end_date=None, | ||
status='Off'): | ||
return OutOfOffice( | ||
id=out_of_office_id, | ||
user_id=user_id, | ||
start_date=start_date, | ||
end_date=end_date, | ||
status=status | ||
) | ||
|
||
|
||
def update_out_of_office(out_of_office_data_from_req, | ||
out_of_office_data_from_db): | ||
activate_out_of_office = '1' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add TODO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explain, please :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe could you please explain this line? why you set always '1'? |
||
if out_of_office_data_from_req['outOfOffice'] == activate_out_of_office: | ||
out_of_office_data_from_db.start_date = datetime.strptime( | ||
out_of_office_data_from_req['start_date'] | ||
+ ' ' + | ||
out_of_office_data_from_req['start_time'], | ||
'%Y-%m-%d %H:%M') | ||
out_of_office_data_from_db.end_date = datetime.strptime( | ||
out_of_office_data_from_req['end_date'] | ||
+ ' ' + | ||
out_of_office_data_from_req['end_time'], | ||
'%Y-%m-%d %H:%M') | ||
out_of_office_data_from_db.status = 'On' | ||
else: | ||
out_of_office_data_from_db.status = 'Off' | ||
YairEn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def update_out_of_office_status_to_off(out_of_office_data, session): | ||
""" | ||
This func check if out of office date passed and changed the status to off | ||
:param out_of_office_data: Out of office data from db | ||
:param session: | ||
:return: 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(): | ||
# update status to off | ||
YairEn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
out_of_office_data.status = 'Off' | ||
session.commit() | ||
return out_of_office_data | ||
YairEn marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,15 @@ | |
from sqlalchemy.exc import SQLAlchemyError | ||
|
||
from app import config | ||
from app.database.models import User | ||
from app.database.models import User, OutOfOffice | ||
|
||
from app.dependencies import get_db, MEDIA_PATH, templates, GOOGLE_ERROR | ||
from app.internal.on_this_day_events import get_on_this_day_events | ||
from app.internal.import_holidays import (get_holidays_from_file, | ||
save_holidays_to_db) | ||
from app.internal.on_this_day_events import get_on_this_day_events | ||
from app.internal.out_of_office import (insert_new_out_of_office, | ||
update_out_of_office, | ||
update_out_of_office_status_to_off) | ||
|
||
PICTURE_EXTENSION = config.PICTURE_EXTENSION | ||
PICTURE_SIZE = config.AVATAR_SIZE | ||
|
@@ -48,6 +52,11 @@ async def profile( | |
session.commit() | ||
user = session.query(User).filter_by(id=1).first() | ||
|
||
out_of_office_data = session.query(OutOfOffice).filter_by(id=1).first() | ||
YairEn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
out_of_office_updated_data = ( | ||
update_out_of_office_status_to_off | ||
(out_of_office_data, session)) | ||
|
||
signs = ['Aries', 'Taurus', 'Gemini', 'Cancer', 'Leo', | ||
'Virgo', 'Libra', 'Scorpio', 'Sagittarius', | ||
'Capricorn', 'Aquarius', 'Pisces'] | ||
|
@@ -60,6 +69,7 @@ async def profile( | |
"signs": signs, | ||
'google_error': GOOGLE_ERROR, | ||
"on_this_day_data": on_this_day_data, | ||
"out_of_office_data": out_of_office_updated_data, | ||
}) | ||
|
||
|
||
|
@@ -182,6 +192,38 @@ def get_image_crop_area(width, height): | |
return 0, delta, width, width + delta | ||
|
||
|
||
@router.post("/out_of_office") | ||
async def out_of_office( | ||
request: Request, session=Depends(get_db)): | ||
activate_out_of_office = '1' | ||
user = session.query(User).filter_by(id=1).first() | ||
YairEn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# TODO: Check if the user exist | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could check it with an existing function. |
||
|
||
out_of_office_data_from_req = await request.form() | ||
|
||
out_of_office_data_from_db = (session.query(OutOfOffice). | ||
filter_by(id=1).first()) | ||
YairEn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# insert new out of office | ||
if not out_of_office_data_from_db: | ||
if (out_of_office_data_from_req['outOfOffice'] | ||
== activate_out_of_office): | ||
insert_new_out_of_office(out_of_office_data_from_req, | ||
user, | ||
session) | ||
|
||
# update out of office | ||
else: | ||
update_out_of_office(out_of_office_data_from_req, | ||
out_of_office_data_from_db) | ||
|
||
session.commit() | ||
|
||
url = router.url_path_for("profile") | ||
return RedirectResponse(url=url, status_code=HTTP_302_FOUND) | ||
|
||
|
||
@router.post("/holidays/update") | ||
async def update( | ||
file: UploadFile = File(...), session=Depends(get_db)): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function findselected() { | ||
let deactivate = 0; | ||
let result = document.querySelector('input[name="outOfOffice"]:checked').value; | ||
if (result == deactivate) { | ||
document.getElementById("start_date").setAttribute('disabled', true); | ||
document.getElementById("end_date").setAttribute('disabled', true); | ||
document.getElementById("start_time").setAttribute('disabled', true); | ||
document.getElementById("end_time").setAttribute('disabled', true); | ||
YairEn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
else { | ||
document.getElementById("start_date").removeAttribute('disabled'); | ||
document.getElementById("end_date").removeAttribute('disabled'); | ||
document.getElementById("start_time").removeAttribute('disabled'); | ||
YairEn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
document.getElementById("end_time").removeAttribute('disabled'); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.