Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project editor #319

Merged
merged 18 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 5.0.4 on 2024-04-15 19:09

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0015_checkresult_remove_extrachecksresult_error_message_and_more'),
]

operations = [
migrations.AddField(
model_name='course',
name='excerpt',
field=models.CharField(default='no excerpt provided', max_length=200),
preserve_default=False,
),
migrations.AlterField(
model_name='checkresult',
name='submission',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='results', to='api.submission'),
),
migrations.AlterField(
model_name='extracheckresult',
name='extra_check',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='extra_check', to='api.extracheck'),
),
migrations.AlterField(
model_name='structurecheckresult',
name='structure_check',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='structure_check', to='api.structurecheck'),
),
]
1 change: 1 addition & 0 deletions backend/api/migrations/0017_merge_20240416_1054.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Migration(migrations.Migration):

dependencies = [
('api', '0016_alter_checkresult_submission_and_more'),
('api', '0016_course_excerpt_alter_checkresult_submission_and_more'),
('api', '0016_remove_checkresult_is_valid_submission_is_valid_and_more'),
]

Expand Down
3 changes: 3 additions & 0 deletions backend/api/models/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Course(models.Model):
# Begin year of the academic year
academic_startyear = models.IntegerField(blank=False, null=False)

# The excerpt of the course
excerpt = models.CharField(max_length=200, blank=False, null=False)

# The description of the course
description = models.TextField(blank=True, null=True)

Expand Down
6 changes: 6 additions & 0 deletions backend/api/serializers/course_serializer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from nh3 import clean
from django.utils.translation import gettext
from rest_framework import serializers
from rest_framework.exceptions import ValidationError
Expand Down Expand Up @@ -37,6 +38,11 @@ class CourseSerializer(serializers.ModelSerializer):
read_only=True
)

def validate(self, attrs: dict) -> dict:
"""Extra custom validation for course serializer"""
attrs['description'] = clean(attrs['description'])
return attrs

class Meta:
model = Course
fields = "__all__"
Expand Down
3 changes: 3 additions & 0 deletions backend/api/serializers/project_serializer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from api.logic.check_folder_structure import parse_zip_file
from nh3 import clean
from api.models.checks import FileExtension
from api.models.course import Course
from api.models.group import Group
Expand Down Expand Up @@ -64,6 +65,8 @@ def validate(self, data):
if "deadline" in data and data["deadline"] < start_date:
raise ValidationError(gettext("project.errors.deadline_before_start_date"))

data['description'] = clean(data['description'])

return data

class Meta:
Expand Down
1 change: 1 addition & 0 deletions backend/api/tests/test_course.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ def test_create_course(self):
data={
"name": "Introduction to Computer Science",
"academic_startyear": 2022,
"excerpt": "Excerpt",
"description": "An introductory course on computer science.",
"faculty": faculty.id,
},
Expand Down
35 changes: 30 additions & 5 deletions backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ django-seed = "^0.3.1"
django-celery-results = "^2.5.1"
django-polymorphic = "^3.1.0"
django-rest-polymorphic = "^0.1.10"
nh3 = "^0.2.17"


[build-system]
Expand Down
1 change: 0 additions & 1 deletion backend/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ poetry install > /dev/null

echo "Migrating database..."
python manage.py migrate > /dev/null
python manage.py migrate django_celery_results > /dev/null

echo "Compiling translations..."
django-admin compilemessages > /dev/null
Expand Down
Loading
Loading