Skip to content

Commit a30cbd8

Browse files
committed
fix: for Changes requeste
1 parent af87259 commit a30cbd8

File tree

8 files changed

+85
-84
lines changed

8 files changed

+85
-84
lines changed

app/database/models.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from sqlalchemy import (
99
Boolean,
1010
Column,
11+
Date,
1112
DateTime,
1213
DDL,
1314
event,
@@ -277,13 +278,14 @@ class Task(Base):
277278

278279
id = Column(Integer, primary_key=True, index=True)
279280
title = Column(String)
280-
content = Column(String)
281-
is_done = Column(Boolean, nullable=False)
281+
description = Column(String)
282+
is_done = Column(Boolean, default=False)
282283
is_important = Column(Boolean, nullable=False)
283-
date_time = Column(DateTime, nullable=False)
284+
date = Column(Date, nullable=False)
285+
time = Column(Time, nullable=False)
286+
owner_id = Column(Integer, ForeignKey("users.id"))
284287

285-
user_id = Column(Integer, ForeignKey("users.id"))
286-
owner = relationship("User", back_populates=__tablename__)
288+
owner = relationship("User", back_populates="tasks")
287289

288290

289291
class WeeklyTask(Base):
@@ -294,7 +296,7 @@ class WeeklyTask(Base):
294296
days = Column(String, nullable=False)
295297
content = Column(String)
296298
is_important = Column(Boolean, nullable=False)
297-
the_time = Column(String, nullable=False)
299+
task_time = Column(String, nullable=False)
298300

299301
user_id = Column(Integer, ForeignKey("users.id"))
300302
owner = relationship("User", back_populates=__tablename__)

app/internal/weekly_tasks.py

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
from sqlalchemy.orm.session import Session
77

88

9-
def check_inputs(days: str, the_time: time, title: str) -> bool:
9+
def check_inputs(days: str, task_time: time, title: str) -> bool:
1010
"""Checks inputs, used by the weekly_task_from_input function"""
11-
return days and the_time and title
11+
return days and task_time and title
1212

1313

1414
def weekly_task_from_input(
1515
user: User,
1616
title: Optional[str],
1717
days: str,
1818
content: Optional[str],
19-
the_time: Optional[time],
19+
task_time: Optional[time],
2020
is_important: bool,
2121
weekly_task_id: int = 0,
2222
) -> WeeklyTask:
@@ -28,7 +28,7 @@ def weekly_task_from_input(
2828
title (str): Title of the Weekly Task.
2929
days (str): Return days of the Weekly Task.
3030
content (str): Content of the Weekly Task.
31-
the_time (time): Return time of the Weekly Task.
31+
task_time (time): Return time of the Weekly Task.
3232
is_important (bool): If the task is important.
3333
weekly_task_id (int): The id of the weekly task, zero if not mentioned.
3434
@@ -49,16 +49,15 @@ def weekly_task_from_input(
4949
if weekly_task_id != 0:
5050
weekly_task.id = weekly_task_id
5151

52-
inputs_ok = check_inputs(days, the_time, title)
52+
inputs_ok = check_inputs(days, task_time, title)
5353
if not inputs_ok:
5454
return weekly_task
5555
weekly_task.set_days(days)
56-
weekly_task.the_time = the_time.strftime("%H:%M")
56+
weekly_task.task_time = task_time.strftime("%H:%M")
5757
return weekly_task
5858

5959

6060
def create_weekly_task(
61-
user: User,
6261
weekly_task: WeeklyTask,
6362
session: Session,
6463
) -> bool:
@@ -72,12 +71,12 @@ def create_weekly_task(
7271
Returns:
7372
bool: Shows if the weekly_task has been added to the db.
7473
"""
75-
if not weekly_task.days or not weekly_task.the_time:
76-
return False
77-
task_titles = (
78-
user_weekly_task.title for user_weekly_task in user.weekly_tasks
74+
inputs_ok = check_inputs(
75+
weekly_task.days,
76+
weekly_task.task_time,
77+
weekly_task.title,
7978
)
80-
if weekly_task.title in task_titles:
79+
if not inputs_ok:
8180
return False
8281
session.add(weekly_task)
8382
session.commit()
@@ -100,37 +99,34 @@ def change_weekly_task(
10099
Returns:
101100
bool: Shows if the weekly_task has been edited in the db.
102101
"""
103-
if weekly_task.days is None or weekly_task.the_time is None:
102+
inputs_ok = check_inputs(
103+
weekly_task.days,
104+
weekly_task.task_time,
105+
weekly_task.title,
106+
)
107+
if not inputs_ok:
104108
return False
105109
w_task_query = session.query(WeeklyTask)
106110
old_weekly_task = w_task_query.filter_by(id=weekly_task.id).first()
107111

108-
user_titles = (
109-
user_weekly_task.title
110-
for user_weekly_task in user.weekly_tasks
111-
if user_weekly_task.title != old_weekly_task.title
112-
)
113-
114-
if weekly_task.title in user_titles:
115-
return False
116-
117112
if weekly_task.user_id != user.id:
118113
return False
119114

120115
old_weekly_task.title = weekly_task.title
121116
old_weekly_task.days = weekly_task.days
122117
old_weekly_task.content = weekly_task.content
123118
old_weekly_task.is_important = weekly_task.is_important
124-
old_weekly_task.the_time = weekly_task.the_time
119+
old_weekly_task.task_time = weekly_task.task_time
125120
session.commit()
126121
return True
127122

128123

129124
def create_task(task: Task, user: User, session: Session) -> bool:
130125
"""Make a task, used by the generate_tasks function"""
131-
user_tasks_query = session.query(Task).filter_by(user_id=user.id)
132-
task_by_time = user_tasks_query.filter_by(date_time=task.date_time)
133-
task_by_title_and_time = task_by_time.filter_by(title=task.title)
126+
user_tasks_query = session.query(Task).filter_by(owner_id=user.id)
127+
task_by_time = user_tasks_query.filter_by(time=task.time)
128+
task_by_date_time = task_by_time.filter_by(date=task.date)
129+
task_by_title_and_time = task_by_date_time.filter_by(title=task.title)
134130
task_exist = task_by_title_and_time.first()
135131
if task_exist:
136132
return False
@@ -139,32 +135,33 @@ def create_task(task: Task, user: User, session: Session) -> bool:
139135
return True
140136

141137

142-
def get_datetime(day: str, the_time: str) -> datetime:
138+
def get_datetime(day: str, task_time: str) -> datetime:
143139
"""Getting the datetime of days in the current week,
144140
used by the generate_tasks function"""
145141
current_date = date.today()
146142
current_week_num = current_date.strftime("%W")
147143
current_year = current_date.strftime("%Y")
148-
date_string = f"{day} {the_time} {current_week_num} {current_year}"
144+
date_string = f"{day} {task_time} {current_week_num} {current_year}"
149145
return datetime.strptime(date_string, "%a %H:%M %W %Y")
150146

151147

152148
def generate_tasks(user: User, session: Session) -> Iterator[bool]:
153149
"""Generates tasks for the week
154150
based on all the weekly tasks the user have"""
155151
for weekly_task in user.weekly_tasks:
156-
the_time = weekly_task.the_time
152+
task_time = weekly_task.task_time
157153
days = weekly_task.get_days()
158154
days_list = days.split(", ")
159155
for day in days_list:
160-
date_time = get_datetime(day, the_time)
156+
date_time = get_datetime(day, task_time)
161157
task = Task(
162158
title=weekly_task.title,
163-
content=weekly_task.content,
159+
description=weekly_task.content,
164160
is_done=False,
165161
is_important=weekly_task.is_important,
166-
date_time=date_time,
167-
user_id=user.id,
162+
date=date_time.date(),
163+
time=date_time.time(),
164+
owner_id=user.id,
168165
)
169166
yield create_task(task, user, session)
170167

app/routers/weekly_tasks.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def get_days_string(
7070
return days
7171

7272

73-
@router.get("/")
73+
@router.get("/", include_in_schema=False)
7474
async def weekly_tasks_manager(
7575
request: Request,
7676
user: schema.CurrentUser = Depends(current_user_from_db),
@@ -165,7 +165,7 @@ def weekly_task_execute(
165165
sat: bool = Form(False),
166166
content: str = Form(None),
167167
is_important: bool = Form(False),
168-
the_time: datetime.time = Form(None),
168+
task_time: datetime.time = Form(None),
169169
weekly_task_id: int = Form(...),
170170
):
171171

@@ -177,14 +177,14 @@ def weekly_task_execute(
177177
title,
178178
days,
179179
content,
180-
the_time,
180+
task_time,
181181
is_important,
182182
weekly_task_id=weekly_task_id,
183183
)
184184

185185
if mode == "add":
186186
# creating the weekly task
187-
created = create_weekly_task(user, weekly_task, session)
187+
created = create_weekly_task(weekly_task, session)
188188
executed = created
189189

190190
else: # mode == "edit":
@@ -223,7 +223,7 @@ def weekly_task_failed(
223223
days: str = Cookie(...),
224224
is_important: bool = Cookie(False),
225225
):
226-
the_time = None
226+
task_time = None
227227
if title == "None":
228228
title = None
229229
if content == "None":
@@ -233,7 +233,7 @@ def weekly_task_failed(
233233
title,
234234
days,
235235
content,
236-
the_time,
236+
task_time,
237237
is_important,
238238
id,
239239
)

app/templates/add_edit_weekly_task.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ <h1>Add Weekly Tasks</h1>
5858
</div>
5959

6060
<div class="mb-3">
61-
<label for="the_time" class="form-label">Time Of The Day:</label>
62-
<input type="time" class="form-control" value="{{ weekly_task.the_time }}" id="the_time" name="the_time">
61+
<label for="task_time" class="form-label">Time Of The Day:</label>
62+
<input type="time" class="form-control" value="{{ weekly_task.task_time }}" id="task_time" name="task_time">
6363
</div>
6464

6565
<div class="input-group">

app/templates/weekly_tasks_manager.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h1>Weekly Tasks</h1>
1616
<!-- Task repeat days and time -->
1717
<small>
1818
<i><span class="text-decoration-underline">Every:</span> {{ weekly_task.get_days() }}</i>
19-
<i><span class="text-decoration-underline">at:</span> {{ weekly_task.the_time }} </i>
19+
<i><span class="text-decoration-underline">at:</span> {{ weekly_task.task_time }} </i>
2020
</small>
2121
<!-- End Task repeat days and time -->
2222

0 commit comments

Comments
 (0)