Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Fix #253
Browse files Browse the repository at this point in the history
  • Loading branch information
AronBuzogany committed Apr 26, 2024
1 parent 4a35f4f commit 18eade6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
18 changes: 16 additions & 2 deletions backend/project/endpoints/projects/project_assignment_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
from urllib.parse import urljoin

from flask import send_from_directory
from flask import send_from_directory, request

from flask_restful import Resource

Expand All @@ -28,8 +28,22 @@ def get(self, project_id):
Get the assignment files of a project
"""

language = request.args.get('lang')
directory_path = os.path.abspath(os.path.join(UPLOAD_FOLDER, str(project_id)))
assignment_file = os.path.join(directory_path, ASSIGNMENT_FILE_NAME)
file_name = ASSIGNMENT_FILE_NAME
if language:
potential_file = f"assignment_{language}.md"
if os.path.isfile(os.path.join(directory_path, potential_file)):
file_name = potential_file
else:
# Find any .md file that starts with "assignment"
for filename in os.listdir(directory_path):
if filename.startswith("assignment") and filename.endswith(".md"):
file_name = filename
break


assignment_file = os.path.join(directory_path, file_name)

if not os.path.isfile(assignment_file):
# no file is found so return 404
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/pages/project/projectView/ProjectView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import SubmissionCard from "./SubmissionCard";
import { Course } from "../../../types/course";
import { Title } from "../../../components/Header/Title";
import { authenticatedFetch } from "../../../utils/authenticated-fetch";
import i18next from "i18next";

const API_URL = import.meta.env.VITE_API_HOST;

Expand All @@ -40,7 +41,9 @@ export default function ProjectView() {
response.json().then((data) => {
const projectData = data["data"];
setProjectData(projectData);
authenticatedFetch(`${API_URL}/courses/${projectData.course_id}`).then((response) => {
authenticatedFetch(
`${API_URL}/courses/${projectData.course_id}`
).then((response) => {
if (response.ok) {
response.json().then((data) => {
setCourseData(data["data"]);
Expand All @@ -51,7 +54,9 @@ export default function ProjectView() {
}
});

authenticatedFetch(`${API_URL}/projects/${projectId}/assignment`).then((response) => {
authenticatedFetch(
`${API_URL}/projects/${projectId}/assignment?lang=${i18next.language}`
).then((response) => {
if (response.ok) {
response.text().then((data) => setAssignmentRawText(data));
}
Expand All @@ -72,7 +77,7 @@ export default function ProjectView() {
<Container>
{projectData && (
<Card>
<Title title={projectData.title}/>
<Title title={projectData.title} />
<CardHeader
color="secondary"
title={projectData.title}
Expand Down

0 comments on commit 18eade6

Please sign in to comment.