Skip to content

Commit

Permalink
fix: score creation
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutV committed May 23, 2024
1 parent dab49cb commit 90c7854
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
6 changes: 5 additions & 1 deletion backend/api/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from api.models.student import Student
from api.models.submission import (ExtraCheckResult, StateEnum,
StructureCheckResult, Submission)
from api.models.teacher import Teacher
from api.tasks.docker_image import (task_docker_image_build,
task_docker_image_remove)
from api.tasks.extra_check import task_extra_check_start
Expand Down Expand Up @@ -35,8 +36,11 @@ def _user_creation(user: User, attributes: dict, **_):
"""Upon user creation, auto-populate additional properties"""
student_id: str = cast(str, attributes.get("ugentStudentID"))

if student_id is not None:
if student_id is None:
Student.create(user, student_id=student_id)
else:
# For now, we assume that everyone without a student ID is a teacher.
Teacher.create(user)


@receiver(run_docker_image_build)
Expand Down
2 changes: 1 addition & 1 deletion backend/api/tasks/docker_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def task_docker_image_build(docker_image: DockerImage):
client.images.build(path=MEDIA_ROOT, dockerfile=docker_image.file.path,
tag=get_docker_image_tag(docker_image), rm=True, quiet=True, forcerm=True)
docker_image.state = StateEnum.READY
except Exception:
except (docker.errors.BuildError, docker.errors.APIError):
docker_image.state = StateEnum.ERROR
notification_type = NotificationType.DOCKER_IMAGE_BUILD_ERROR
finally:
Expand Down
2 changes: 1 addition & 1 deletion backend/api/views/user_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def notifications(self, request: Request, pk: str):
# Get the notifications for the user
notifications = Notification.objects.filter(user=pk, is_read=False).order_by("-created_at")

if 0 < notifications.count() < count:
if notifications.count() < count:
notifications = list(notifications) + list(
Notification.objects.filter(user=pk, is_read=True).order_by("-created_at")[:count - notifications.count()]
)
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/projects/groups/GroupsManageTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import DataTable, { type DataTableRowExpandEvent } from 'primevue/datatable';
import Column from 'primevue/column';
import AllSubmission from '@/components/submissions/AllSubmission.vue';
import InputNumber from 'primevue/inputnumber';
import InputNumber, { InputNumberBlurEvent } from 'primevue/inputnumber';
import { type Project } from '@/types/Project.ts';
import { useStudents } from '@/composables/services/student.service.ts';
import { ref } from 'vue';
Expand Down Expand Up @@ -35,7 +35,7 @@ const editingGroup = ref<Group | null>();
* @param group The group to update.
* @param score The new score.
*/
function updateGroupScore(group: Group, score: number): void {
function updateGroupScore(group: Group, score: number|string): void {
emit('update:group-score', group, score);
editingGroup.value = null;
}
Expand Down Expand Up @@ -79,7 +79,7 @@ async function expandGroup(event: DataTableRowExpandEvent): Promise<void> {
<template #body="{ data }">
<i :class="PrimeIcons.CHART_BAR" class="mr-2" />
<template v-if="editingGroup === data">
<InputNumber :model-value="data.score" @change="updateGroupScore(data, $event.target.value)" /> /
<InputNumber :model-value="data.score" @blur="(event: InputNumberBlurEvent) => updateGroupScore(data, event.value)" /> /
{{ project.max_score }}
</template>
<template v-else>
Expand Down
18 changes: 13 additions & 5 deletions frontend/src/views/projects/roles/TeacherProjectView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useRoute } from 'vue-router';
import { useMessagesStore } from '@/store/messages.store.ts';
import { type Group } from '@/types/Group.ts';
import { type Assistant } from '@/types/users/Assistant.ts';
import { processError } from '@/composables/services/helpers.ts';
/* Props */
defineProps<{
Expand All @@ -37,11 +38,18 @@ const { groups, getGroupsByProject, updateGroup } = useGroup();
* @param score The new score.
*/
async function updateGroupScore(group: Group, score: number): Promise<void> {
await updateGroup({
...group,
score,
});
group.score = score;
try {
await updateGroup({
...group,
score,
}, false);
group.score = score;
addSuccessMessage('Gelukt', 'De groepsscore is bijgewerkt.');
} catch (error) {
processError(error);
}
}
/**
Expand Down

0 comments on commit 90c7854

Please sign in to comment.