Commit 1ececa6b authored by NikolaiDokken's avatar NikolaiDokken
Browse files

post group done

parent 9148240a
Pipeline #161435 passed with stage
in 21 seconds
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
......
......@@ -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 usernames" id="group-input" />
<input class="form-control" name="group" type="text" placeholder="Group name: username1, username2" id="group-input" />
<input type="button" class="btn btn-primary mt-1 mb-2" id="button-submit-group" value="Submit">
</div>
</div>
......
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();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment