Skip to content
Snippets Groups Projects
Commit a2fb8428 authored by Oliwer Mattsson's avatar Oliwer Mattsson :headphones:
Browse files

Funktioner för att lägga till nytt projekt & redigera ett projekt.

parent 63b95d17
No related branches found
No related tags found
No related merge requests found
{
"projects": [
{
"title": "project_title",
"title": "project_example",
"project_id": 0,
"techniques": "techniques",
"desc": "description",
......@@ -20,6 +20,18 @@
"desc": "It's great!",
"img_url": "logo.jpg",
"url": "https://www.github.com/"
},
{
"title": "MySecondProject",
"project_id": 2,
"techniques": [
"python",
"html",
"css"
],
"desc": "This is a python project!",
"img_url": "logo.png",
"url": "https://www.github.com"
}
]
}
\ No newline at end of file
}
......@@ -27,26 +27,33 @@ def save(data):
file.close()
# Update unique techniques if user added new ones to the file.
get_techniques_stats(data)
# Reload data
load()
def get_project(data, id):
pass
# Get project by ID
def get_project(data, id):
for n in range(0, get_project_count(data)):
if data["projects"][n]["project_id"] == id:
return data["projects"][n]
# Get project count
def get_project_count(data):
return len(data["projects"])
# Get techniques from project by ID
def get_techniques(data, id):
for n in range(0, get_project_count(data)):
if data["projects"][n]["project_id"] == id:
return (data["projects"][n]["techniques"])
return get_project(data,id)['techniques']
# Gets all unique techniques from all projects ! COULD USE SOME FILTERING !
def get_techniques_stats(data):
techniques = []
......@@ -110,10 +117,38 @@ def new_project(data):
pass
def list_projects(data):
cls()
for project in data['projects']:
pprint.pp(project)
print("\n")
def edit_project(data):
pass
def edit_project(data, id):
while True:
if id > get_project_count(data) or id < 0:
print("Project ID doesn't exist.\n")
id = int(input("Project_ID to edit: "))
else:
cls()
project = get_project(data, id)
project.pop('project_id') # Project ID shouldn't be changed
print(f"Editing project: {project['title']}\n")
pprint.pp(project)
print("")
for field in enumerate(project):
print(f"{field[0]}: {field[1]}")
input("\nField to edit: ")
......@@ -124,7 +159,7 @@ def delete_project(data):
def menu(data):
menu_items = ["Add new project", "Edit existing project", "Delete project", "Quit"]
menu_items = ["Add new project", "List projects", "Edit existing project", "Delete project", "Quit"]
menu_index = 0
while True:
......@@ -132,11 +167,11 @@ def menu(data):
cls()
titular = r"""
____ _ __ _ _
| _ \ ___ _ __ | |_ / _| ___ | | (_) ___
| |_) | / _ \ | '__| | __| | |_ / _ \ | | | | / _ \
| __/ | (_) | | | | |_ | _| | (_) | | | | | | (_) |
|_| \___/ |_| \__| |_| \___/ |_| |_| \___/
____ _ __ _ _
| _ \ ___ _ __ | |_ / _| ___ | | (_) ___
| |_) | / _ \ | '__| | __| | |_ / _ \ | | | | / _ \
| __/ | (_) | | | | |_ | _| | (_) | | | _ | | | (_) |
|_| \___/ |_| \__| |_| \___/ |_| (_) |_| \___/
"""
print(titular)
......@@ -149,12 +184,15 @@ def menu(data):
if option == 1:
new_project(data)
print("1")
elif option == 2:
edit_project(data)
list_projects(data)
input()
elif option == 3:
delete_project(data)
list_projects(data)
edit_project(data, int(input("Project_ID to edit: ")))
elif option == 4:
delete_project(data, int(input("Project_ID to delete: ")))
elif option == 5:
cls()
break
except:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment