def student_profile(request: HttpRequest, user_id: int) -> HttpResponse: """student profile""" try: student: Student = Student.objects.select_related( 'user', 'consent').get(user_id=user_id) except Student.DoesNotExist: raise Http404 # We will not show the student profile if he decides to hide it. if not BaseUser.is_employee( request.user) and not student.consent_granted(): return HttpResponseRedirect(reverse('students-list')) semester = Semester.objects.get_next() records = Record.objects.filter( student=student, group__course__semester=semester, status=RecordStatus.ENROLLED).select_related( 'group__teacher', 'group__teacher__user', 'group__course').prefetch_related('group__term', 'group__term__classrooms') groups = [r.group for r in records] # Highlight groups shared with the viewer in green. viewer_groups = Record.common_groups(request.user, groups) for g in groups: g.is_enrolled = g.pk in viewer_groups group_dicts = build_group_list(groups) data = { 'student': student, 'groups_json': json.dumps(group_dicts, cls=DjangoJSONEncoder), } if request.is_ajax(): return render(request, 'users/student_profile_contents.html', data) active_students = Student.get_list( begin='All', restrict_list_consent=not BaseUser.is_employee(request.user)) data.update({ 'students': active_students, 'char': "All", }) return render(request, 'users/student_profile.html', data)
def employee_profile(request: HttpRequest, user_id: int) -> HttpResponse: """employee profile""" try: employee = Employee.objects.select_related('user').get(user_id=user_id) except Employee.DoesNotExist: raise Http404 semester = Semester.objects.get_next() groups = Group.objects.filter(course__semester_id=semester.pk, teacher=employee).select_related( 'teacher', 'teacher__user', 'course').prefetch_related( 'term', 'term__classrooms') groups = list(groups) # Highlight groups shared with the viewer in green. viewer_groups = Record.common_groups(request.user, groups) for g in groups: g.is_enrolled = g.pk in viewer_groups group_dicts = build_group_list(groups) data = { 'employee': employee, 'groups_json': json.dumps(group_dicts, cls=DjangoJSONEncoder), } if request.is_ajax(): return render(request, 'users/employee_profile_contents.html', data) current_groups = Group.objects.filter( course__semester_id=semester.pk).select_related( 'teacher', 'teacher__user').distinct('teacher') active_teachers = map(lambda g: g.teacher, current_groups) for e in active_teachers: e.short_new = (e.user.first_name[:1] + e.user.last_name[:2] ) if e.user.first_name and e.user.last_name else None e.short_old = (e.user.first_name[:2] + e.user.last_name[:2] ) if e.user.first_name and e.user.last_name else None data.update({ 'employees': active_teachers, 'char': "All", }) return render(request, 'users/employee_profile.html', data)