diff --git a/core/tests/test_export.py b/core/tests/test_export.py index 3768a277374187657e9e0e5d940753baca660270..5ef57548e9c303d50c40bc68d3293048da76890c 100644 --- a/core/tests/test_export.py +++ b/core/tests/test_export.py @@ -96,7 +96,9 @@ class ExportInstanceTest(APITestCase): def setUp(self): self.client = APIClient() self.client.force_login(user=self.data['reviewers'][0]) - self.response = self.client.get('/api/instance/export/') + self.response = self.client.get('/api/instance/export/', + data={'setPasswords': True, + 'selected_exam': self.data['exams'][0].exam_type_id}) def test_can_access(self): self.assertEqual(status.HTTP_200_OK, self.response.status_code) @@ -180,7 +182,8 @@ class ExportJSONTest(APITestCase): def setUp(self): self.client = APIClient() self.client.force_login(user=self.data['reviewers'][0]) - self.response = self.client.post('/api/export/json/') + self.response = self.client.post('/api/export/json/', + data={'selected_exam': self.data['exams'][0].exam_type_id}) def test_can_access(self): self.assertEqual(status.HTTP_200_OK, self.response.status_code) @@ -194,8 +197,8 @@ class ExportJSONTest(APITestCase): self.assertEqual('', student1['Name']) self.assertEqual('', student2['Name']) - self.assertEqual('Test Exam 01', student1['Exams'][0]['exam']['module_reference']) - self.assertEqual('Test Exam 01', student2['Exams'][0]['exam']['module_reference']) + self.assertEqual('Test Exam 01', student1['Exam']) + self.assertEqual('Test Exam 01', student2['Exam']) self.assertEqual('student01', student1['Username']) self.assertEqual('student02', student2['Username']) @@ -203,17 +206,17 @@ class ExportJSONTest(APITestCase): self.assertEqual('********', student2['Password']) self.assertEqual('********', student1['Password']) - self.assertEqual('01. Sort', student1['Scores'][0]['submissions'][0]['type']) - self.assertEqual('01. Sort', student2['Scores'][0]['submissions'][0]['type']) + self.assertEqual('01. Sort', student1['Scores'][0]['type']) + self.assertEqual('01. Sort', student2['Scores'][0]['type']) - self.assertEqual('02. Shuffle', student1['Scores'][0]['submissions'][1]['type']) - self.assertEqual('02. Shuffle', student2['Scores'][0]['submissions'][1]['type']) + self.assertEqual('02. Shuffle', student1['Scores'][1]['type']) + self.assertEqual('02. Shuffle', student2['Scores'][1]['type']) - self.assertEqual(5, student1['Scores'][0]['submissions'][0]['score']) - self.assertEqual(0, student2['Scores'][0]['submissions'][0]['score']) + self.assertEqual(5, student1['Scores'][0]['score']) + self.assertEqual(0, student2['Scores'][0]['score']) - self.assertEqual(0, student2['Scores'][0]['submissions'][1]['score']) - self.assertEqual(0, student2['Scores'][0]['submissions'][1]['score']) + self.assertEqual(0, student2['Scores'][1]['score']) + self.assertEqual(0, student2['Scores'][1]['score']) class ExportJSONAndSetPasswordsTest(APITestCase): @@ -225,7 +228,8 @@ class ExportJSONAndSetPasswordsTest(APITestCase): self.client = APIClient() self.client.force_login(user=self.data['reviewers'][0]) self.response = self.client.post('/api/export/json/', - data={'setPasswords': True}) + data={'setPasswords': True, + 'selected_exam': self.data['exams'][0].exam_type_id}) def test_can_access(self): self.assertEqual(status.HTTP_200_OK, self.response.status_code) diff --git a/core/views/export.py b/core/views/export.py index 7a02c8e2a1b77e523c40ab40965d9a3cb97cc520..d0b18b139594172644a55fa7814d68de6eeafadb 100644 --- a/core/views/export.py +++ b/core/views/export.py @@ -9,7 +9,7 @@ from core.models import StudentInfo, UserAccount, ExamType, SubmissionType from core.permissions import IsReviewer from core.serializers import SubmissionTypeSerializer, \ ExamSerializer, UserAccountSerializer -from core.serializers.student import StudentExportSerializer, ExamInfoSerializer +from core.serializers.student import StudentExportSerializer from core.serializers.tutor import CorrectorSerializer words = xp.generate_wordlist(wordfile=xp.locate_wordfile(), min_length=5, max_length=8) @@ -34,25 +34,24 @@ class StudentJSONExport(APIView): def post(self, request, format=None): set_passwords = request.data.get('set_passwords') passwords = _set_student_passwords() if set_passwords else None + selected_exam = request.data.get('selected_exam') + result = ExamType.objects.get(exam_type_id=selected_exam) content = [ {'Matrikel': student.matrikel_no, 'Name': student.user.fullname, 'Username': student.user.username, 'Email': student.user.email, - 'Exams': ExamInfoSerializer(student.exams.all(), many=True).data, + 'Exam': result.module_reference, 'Password': passwords[student.user.pk] if set_passwords else '********', 'Scores': [ { - 'exam': exam_info.exam.module_reference, - 'submissions': [ - { - 'type': submission_type, - 'score': score - } for submission_type, score in exam_info.score_per_submission().items()] - } for exam_info in student.exams.all()] + 'type': submission_type, + 'score': score + } for submission_type, score in student.exams.get( + exam__exam_type_id=selected_exam).score_per_submission().items()] } for student - in StudentInfo.objects.all()] + in StudentInfo.objects.all().filter(exams__exam__exam_type_id=selected_exam)] return Response(content) diff --git a/frontend/src/api.ts b/frontend/src/api.ts index 0a9b569c5d7c1831a570696d09b5125cf3334433..77ef7112a8f79a0d1381941c04116ef899ab10f2 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -288,7 +288,7 @@ export async function fetchReleases () { return (await ax.get(url)).data as GitlabRelease[] } -export interface StudentExportOptions { setPasswords?: boolean } +export interface StudentExportOptions { setPasswords?: boolean, selectedExam: string } export interface StudentExportItem { Matrikel: string, Name: string, diff --git a/frontend/src/components/mixins/exportMixin.ts b/frontend/src/components/mixins/exportMixin.ts index b68131f1929d5f404ea4b4b73f63f31b75fc60ff..e7108b64b5cfdb84f2913a4c9c034d6a45f3ccf0 100644 --- a/frontend/src/components/mixins/exportMixin.ts +++ b/frontend/src/components/mixins/exportMixin.ts @@ -4,6 +4,8 @@ import { fetchStudentExportData, StudentExportItem, InstanceExportData, fetchIns import { getters } from '@/store/getters' import { mutations as mut } from '@/store/mutations' import { saveAs } from 'file-saver' +import { Exam } from '@/models' +import { ConfigModule } from '../../store/modules/config' let download = saveAs @@ -30,9 +32,11 @@ export class exportMixin extends Vue { async getExportFile (type: string) { this.loading = true + let selected_exam = ConfigModule.state.config.examId + let studentData if (type === 'data') { - studentData = await fetchStudentExportData({ setPasswords: this.setPasswords }) + studentData = await fetchStudentExportData({ setPasswords: this.setPasswords, selectedExam: selected_exam }) } else if (type === 'instance') { studentData = await fetchInstanceExportData() } else { diff --git a/functional_tests/test_export_modal.py b/functional_tests/test_export_modal.py index 61387780e8e6b4b8fe31f211f390ee222a1eeb21..cab6adbf33dce5e81ca29b2371953ef5002d53c6 100644 --- a/functional_tests/test_export_modal.py +++ b/functional_tests/test_export_modal.py @@ -115,10 +115,9 @@ class ExportTestModal(GradyTestCase): with open(JSON_EXPORT_FILE) as f: data = json.load(f) - self.assertEqual('B.Inf.4242 Test Module', - data[0]['Exams'][0]['exam']['moduleReference']) + self.assertEqual('B.Inf.4242 Test Module', data[0]['Exam']) + except Exception as e: - print(data) raise e finally: os.remove(JSON_EXPORT_FILE) diff --git a/grady/settings/live.py b/grady/settings/live.py index 8ac84849c3139c211665074e97da6e8790c42cb5..405c0bed4e887cb8084347ab75da65a1e25ea82f 100644 --- a/grady/settings/live.py +++ b/grady/settings/live.py @@ -32,9 +32,7 @@ except (IOError, Exception): to generate your secret key!' % SECRET_FILE) # adjust this setting to your needs -ALLOWED_HOSTS = [ - 'localhost', '.grady.janmax.org', 'grady.informatik.uni-goettingen.de' -] +ALLOWED_HOSTS = [ 'localhost', '.informatik.uni-goettingen.de' ] # sample postgres sql database configuration DATABASES = {