Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Nikolai Roede Dokken
tdt4242-SecFit
Commits
1ececa6b
Commit
1ececa6b
authored
Mar 12, 2022
by
NikolaiDokken
Browse files
post group done
parent
9148240a
Pipeline
#161435
passed with stage
in 21 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
backend/secfit/groups/serializers.py
View file @
1ececa6b
from
rest_framework
import
serializers
from
groups.models
import
Group
from
django.contrib.auth
import
get_user_model
import
logging
class
GroupSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
...
...
@@ -13,27 +12,13 @@ class GroupSerializer(serializers.HyperlinkedModelSerializer):
]
def
create
(
self
,
validated_data
):
logger
=
logging
.
getLogger
(
'django'
)
name
=
validated_data
[
"name"
]
coach
=
validated_data
[
"coach"
]
#athletes = validated_data["athletes"]
#coach = get_user_model().objects.filter
#athletes = athletes.split(",")
#logging.info("Log message goes here.")
#logging.info(athletes)
files_data
=
[]
if
"athletes"
in
validated_data
:
files_data
=
validated_data
.
pop
(
"athletes"
)
group_obj
=
Group
.
objects
.
create
(
**
validated_data
)
for
ath
in
files_data
:
logging
.
info
(
"SBDHJSBDHJASBDADJHADBS NEGER"
)
group_obj
.
athletes
.
push
(
ath
)
# group_obj.save()
#print(athletes)
#for athlete in athletes:
# group_obj.athletes.set(athlete)
group_obj
.
athletes
.
set
(
files_data
)
return
group_obj
...
...
frontend/www/myathletes.html
View file @
1ececa6b
...
...
@@ -50,7 +50,7 @@
<div
id=
"list-groups-div"
class=
"col-lg-6"
>
<label
for=
"group-control"
class=
"form-label mt-2"
>
Groups
</label>
<div
id=
"group-control"
></div>
<input
class=
"form-control"
name=
"group"
type=
"text"
placeholder=
"
Comma-separated
username
s
"
id=
"group-input"
/>
<input
class=
"form-control"
name=
"group"
type=
"text"
placeholder=
"
Group name: username1,
username
2
"
id=
"group-input"
/>
<input
type=
"button"
class=
"btn btn-primary mt-1 mb-2"
id=
"button-submit-group"
value=
"Submit"
>
</div>
</div>
...
...
frontend/www/scripts/group.js
View file @
1ececa6b
function
generateGroupForm
()
{
async
function
generateGroupForm
()
{
let
form
=
document
.
querySelector
(
"
#form-group
"
);
let
formData
=
new
FormData
(
form
);
...
...
@@ -6,19 +6,27 @@ function generateGroupForm() {
let
input
=
formData
.
get
(
"
group
"
);
let
groupName
=
input
.
split
(
"
:
"
)[
0
];
let
athletes
=
input
.
split
(
"
:
"
)[
1
].
split
(
"
,
"
)[
0
];
submitForm
.
append
(
"
name
"
,
"
Nikos gruppe 3
"
);
submitForm
.
append
(
"
athletes
"
,
[
"
http://localhost:8000/api/users/7/
"
,
"
http://localhost:8000/api/users/8/
"
,
]);
submitForm
.
append
(
"
coach
"
,
"
http://localhost:8000/api/users/6/
"
);
submitForm
.
append
(
"
name
"
,
groupName
);
let
athletes
=
input
.
split
(
"
:
"
)[
1
].
replaceAll
(
"
"
,
""
).
split
(
"
,
"
);
let
currentUser
=
await
getCurrentUser
();
for
(
let
athlete
of
athletes
)
{
let
response
=
await
sendRequest
(
"
GET
"
,
`
${
HOST
}
/api/users/
${
athlete
}
/`
);
let
result
=
await
response
.
json
();
submitForm
.
append
(
"
athletes
"
,
result
.
url
);
}
console
.
log
(
currentUser
.
url
);
submitForm
.
append
(
"
coach
"
,
currentUser
.
url
);
return
submitForm
;
}
async
function
createGroup
()
{
let
submitForm
=
generateGroupForm
();
let
submitForm
=
await
generateGroupForm
();
let
response
=
await
sendRequest
(
"
POST
"
,
...
...
@@ -28,7 +36,8 @@ async function createGroup() {
);
if
(
response
.
ok
)
{
// window.location.reload();
document
.
getElementById
(
"
group-input
"
).
value
=
""
;
window
.
location
.
reload
();
return
;
}
else
{
let
data
=
await
response
.
json
();
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment