Косметические изменения в коде

This commit is contained in:
Ivan
2021-04-26 22:50:40 +03:00
parent b2b447e392
commit c9610f7765
4 changed files with 44 additions and 44 deletions

View File

@@ -171,7 +171,7 @@ class UserApi(object):
return UserApi._raise_or_return_(
requests.post(
url=self.get_api(API_TODO_ITEMS_CREATE),
json={"text": text, "parent":parent, "finished":False},
json={"text": text, "parent": parent, "finished": False},
headers=self._access_token_(),
)
)
@@ -212,7 +212,7 @@ class UserApi(object):
return UserApi._raise_or_return_(
requests.put(
url=self.get_api(API_TODO_ITEMS_UPDATE.format(id)),
json={"text": text, "finished":finished, "parent":parent},
json={"text": text, "finished": finished, "parent": parent},
headers=self._access_token_(),
)
)
@@ -315,5 +315,6 @@ class UserApi(object):
response.raise_for_status()
try:
return response.json()
except:
except Exception as e:
print(e)
return response.content

View File

@@ -4,7 +4,9 @@ from user import User
def print_lists(lists):
for item in lists:
print(f"List: '{item.title}'", f"Id: {item.id}", "|", "|".join([str(x) for x in item.items_]))
print(
f"List: '{item.title}'", f"Id: {item.id}", "|", "|".join([str(x) for x in item.items_])
)
DEFAULT_URL = "http://127.0.0.1:8000"

View File

@@ -1,7 +1,5 @@
import os
from types import SimpleNamespace
from datetime import datetime
import numpy as np
@@ -14,12 +12,13 @@ UPDATE_ERROR = "Failed to update property: {0}"
DATETIME_STR = "%Y-%m-%dT%H:%M:%S.%fZ"
def bad_arguments(x, d):
return list((set(x) - set(d)))
class ToDoList(object):
def __init__(self, id, title, created_at=None, items=None,
parent=None, user=None):
def __init__(self, id, title, created_at=None, items=None, parent=None, user=None):
self.id = id
self.title = title
self.items_ = [] if items is None else items
@@ -88,10 +87,8 @@ class ToDoList(object):
self.user.lists_update(title=self.title, id=self.id)
class ToDoItem(object):
def __init__(self, id, text, finished=False, created_at=None,
parent=None, user=None):
def __init__(self, id, text, finished=False, created_at=None, parent=None, user=None):
self.id = id
self.text = text
self.finished = finished
@@ -125,7 +122,9 @@ class ToDoItem(object):
print(f"Item '{self}' is being synchronized...")
if "DEBUG" in os.environ:
return
self.user.todo_items_update(id=self.id, text=self.text, finished=self.finished, parent=self.parent)
self.user.todo_items_update(
id=self.id, text=self.text, finished=self.finished, parent=self.parent
)
def make_debug_lists():
@@ -142,8 +141,8 @@ def make_debug_lists():
for i in range(10)
]
class User(UserApi):
class User(UserApi):
def auth(self, user, passwd):
"""
Basic authentification
@@ -165,7 +164,7 @@ class User(UserApi):
return self.lists_
user_lists = self.lists_list()["results"]
user_items = self.todo_items_list()["results"]
toDoLists = {x["id"]:ToDoList(**x, user=self) for x in user_lists}
toDoLists = {x["id"]: ToDoList(**x, user=self) for x in user_lists}
toDoItems = [ToDoItem(**x, user=self) for x in user_items]
for toDoItem in toDoItems:
# Catching stray items
@@ -188,7 +187,6 @@ class User(UserApi):
to_remove.dispose()
return self.lists_
def appendUserList(self, title):
"""
Create a new user list

View File

@@ -162,14 +162,13 @@ class WorkSpaceFrame(tk.Frame):
self.lists = self.user.fetchUserLists()
# fill list box
self.listBox.delete(0,'end')
self.listBox.delete(0, "end")
for item in self.lists:
s = f"{str(item)}: {item.created_at.strftime('%Y-%m-%d %H:%M:%S')}"
self.listBox.insert(tk.END, s)
self.listBox.pack()
len(self.lists) > 0 and self.listBox.selection_set(first=0)
def listBox_selected(self, *args):
self.toToList.clear()