forked from ozcanyarimdunya/python_mini_projeler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c53943
commit d50e64c
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
[Proje - 01] Çarpım Tablosu/[Proje - 26] Advanced Todo/todo.py
This file contains 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,85 @@ | ||
import uuid | ||
|
||
|
||
class Todo: | ||
def __init__(self, name, done=False): | ||
self.id = str(uuid.uuid4()).split('-')[0] | ||
self.name = name | ||
self.done = done | ||
|
||
def __repr__(self): | ||
return f"{self.id} {self.name}({'✔️' if self.done else '❌'})" | ||
|
||
|
||
class Repository(list): | ||
|
||
def append(self, todo: Todo): | ||
for _todo in self: | ||
if _todo.id == todo.id: | ||
return | ||
|
||
super(Repository, self).append(todo) | ||
|
||
def update(self, todo: Todo): | ||
for _todo in self: | ||
if _todo.id == todo.id: | ||
_todo.name = todo.name | ||
_todo.done = todo.done | ||
return | ||
else: | ||
raise Exception("No such todo!") | ||
|
||
def delete(self, todo: Todo): | ||
for _todo in self: | ||
if _todo.id == todo.id: | ||
self.remove(_todo) | ||
return | ||
else: | ||
raise Exception("No such todo!") | ||
|
||
|
||
repo = Repository() | ||
|
||
|
||
def add(*todos): | ||
if len(todos) == 1: | ||
repo.append(*todos) | ||
else: | ||
for todo in todos: | ||
repo.append(todo) | ||
|
||
|
||
def update(*todos): | ||
if len(todos) == 1: | ||
repo.update(*todos) | ||
else: | ||
for todo in todos: | ||
repo.update(todo) | ||
|
||
|
||
def delete(*todos): | ||
if len(todos) == 1: | ||
repo.delete(*todos) | ||
else: | ||
for todo in todos: | ||
repo.delete(todo) | ||
|
||
|
||
if __name__ == '__main__': | ||
t = Todo("Go home") | ||
t2 = Todo("Go shopping") | ||
t3 = Todo("Go school") | ||
|
||
add(t, t2, t3) | ||
print(repo) | ||
# [0d5b07a4 Go home(❌), 676ef76e Go shopping(❌), 7f46f32d Go school(❌)] | ||
|
||
t.done = True | ||
t2.done = True | ||
update(t, t2) | ||
print(repo) | ||
# [0d5b07a4 Go home(✔️), 676ef76e Go shopping(✔️), 7f46f32d Go school(❌)] | ||
|
||
delete(t2, t3) | ||
print(repo) | ||
# [0d5b07a4 Go home(✔️)] |