Skip to content

Commit

Permalink
Merge branch 'develop' into 148-advanced-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robinpdev committed May 23, 2024
2 parents d4d7653 + b68c5ec commit 7ee0059
Show file tree
Hide file tree
Showing 23 changed files with 690 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.13 on 2024-05-22 15:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('submissions', '0004_remove_submissions_file_and_more'),
]

operations = [
migrations.AddField(
model_name='submissions',
name='feedback_simple_test',
field=models.JSONField(blank=True, null=True),
),
migrations.AddField(
model_name='submissions',
name='output_simple_test',
field=models.BooleanField(blank=True, default=False),
),
]
4 changes: 4 additions & 0 deletions backend/pigeonhole/apps/submissions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class Submissions(models.Model):
eval_result = models.BooleanField(default=None, null=True)
eval_output = models.TextField(null=True)

output_simple_test = models.BooleanField(default=False, blank=True)
feedback_simple_test = models.JSONField(null=True, blank=True)
objects = models.Manager()

# submission_nr is automatically assigned and unique per group, and
Expand Down Expand Up @@ -149,4 +151,6 @@ class Meta:
"submission_nr",
"group_id",
"draft",
"output_simple_test",
"feedback_simple_test",
]
39 changes: 23 additions & 16 deletions backend/pigeonhole/apps/submissions/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fnmatch
import json
import os
import shutil
import zipfile
Expand Down Expand Up @@ -66,9 +67,6 @@ def create(self, request, *args, **kwargs):
else:
file_urls = request.data["file_urls"].split(",")

serializer = SubmissionsSerializer(data=data)
serializer.is_valid(raise_exception=True)

if not group:
return Response(
{"message": "Group not found", "errorcode":
Expand All @@ -92,6 +90,26 @@ def create(self, request, *args, **kwargs):
status=status.HTTP_400_BAD_REQUEST
)

project = Project.objects.get(project_id=group.project_id.project_id)
# return Response(",".join(file_urls), status=status.HTTP_201_CREATED)
if project.file_structure is None or project.file_structure == "":
complete_message = {"message": "Submission successful"}
else:
violations = check_restrictions(file_urls, project.file_structure.split(","))

if not violations[0] and not violations[2]:
complete_message = {"success": 0}
data["output_simple_test"] = True
else:
violations.update({'success': 1})
data["output_simple_test"] = False
complete_message = violations

json_violations = json.dumps(violations)
data["feedback_simple_test"] = json_violations

serializer = SubmissionsSerializer(data=data)
serializer.is_valid(raise_exception=True)
submission = serializer.save()

# upload files
Expand All @@ -115,21 +133,10 @@ def create(self, request, *args, **kwargs):
"ERROR_FILE_UPLOAD"}, status=status.HTTP_400_BAD_REQUEST
)

project = Project.objects.get(project_id=group.project_id.project_id)
# return Response(",".join(file_urls), status=status.HTTP_201_CREATED)
if project.file_structure is None or project.file_structure == "":
complete_message = {"message": "Submission successful"}
else:
violations = check_restrictions(file_urls, project.file_structure.split(","))

if not violations[0] and not violations[2]:
complete_message = {"success": 0}
else:
violations.update({'success': 1})
complete_message = violations
complete_message["submission_id"] = serializer.data["submission_id"]

submission.eval()

return Response(complete_message, status=status.HTTP_201_CREATED)

def update(self, request, *args, **kwargs):
Expand Down
35 changes: 35 additions & 0 deletions frontend/app/[locale]/calendar/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import ProjectCalendar from '../components/ProjectCalendar';
import initTranslations from "@app/i18n";
import NavBar from '@app/[locale]/components/NavBar';
import TranslationsProvider from "@app/[locale]/components/TranslationsProvider";
import {Box, Typography} from "@mui/material";



