Skip to content

Commit

Permalink
Merge pull request #189 from SELab-2/simple_test_feedback
Browse files Browse the repository at this point in the history
Feedback tests in frontend
  • Loading branch information
gilles-arnout committed May 23, 2024
2 parents af66343 + 97f3281 commit b68c5ec
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 44 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 @@ -31,6 +31,8 @@ class Submissions(models.Model):
file_urls = models.TextField(null=True)
timestamp = models.DateTimeField(auto_now_add=True, blank=True)
draft = models.BooleanField(default=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 @@ -58,4 +60,6 @@ class Meta:
"submission_nr",
"group_id",
"draft",
"output_simple_test",
"feedback_simple_test",
]
38 changes: 22 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 @@ -75,9 +76,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 @@ -101,6 +99,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)
serializer.save()

# upload files
Expand All @@ -123,19 +141,7 @@ 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"]
return Response(complete_message, status=status.HTTP_201_CREATED)

def update(self, request, *args, **kwargs):
Expand Down
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
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
44 changes: 39 additions & 5 deletions frontend/app/[locale]/components/SubmissionDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ const SubmissionDetailsPage: React.FC<SubmissionDetailsPageProps> = ({ locale, s

return (
<ThemeProvider theme={baseTheme}>
<Grid container justifyContent="center" alignItems="flex-start" style={{ width: '100%', padding: '20px' }}>
<Grid item xs={12} style={{paddingBottom: '20px'}}>
<Grid container direction={'column'} justifyContent="flex-start" alignItems="stretch" style={{ padding: '20px', width: '100%'}}>
<Grid item style={{paddingBottom: '20px', width: '100%'}}>
<ProjectReturnButton locale={locale} project_id={projectId} />
</Grid>
<Grid item xs={12}>
<Grid item>
<Card raised style={{ width: '100%' }}>
<CardContent>
<Typography variant="h4" style={{ fontWeight: 'bold', marginBottom: '20px' }}>
Expand All @@ -82,14 +82,14 @@ const SubmissionDetailsPage: React.FC<SubmissionDetailsPageProps> = ({ locale, s
{`${t("evaluation")} status`}
</Typography>
<div style={{ display: "flex", alignItems: "center", columnGap: "10px" }}>
{submission?.output_test !== "" ? (
{submission?.output_simple_test ? (
<CheckIcon color="success" style={{ fontSize: 40 }}/>
) : (
<CancelIcon color="error" style={{ fontSize: 40 }}/>
)}
<div>
<Typography variant="subtitle1" style={{ fontWeight: 'bold' }}>
{submission?.output_test !== "" ? t("accepted") : t("denied")}
{submission?.output_simple_test ? t("accepted") : t("denied")}
</Typography>
<Typography variant="caption">
{`(${t("timestamp")}: ${formatDate(submission?.timestamp)})`}
Expand All @@ -113,6 +113,40 @@ const SubmissionDetailsPage: React.FC<SubmissionDetailsPageProps> = ({ locale, s
</Button>
</Grid>
</Grid>
{
!submission?.output_simple_test ? (
<>
<Divider style={{ marginBottom: '20px', marginTop: '20px' }}/>

{submission?.feedback_simple_test["0"].length > 0 ? (
<>
<Typography variant="h6" style={{ fontWeight: 'bold', marginBottom: '10px' }}>
{t("feedback_simple_test_0")}
</Typography>
{submission?.feedback_simple_test["0"].map((feedback, index) => (
<Typography key={index} variant="body1" style={{ marginBottom: '10px' }}>
{feedback}
</Typography>
))}
</>
) : null}

{submission?.feedback_simple_test["2"].length > 0 ? (
<>
<Typography variant="h6" style={{ fontWeight: 'bold', marginBottom: '10px' }}>
{t("feedback_simple_test_2")}
</Typography>
{submission?.feedback_simple_test["2"].map((feedback, index) => (
<Typography key={index} variant="body1" style={{ marginBottom: '10px' }}>
{feedback}
</Typography>
))}
</>
) : null}
</>
) : null
}

</CardContent>
</Card>
</Grid>
Expand Down
4 changes: 3 additions & 1 deletion frontend/app/[locale]/components/SubmitDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ const SubmitDetailsPage: React.FC<SubmitDetailsPageProps> = ({
};

const handleSubmit = async (e) => {
setSubmitted(await uploadSubmissionFile(e, project_id));
const response = await uploadSubmissionFile(e, project_id);
setSubmitted(response);
window.location.href = `/submission/${response.submission_id}/`;
};

useEffect(() => {
Expand Down
10 changes: 6 additions & 4 deletions frontend/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ export type Submission = {
submission_nr: number;
file: string;
timestamp: string;
output_test: string;
output_simple_test: boolean;
feedback_simple_test: object;
}

export type UserData = {
Expand Down Expand Up @@ -681,13 +682,14 @@ export async function joinCourseUsingToken(course_id: number, token: string) {
type uploadResult = {
result: string;
errorcode: string | undefined;
submission_id: number;
}

export async function uploadSubmissionFile(event: any, project_id: string) : Promise<uploadResult>{
axios.defaults.headers.get['X-CSRFToken'] = getCookieValue('csrftoken');
axios.defaults.headers.post['X-CSRFToken'] = getCookieValue('csrftoken');
event.preventDefault();
console.log(event.target.fileList.files);

const formData = new FormData(event.target);
//filter files by key

Expand All @@ -710,13 +712,13 @@ export async function uploadSubmissionFile(event: any, project_id: string) : Pro
let groupres = await axios.get(backend_url + "/projects/" + project_id + "/get_group/", {withCredentials: true});
const group_id = groupres.data.group_id;
formDataObject.group_id = group_id;
await axios.post(backend_url + '/submissions/', formDataObject,
const response = await axios.post(backend_url + '/submissions/', formDataObject,
{ withCredentials: true,
headers: {
'Content-Type': 'multipart/form-data'
}
});
return {result: "ok", errorcode: undefined};
return {result: "ok", errorcode: undefined, submission_id: response.data.submission_id};
} catch (error) {
const apierror : APIError = new APIError();
apierror.message = "error posting form";
Expand Down
7 changes: 4 additions & 3 deletions frontend/locales/en/common.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"accepted": "accepted",
"accepted": "Accepted",
"description_of_your_course": "Description of your course",
"access": "Access",
"action_dialog": "This action cannot be undone.",
Expand Down Expand Up @@ -101,7 +101,6 @@
"visibility": "Visibility",
"year": "Year",
"archive_course": "Archive course",
"visibility": "Visibility",
"download_file": "Download",
"denied": "Denied",
"show_more": "Show more",
Expand Down Expand Up @@ -152,5 +151,7 @@
"teachers": "Teachers",
"courses_archive": "Courses archive",
"courses_all": "All courses",
"open": "Open"
"open": "Open",
"feedback_simple_test_0": "You forgot to upload the following files:",
"feedback_simple_test_2": "You uploaded the following files that were not required:"
}
4 changes: 3 additions & 1 deletion frontend/locales/nl/common.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"accepted": "aanvaard",
"accepted": "Aanvaard",
"description_of_your_course": "Beschrijving van je cursus",
"access": "Toegang",
"action_dialog": "Deze actie kan niet ongedaan worden gemaakt.",
Expand Down Expand Up @@ -149,6 +149,8 @@
"project_calendar": "Project kalender",
"edit_user_details": "Gebruiker bewerken",
"status_button_tooltip": "Verplicht, optioneel of verboden bestand",
"feedback_simple_test_0": "Je hebt de volgende bestanden niet ingeleverd:",
"feedback_simple_test_2": "Je hebt de volgende bestanden ingeleverd die niet nodig zijn:",
"no_deadline": "Geen deadline",
"all_submissions": "Alle indieningen",
"students": "Studenten",
Expand Down
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions scripts/opdracht_incorrect/tests/test.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dit bestand is verboden

0 comments on commit b68c5ec

Please sign in to comment.