Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Rename methods to snake_case
Browse files Browse the repository at this point in the history
  • Loading branch information
tdemin committed Apr 27, 2020
1 parent 3cafcdb commit 86b19f5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
8 changes: 4 additions & 4 deletions project_amber/controllers/task.py
Expand Up @@ -63,11 +63,11 @@ def update_children(self, task_id: int):
task = self.get_task(task_id)
if task.parent_id:
parent = self.get_task(task.parent_id)
parent_list = parent.getParents()
parent_list = parent.get_parents()
parent_list.append(parent.id)
task.setParents(parent_list)
task.set_parents(parent_list)
else:
task.setParents(list())
task.set_parents(list())
children = db.session.query(Task).filter_by(parent_id=task_id).all()
for child in children:
self.update_children(child.id)
Expand All @@ -86,7 +86,7 @@ def update_task(self, task_id: int, data: dict) -> int:
self.update_children(task.id)
else:
new_parent = self.get_task(new_details.parent_id)
if task.id in new_parent.getParents() or task.id == new_parent.id:
if task.id in new_parent.get_parents() or task.id == new_parent.id:
raise BadRequest(MSG_TASK_DANGEROUS)
task.parent_id = new_parent.id
self.update_children(task.id)
Expand Down
4 changes: 2 additions & 2 deletions project_amber/handlers/task.py
Expand Up @@ -55,7 +55,7 @@ def task_request():
tasks = tc.get_tasks(query)
tasksList = list()
for task in tasks:
tasksList.append(task.toDict())
tasksList.append(task.to_dict())
return dumps(tasksList)
if request.method == "POST":
new_id = tc.add_task(request.json)
Expand Down Expand Up @@ -97,7 +97,7 @@ def task_id_request(task_id: int):
tc = TaskController(request.user)
if request.method == "GET":
task = tc.get_task(task_id)
response = task.toDict()
response = task.to_dict()
return dumps(response)
if request.method == "PATCH":
tc.update_task(task_id, request.json)
Expand Down
15 changes: 3 additions & 12 deletions project_amber/models/task.py
Expand Up @@ -25,14 +25,7 @@ class Task(db.Model):
reminder = db.Column(db.BigInteger)
parents = db.Column(db.String(2048), nullable=False)

def isChild(self) -> bool:
"""
Helper method. Simply checks whether the task is of gen 0 or not.
"""
if self.gen > 0: return True
return False

def toDict(self) -> dict:
def to_dict(self) -> dict:
"""
Helper method that converts public task data (ID, text, PID, status,
modtime, deadline and reminders) to a dict that can be safely used in
Expand All @@ -52,8 +45,6 @@ def toDict(self) -> dict:
def merge(self, task: "Task"):
"""
Copies public data from another task.
Does not update task generations; this has to be done manually.
"""
for i in ("parent_id", "text", "status", "reminder", "deadline"):
new_value = getattr(task, i)
Expand Down Expand Up @@ -87,7 +78,7 @@ def delete(self):
"""
db.session.delete(self)

def getParents(self) -> List[int]:
def get_parents(self) -> List[int]:
"""
Retrieves a list of connected parent IDs that have a higher tree level.
The list is deserialized from a string contained in the database.
Expand All @@ -96,7 +87,7 @@ def getParents(self) -> List[int]:
return list()
return list(map(lambda x: int(x), self.parents.split(SEPARATOR)))

def setParents(self, pids: List[int]) -> str:
def set_parents(self, pids: List[int]) -> str:
"""
Serializes the provided list of connected parent IDs that have a higher
tree level into a string. Returns the resulting string.
Expand Down

0 comments on commit 86b19f5

Please sign in to comment.