Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Egna datormiljön
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TDP003 - Projekt
Egna datormiljön
Commits
a2fb8428
Commit
a2fb8428
authored
6 months ago
by
Oliwer Mattsson
Browse files
Options
Downloads
Patches
Plain Diff
Funktioner för att lägga till nytt projekt & redigera ett projekt.
parent
63b95d17
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
MyPortfolio/data.json
+14
-2
14 additions, 2 deletions
MyPortfolio/data.json
MyPortfolio/data_layer.py
+56
-18
56 additions, 18 deletions
MyPortfolio/data_layer.py
with
70 additions
and
20 deletions
MyPortfolio/data.json
+
14
−
2
View file @
a2fb8428
{
"projects"
:
[
{
"title"
:
"project_
tit
le"
,
"title"
:
"project_
examp
le"
,
"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
}
This diff is collapsed.
Click to expand it.
MyPortfolio/data_layer.py
+
56
−
18
View file @
a2fb8428
...
...
@@ -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
(
"
\n
Field 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
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment