From 86b19f592e2a2f58503452ca3e2ddc6f4890865e Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Mon, 27 Apr 2020 14:10:42 +0500 Subject: [PATCH] Rename methods to snake_case --- project_amber/controllers/task.py | 8 ++++---- project_amber/handlers/task.py | 4 ++-- project_amber/models/task.py | 15 +++------------ 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/project_amber/controllers/task.py b/project_amber/controllers/task.py index d577a7f..53b0728 100644 --- a/project_amber/controllers/task.py +++ b/project_amber/controllers/task.py @@ -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) @@ -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) diff --git a/project_amber/handlers/task.py b/project_amber/handlers/task.py index 488c182..cf0f97a 100644 --- a/project_amber/handlers/task.py +++ b/project_amber/handlers/task.py @@ -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) @@ -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) diff --git a/project_amber/models/task.py b/project_amber/models/task.py index b3fdcb2..3313f16 100644 --- a/project_amber/models/task.py +++ b/project_amber/models/task.py @@ -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 @@ -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) @@ -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. @@ -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.