-
Notifications
You must be signed in to change notification settings - Fork 52
Feature/weekly tasks #146
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
issac211
wants to merge
43
commits into
PythonFreeCourse:develop
Choose a base branch
from
issac211:feature/weekly-tasks
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
Feature/weekly tasks #146
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
a459763
feat: added models Task and WeeklyTasks. added the weekly_tasks route…
issac211 75015bb
fix: made a connection between the HTML pages and the functions. dele…
issac211 cad6d10
fix: Arrange the code in all the files and add a description to the c…
issac211 a27bb08
feat: merging to local develop branch
issac211 30fd9a3
fix: Position the generate_tasks function on the weekly_tasks_manager…
issac211 f65155c
fix: Added a note in routers/weekly_tasks.py on the generate_tasks fu…
issac211 c4e1a1d
closed the session on the relevant functions
issac211 2e441a1
feat: added tests for all the functions and fixed a small thing
issac211 276943e
Merge branch 'develop' into feature/weekly-tasks
issac211 ecdd5fa
fix: Improved code visibility for flake8
issac211 f7bd688
fix: improved testing for max coverage
issac211 0c4fcaf
fix: improved code visibility
issac211 54e68b1
fix: improved testing code visibility
issac211 2b4ae86
fix: improved code for requested changes
issac211 f42fb9c
fix: improved code for requested changes
issac211 1c4c61c
Merge branch 'develop' into feature/weekly-tasks
issac211 52d6197
fix: improved code for requested changes
issac211 3eede59
fix: improved code for requested changes
issac211 8f54b10
Merge branch 'develop' into feature/weekly-tasks
issac211 2554f98
Merge branch 'develop' into feature/weekly-tasks
issac211 cb6836f
fix: improved code for requested changes
issac211 1855ce7
fix: minor change
issac211 564da0e
Merge branch 'develop' into feature/weekly-tasks
issac211 2485084
fix: fixed for flake8
issac211 4b3e3ee
fix: fixed imports
issac211 62f2023
fix: fixed a mistake
issac211 6a5151e
Merge branch 'develop' into feature/weekly-tasks
issac211 ce4bc71
fix: for flake8
issac211 bd8147c
fix: improved code for requested changes
issac211 f7cbce6
Merge branch 'develop' into feature/weekly-tasks
issac211 925e449
Merge branch 'develop' into feature/weekly-tasks
issac211 a6efda9
fix: pre-commit hooks
issac211 07502c0
fix: for change request
issac211 4cf90a2
fix: import name fix
issac211 9244bbb
Merge branch 'develop' into feature/weekly-tasks
issac211 af87259
fix: weekview, Not my model, but it failed and needed a little fix
issac211 b947751
Feature/geolocation (#193)
Eliory09 b4b0ede
Feature/notifications (#331)
IdanPelled a30cbd8
fix: for Changes requeste
issac211 3e2b357
local merge
issac211 d210459
Revert "local merge"
issac211 dab05ee
Arranging files
issac211 487fd66
Revert "Arranging files"
issac211 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
from datetime import date, datetime, time | ||
from typing import Iterator, Optional | ||
|
||
from app.internal.security.schema import CurrentUser | ||
from app.database.models import User, Task, WeeklyTask | ||
from sqlalchemy.orm.session import Session | ||
|
||
|
||
def check_inputs(days: str, task_time: time, title: str) -> bool: | ||
"""Checks inputs, used by the weekly_task_from_input function""" | ||
return days and task_time and title | ||
|
||
|
||
def weekly_task_from_input( | ||
user: User, | ||
title: Optional[str], | ||
days: str, | ||
content: Optional[str], | ||
task_time: Optional[time], | ||
is_important: bool, | ||
weekly_task_id: int = 0, | ||
) -> WeeklyTask: | ||
"""This function is being used to make a Weekly Task model | ||
from the inputs. | ||
|
||
Args: | ||
user (User): The user who wants to make or edit a Weekly Task. | ||
title (str): Title of the Weekly Task. | ||
days (str): Return days of the Weekly Task. | ||
content (str): Content of the Weekly Task. | ||
task_time (time): Return time of the Weekly Task. | ||
is_important (bool): If the task is important. | ||
weekly_task_id (int): The id of the weekly task, zero if not mentioned. | ||
|
||
Returns: | ||
WeeklyTask: the model WeeklyTask which the function managed to make. | ||
""" | ||
if isinstance(user, CurrentUser): | ||
user_id = user.user_id | ||
else: | ||
user_id = user.id | ||
weekly_task = WeeklyTask( | ||
title=title, | ||
content=content, | ||
is_important=is_important, | ||
user_id=user_id, | ||
) | ||
|
||
if weekly_task_id != 0: | ||
weekly_task.id = weekly_task_id | ||
|
||
inputs_ok = check_inputs(days, task_time, title) | ||
if not inputs_ok: | ||
return weekly_task | ||
weekly_task.set_days(days) | ||
weekly_task.task_time = task_time.strftime("%H:%M") | ||
return weekly_task | ||
|
||
|
||
def create_weekly_task( | ||
weekly_task: WeeklyTask, | ||
session: Session, | ||
) -> bool: | ||
"""This function is being used to add a Weekly Task to the user. | ||
|
||
Args: | ||
user (User): The user who wants to add the Weekly Task. | ||
session (Session): The session to redirect to the database. | ||
weekly_task (WeeklyTask): The Weekly Task that the user will add. | ||
|
||
Returns: | ||
bool: Shows if the weekly_task has been added to the db. | ||
""" | ||
inputs_ok = check_inputs( | ||
weekly_task.days, | ||
weekly_task.task_time, | ||
weekly_task.title, | ||
) | ||
if not inputs_ok: | ||
return False | ||
session.add(weekly_task) | ||
session.commit() | ||
return True | ||
|
||
|
||
def change_weekly_task( | ||
user: User, | ||
weekly_task: WeeklyTask, | ||
session: Session, | ||
) -> bool: | ||
"""This function is being used to edit a Weekly Task the user have. | ||
|
||
Args: | ||
user (User): The user who wants to edit the Weekly Task. | ||
session (Session): The session to redirect to the database. | ||
weekly_task (WeeklyTask): The Weekly Task that the of the user, | ||
with the edited values. | ||
|
||
Returns: | ||
bool: Shows if the weekly_task has been edited in the db. | ||
""" | ||
inputs_ok = check_inputs( | ||
weekly_task.days, | ||
weekly_task.task_time, | ||
weekly_task.title, | ||
) | ||
if not inputs_ok: | ||
return False | ||
w_task_query = session.query(WeeklyTask) | ||
old_weekly_task = w_task_query.filter_by(id=weekly_task.id).first() | ||
|
||
if weekly_task.user_id != user.id: | ||
return False | ||
|
||
old_weekly_task.title = weekly_task.title | ||
old_weekly_task.days = weekly_task.days | ||
old_weekly_task.content = weekly_task.content | ||
old_weekly_task.is_important = weekly_task.is_important | ||
old_weekly_task.task_time = weekly_task.task_time | ||
session.commit() | ||
return True | ||
|
||
|
||
def create_task(task: Task, user: User, session: Session) -> bool: | ||
"""Make a task, used by the generate_tasks function""" | ||
user_tasks_query = session.query(Task).filter_by(owner_id=user.id) | ||
task_by_time = user_tasks_query.filter_by(time=task.time) | ||
task_by_date_time = task_by_time.filter_by(date=task.date) | ||
task_by_title_and_time = task_by_date_time.filter_by(title=task.title) | ||
task_exist = task_by_title_and_time.first() | ||
if task_exist: | ||
return False | ||
session.add(task) | ||
session.commit() | ||
return True | ||
|
||
|
||
def get_datetime(day: str, task_time: str) -> datetime: | ||
"""Getting the datetime of days in the current week, | ||
used by the generate_tasks function""" | ||
current_date = date.today() | ||
current_week_num = current_date.strftime("%W") | ||
current_year = current_date.strftime("%Y") | ||
date_string = f"{day} {task_time} {current_week_num} {current_year}" | ||
return datetime.strptime(date_string, "%a %H:%M %W %Y") | ||
|
||
|
||
def generate_tasks(user: User, session: Session) -> Iterator[bool]: | ||
"""Generates tasks for the week | ||
based on all the weekly tasks the user have""" | ||
for weekly_task in user.weekly_tasks: | ||
task_time = weekly_task.task_time | ||
days = weekly_task.get_days() | ||
days_list = days.split(", ") | ||
for day in days_list: | ||
date_time = get_datetime(day, task_time) | ||
task = Task( | ||
title=weekly_task.title, | ||
description=weekly_task.content, | ||
is_done=False, | ||
is_important=weekly_task.is_important, | ||
date=date_time.date(), | ||
time=date_time.time(), | ||
owner_id=user.id, | ||
) | ||
yield create_task(task, user, session) | ||
|
||
|
||
def remove_weekly_task(weekly_task_id: int, session: Session) -> bool: | ||
issac211 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Removes a weekly task from the db based on the weekly task id""" | ||
weekly_task_query = session.query(WeeklyTask) | ||
weekly_task = weekly_task_query.filter_by(id=weekly_task_id).first() | ||
if not weekly_task: | ||
return False | ||
session.query(WeeklyTask).filter_by(id=weekly_task_id).delete() | ||
session.commit() | ||
return True |
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.