Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • j.michal/grady
1 result
Show changes
Commits on Source (9)
......@@ -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)
......
......@@ -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)
......
......@@ -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,
......
......@@ -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 {
......
......@@ -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)
......
......@@ -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 = {
......