From e928937d4302980e4b67f00b79b9b8c146858595 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sat, 23 Oct 2021 07:28:34 +0000 Subject: [PATCH] Add course description to class page --- apiserver/apiserver/api/serializers.py | 16 ++++++++-------- webclient/src/Classes.js | 15 ++++++++++++--- webclient/src/InstructorClasses.js | 4 ++-- webclient/src/InstructorCourses.js | 5 ++++- webclient/src/Training.js | 2 +- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/apiserver/apiserver/api/serializers.py b/apiserver/apiserver/api/serializers.py index f07f2a5..c1738bd 100644 --- a/apiserver/apiserver/api/serializers.py +++ b/apiserver/apiserver/api/serializers.py @@ -449,9 +449,14 @@ class StudentTrainingSerializer(TrainingSerializer): attendance_status = serializers.ChoiceField(['Waiting for payment', 'Withdrawn']) +class CourseSerializer(serializers.ModelSerializer): + class Meta: + model = models.Course + fields = ['id', 'name', 'is_old', 'description'] + class SessionSerializer(serializers.ModelSerializer): student_count = serializers.SerializerMethodField() - course_name = serializers.SerializerMethodField() + course_data = serializers.SerializerMethodField() instructor_name = serializers.SerializerMethodField() datetime = serializers.DateTimeField() course = serializers.PrimaryKeyRelatedField(queryset=models.Course.objects.all()) @@ -467,8 +472,8 @@ class SessionSerializer(serializers.ModelSerializer): def get_student_count(self, obj): return len([x for x in obj.students.all() if x.attendance_status != 'Withdrawn']) - def get_course_name(self, obj): - return obj.course.name + def get_course_data(self, obj): + return CourseSerializer(obj.course).data def get_instructor_name(self, obj): if obj.instructor and hasattr(obj.instructor, 'member'): @@ -481,11 +486,6 @@ class SessionListSerializer(SessionSerializer): students = None -class CourseSerializer(serializers.ModelSerializer): - class Meta: - model = models.Course - fields = ['id', 'name'] - class CourseDetailSerializer(serializers.ModelSerializer): sessions = SessionListSerializer(many=True, read_only=True) name = serializers.CharField(max_length=100) diff --git a/webclient/src/Classes.js b/webclient/src/Classes.js index da401e5..c961986 100644 --- a/webclient/src/Classes.js +++ b/webclient/src/Classes.js @@ -28,7 +28,7 @@ function ClassTable(props) { {classes.length ? classes.map(x => - {x.course_name} + {x.course_data.name} {moment.utc(x.datetime).tz('America/Edmonton').format('ll')} @@ -170,7 +170,7 @@ export function ClassDetail(props) { Name: - {clazz.course_name} + {clazz.course_data.name} @@ -201,6 +201,15 @@ export function ClassDetail(props) { +
Course Description
+ {clazz.course_data.is_old ? + clazz.course_data.description.split('\n').map((x, i) => +

{x}

+ ) + : +
+ } +
Attendance
{(isAdmin(user) || clazz.instructor === user.id) && @@ -230,7 +239,7 @@ export function ClassDetail(props) {

Please pay the course fee of ${clazz.cost} to confirm your attendance.

diff --git a/webclient/src/InstructorClasses.js b/webclient/src/InstructorClasses.js index b602850..b6f46b3 100644 --- a/webclient/src/InstructorClasses.js +++ b/webclient/src/InstructorClasses.js @@ -16,7 +16,7 @@ class AttendanceSheet extends React.Component { return (
-
{clazz.course_name} Attendance
+
{clazz.course_data.name} Attendance

{moment.utc(clazz.datetime).tz('America/Edmonton').format('llll')} {num >= 2 ? ', '+num+' students sorted by registration time.' : '.'} @@ -406,7 +406,7 @@ export function InstructorClassList(props) { {sameClasses.length ? sameClasses.map(x =>

- {moment.utc(x.datetime).tz('America/Edmonton').format('LT')} — {x.course_name} + {moment.utc(x.datetime).tz('America/Edmonton').format('LT')} — {x.course_data.name}

) : diff --git a/webclient/src/InstructorCourses.js b/webclient/src/InstructorCourses.js index ef11bab..d397cf5 100644 --- a/webclient/src/InstructorCourses.js +++ b/webclient/src/InstructorCourses.js @@ -173,7 +173,10 @@ export function InstructorCourseList(props) {
Instructor Panel
- {!open && success &&

Added to bottom of course list! View the course.

} + {!open && success && <> +

Added to bottom of course list!

+

View the course.

+ } {open ?
diff --git a/webclient/src/Training.js b/webclient/src/Training.js index 758a6fa..72d154f 100644 --- a/webclient/src/Training.js +++ b/webclient/src/Training.js @@ -94,7 +94,7 @@ export function TrainingList(props) { {training.slice().sort((a, b) => a.session.datetime < b.session.datetime ? 1 : -1).map(x => - {x.session.course_name} + {x.session.course_data.name} {moment(x.session.datetime).format('MMMM Do YYYY')}