const CalendarPage: React.FC = async ({params: {locale}}: { params: { locale: any } }) => {
const {t, resources} = await initTranslations(locale, ['common'])

return (
<TranslationsProvider
resources={resources}
locale={locale}
namespaces={["common"]}
>
<NavBar/>
<Box
padding={15}
>
<Typography
variant={"h3"}
align={"center"}
>
{t("project_calendar")}
</Typography>
<ProjectCalendar/>
</Box>
</TranslationsProvider>
);
};

export default CalendarPage;
43 changes: 43 additions & 0 deletions frontend/app/[locale]/calendar/useProjects.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { useState, useEffect } from 'react';
import { getCoursesForUser, getProjectsFromCourse } from '@lib/api';

interface Data {
id: number;
name: string;
deadline: string; // ISO date string
}

export const useProjects = () => {
const [projects, setProjects] = useState<Data[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);

useEffect(() => {
const fetchProjects = async () => {
try {
const courses = await getCoursesForUser();
const temp_projects: Data[] = [];
for (const course of courses) {
const course_projects = await getProjectsFromCourse(course.course_id);
for (const project of course_projects) {
temp_projects.push({
id: project.project_id,
name: project.name,
deadline: project.deadline,
});
}
}
console.log(temp_projects);
setProjects(temp_projects);
} catch (err) {
setError(err as Error);
} finally {
setLoading(false);
}
};

fetchProjects();
}, []);

return { projects, loading, error };
};
14 changes: 2 additions & 12 deletions frontend/app/[locale]/components/CourseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const CourseCard = ({params: {course}}: { params: { course: Course } }) => {
submission_nr: 0,
file: '',
timestamp: '',
output_test: '',
output_simple_test: false,
feedback_simple_test: {},
});
const [hover, setHover] = useState(false);

Expand Down Expand Up @@ -45,17 +46,6 @@ const CourseCard = ({params: {course}}: { params: { course: Course } }) => {














const headers = [
<React.Fragment key="name"><Person style={{ fontSize: '20px', verticalAlign: 'middle', marginBottom: '3px' }}/>{" " + t('name')}</React.Fragment>,
<React.Fragment key="deadline"><AccesAlarm style={{ fontSize: '20px', verticalAlign: 'middle', marginBottom: '3px' }}/>{" " +t('deadline')}</React.Fragment>,
Expand Down
9 changes: 9 additions & 0 deletions frontend/app/[locale]/components/CourseControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ViewListIcon from '@mui/icons-material/ViewList';
import ArchiveIcon from '@mui/icons-material/Archive';
import SupervisorAccountIcon from '@mui/icons-material/SupervisorAccount';
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
import CalendarMonthIcon from '@mui/icons-material/CalendarMonth';
import {useTranslation} from "react-i18next";
import {APIError, fetchUserData, UserData} from "@lib/api";

Expand Down Expand Up @@ -124,6 +125,14 @@ const CourseControls = ({selectedYear, onYearChange}) => {
>
{t("all_courses")}
</Button>
<Button
variant="contained"
color="secondary"
startIcon={<CalendarMonthIcon/>}
href={'/calendar'}
>
{t("deadlines")}
</Button>
<Button
variant="contained"
color="secondary"
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/[locale]/components/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ const ListView: NextPage<ListViewProps> = ({
setGroupSize((await getProject(data.project_id)).group_size);
return [data.group_id, data.user, data.group_nr, l.join(', ')];
},
'submissions': (data) => [data.submission_id, data.group_id, convertDate(t,data.timestamp), data.output_test !== undefined],
'submissions_group': (data) => [data.submission_id, data.group_id, convertDate(t,data.timestamp), data.output_test !== undefined],
'submissions': (data) => [data.submission_id, data.group_id, convertDate(t, data.timestamp), data.output_simple_test],
'submissions_group': (data) => [data.submission_id, data.group_id, convertDate(t, data.timestamp), data.output_simple_test],
'archived_courses': (data) => [data.course_id, data.name, data.description, data.open_course],
};

Expand Down
Loading

0 comments on commit 7ee0059

Please sign in to comment.