Remove Duedates with no dates from list in store
This commit is contained in:
parent
24b36ac6df
commit
6595890c48
|
|
@ -91,7 +91,6 @@ const appointments = computed(() => {
|
|||
.allDueDates()
|
||||
.filter(
|
||||
(dueDate) =>
|
||||
hasDueDate(dueDate) &&
|
||||
isMatchingCourse(dueDate) &&
|
||||
isMatchingSession(dueDate) &&
|
||||
isMatchingCircle(dueDate)
|
||||
|
|
@ -109,10 +108,6 @@ const isMatchingCircle = (dueDate: DueDate) =>
|
|||
const isMatchingCourse = (dueDate: DueDate) =>
|
||||
courseSessions.value.map((cs) => cs.id).includes(dueDate.course_session_id);
|
||||
|
||||
const hasDueDate = (dueDate: DueDate) => {
|
||||
return dueDate.start || dueDate.end;
|
||||
};
|
||||
|
||||
const numAppointmentsToShow = ref(7);
|
||||
const canLoadMore = computed(() => {
|
||||
return numAppointmentsToShow.value < appointments.value.length;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
from django.db.models import Q
|
||||
from rest_framework import serializers
|
||||
|
||||
from vbv_lernwelt.core.utils import StringIDField
|
||||
|
|
@ -63,7 +64,9 @@ class CourseSessionSerializer(serializers.ModelSerializer):
|
|||
# return obj.course.get_course_url()
|
||||
|
||||
def get_due_dates(self, obj):
|
||||
due_dates = DueDate.objects.filter(course_session=obj)
|
||||
due_dates = DueDate.objects.filter(
|
||||
Q(start__isnull=False) | Q(end__isnull=False), course_session=obj
|
||||
)
|
||||
return DueDateSerializer(due_dates, many=True).data
|
||||
|
||||
class Meta:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import json
|
||||
from datetime import datetime
|
||||
|
||||
from django.utils import timezone
|
||||
from rest_framework.test import APITestCase
|
||||
|
||||
from vbv_lernwelt.core.create_default_users import create_default_users
|
||||
|
|
@ -7,6 +9,9 @@ from vbv_lernwelt.core.models import User
|
|||
from vbv_lernwelt.course.consts import COURSE_TEST_ID
|
||||
from vbv_lernwelt.course.creators.test_course import create_test_course
|
||||
from vbv_lernwelt.course.models import CourseSession, CourseSessionUser
|
||||
from vbv_lernwelt.course_session.models import CourseSessionAssignment
|
||||
from vbv_lernwelt.duedate.factories import DueDateFactory
|
||||
from vbv_lernwelt.learnpath.models import LearningContentAssignment
|
||||
|
||||
|
||||
class CourseCompletionApiTestCase(APITestCase):
|
||||
|
|
@ -51,3 +56,41 @@ class CourseCompletionApiTestCase(APITestCase):
|
|||
|
||||
print(json.dumps(response.json(), indent=4))
|
||||
self.assertEqual(response.json()[0]["id"], str(self.course_session.id))
|
||||
|
||||
def test_api_hasNoDueDates(self):
|
||||
self.client.login(username="admin", password="test")
|
||||
response = self.client.get(f"/api/course/sessions/")
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(len(response.json()), 1)
|
||||
|
||||
print(json.dumps(response.json(), indent=4))
|
||||
self.assertEqual(response.json()[0]["due_dates"], [])
|
||||
|
||||
def test_api_hasDueDates(self):
|
||||
cs = CourseSession.objects.first()
|
||||
|
||||
due_date = DueDateFactory(
|
||||
start=timezone.make_aware(datetime.now()),
|
||||
course_session=cs,
|
||||
title="Test Due Date",
|
||||
)
|
||||
csa = CourseSessionAssignment.objects.create(
|
||||
course_session=cs,
|
||||
learning_content=LearningContentAssignment.objects.get(
|
||||
slug=f"test-lehrgang-lp-circle-reisen-lc-mein-kundenstamm"
|
||||
),
|
||||
)
|
||||
|
||||
csa.submission_deadline = due_date
|
||||
|
||||
csa.save()
|
||||
self.client.login(username="admin", password="test")
|
||||
response = self.client.get(f"/api/course/sessions/")
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
print(json.dumps(response.json(), indent=4))
|
||||
self.assertEqual(len(response.json()), 1)
|
||||
|
||||
self.assertEqual(len(response.json()[0]["due_dates"]), 1)
|
||||
self.assertEqual(response.json()[0]["due_dates"][0]["title"], "Test Due Date")
|
||||
|
|
|
|||
Loading…
Reference in New Issue