develop #10

Merged
s460930 merged 4 commits from develop into master 2020-12-21 14:25:54 +01:00
Showing only changes of commit 0aad49aaec - Show all commits

View File

@ -10,6 +10,7 @@ URL_REGISTER = "http://localhost:8000/api/register"
URL_PROFILE = "http://localhost:8000/api/profile"
URL_PROJECTS = "http://localhost:8000/api/projects"
class SmartPicasso(tk.Tk):
def __init__(self, *args, **kwargs):
@ -96,7 +97,7 @@ class MainView(tk.Frame):
self.frames = {}
self.token = ''
for F in (ProfileView, ProjectsView, ProjectsAddView):
frame = F(parent, controller)
frame = F(parent, controller, self)
self.frames[F] = frame
@ -107,19 +108,13 @@ class MainView(tk.Frame):
label_u.pack(pady=10, padx=10)
button_projects = tk.Button(self, text="Projects", font=FONT,
command=lambda: self.show_frame(ProjectsView))
command=lambda: self.show_frame(ProjectsView))
button_projects.pack()
button_projects2 = tk.Button(self, text="Projects Add", font=FONT,
command=lambda: self.show_frame(ProjectsAddView))
button_projects2.pack()
button_profile = tk.Button(self, text="My profile", font=FONT,
command=lambda: self.show_frame(ProfileView))
button_profile.pack()
def show_frame(self, view):
frame = self.frames[view]
frame.tkraise()
@ -202,7 +197,7 @@ class RegisterView(tk.Frame):
class ProfileView(tk.Frame):
def __init__(self, parent, controller):
def __init__(self, parent, controller, main_view_controller):
tk.Frame.__init__(self, parent)
self.token = ''
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
@ -233,24 +228,29 @@ class ProfileView(tk.Frame):
self.label_first_name['text'] = response['profile']['first_name']
self.label_last_name['text'] = response['profile']['last_name']
class ProjectsView(tk.Frame):
def __init__(self, parent, controller):
def __init__(self, parent, controller, main_view_controller):
tk.Frame.__init__(self, parent)
self.token = ''
self.projects_buttons = []
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
label.pack(pady=10, padx=10)
button_add = tk.Button(self, text="Add project", font=FONT,
command=lambda: controller.show_frame(ProjectsAddView, self.token))
command=lambda: main_view_controller.show_frame(ProjectsAddView))
button_add.pack()
button_back = tk.Button(self, text="Back", font=FONT,
command=lambda: controller.show_frame(MainView, self.token))
command=lambda: controller.show_frame(MainView, self.token))
button_back.pack()
label0 = tk.Label(self, text='Projects:', font=FONT)
label0.pack()
def start(self):
for button in self.projects_buttons:
button.destroy()
self.projects_buttons = []
headers = {'Authorization': 'Bearer ' + self.token}
resp = requests.get(URL_PROJECTS, headers=headers)
response = resp.json()
@ -258,10 +258,12 @@ class ProjectsView(tk.Frame):
for projects in response:
button_proj = tk.Button(self, text=projects['name'], font=FONT)
button_proj.pack()
self.projects_buttons.append(button_proj)
class ProjectsAddView(tk.Frame):
def __init__(self, parent, controller):
def __init__(self, parent, controller, main_view_controller):
tk.Frame.__init__(self, parent)
self.token = ''
@ -272,27 +274,27 @@ class ProjectsAddView(tk.Frame):
input0.pack()
button_add = tk.Button(self, text="Confirm and add", font=FONT,
command=lambda: self.addproject(controller, input0.get()))
command=lambda: self.add_project(main_view_controller, input0.get()))
button_add.pack()
button_back = tk.Button(self, text="Back", font=FONT,
command=lambda: controller.show_frame(ProjectsView))
command=lambda: main_view_controller.show_frame(ProjectsView))
button_back.pack()
def start(self):
print("ok")
def addproject(self, controller, projectname):
def add_project(self, controller, project_name):
headers = {'Authorization': 'Bearer ' + self.token}
data = {
"name": str(projectname)
}
"name": str(project_name)
}
print(data)
response = requests.post(URL_PROJECTS, json=data, headers=headers)
print(response)
if response.status_code == 201:
response = response.json()
controller.show_frame(MainView)
controller.show_frame(ProjectsView)
else:
print("sth wrong")
bad_pass_label = tk.Label(self, text='Something went wrong!', font=FONT)