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

Model update #55

Merged
merged 14 commits into from
Mar 7, 2024
32 changes: 20 additions & 12 deletions backend/api/fixtures/checks.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
- model: api.checks
- model: api.structurecheck
pk: 1
fields:
dockerfile: 'path/to/Dockerfile'
allowed_file_extensions:
- 1
- 2
forbidden_file_extensions:
- 3
- 4
name: '.'
project: 123456
obligated_extensions:
- 3
- 4
blocked_extensions:
- 1
- 2

- model: api.extracheck
pk: 1
fields:
project: 123456
run_script: 'scripts/run.sh'

- model: api.fileextension
pk: 1
fields:
extension: 'py'
extension: 'class'
- model: api.fileextension
pk: 2
fields:
extension: 'js'
extension: 'png'
- model: api.fileextension
pk: 3
fields:
extension: 'html'
extension: 'java'
- model: api.fileextension
pk: 4
fields:
extension: 'php'
extension: 'py'
3 changes: 2 additions & 1 deletion backend/api/fixtures/projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
archived: false
start_date: 2024-02-26 00:00:00+00:00
deadline: 2024-02-27 00:00:00+00:00
checks: 1
group_size: 3
max_score: 20
course: 2
16 changes: 15 additions & 1 deletion backend/api/fixtures/submissions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
group: 1
submission_number: 1
submission_time: '2021-01-01T00:00:00Z'
structure_checks_passed: True
- model: api.submission
pk: 2
fields:
group: 1
submission_number: 2
submission_time: '2021-01-02T00:00:00Z'

structure_checks_passed: True

- model: api.submissionfile
pk: 1
Expand All @@ -22,3 +23,16 @@
fields:
submission: 2
file: 'submissions/1/2/1.txt'

- model: api.extrachecksresult
pk: 1
fields:
submission: 1
extra_check: 1
passed: False
- model: api.extrachecksresult
pk: 2
fields:
submission: 2
extra_check: 1
passed: True
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.0.2 on 2024-03-05 10:22

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='project',
name='group_size',
field=models.PositiveSmallIntegerField(default=1),
),
migrations.AddField(
model_name='project',
name='max_score',
field=models.PositiveSmallIntegerField(default=100),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 5.0.2 on 2024-03-06 09:08

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


class Migration(migrations.Migration):

dependencies = [
('api', '0002_project_group_size_project_max_score'),
]

operations = [
migrations.RemoveField(
model_name='project',
name='checks',
),
migrations.CreateModel(
name='ExtraCheck',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('run_script', models.FileField(upload_to='')),
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='extra_checks', to='api.project')),
],
),
migrations.CreateModel(
name='StructureCheck',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('blocked_extensions', models.ManyToManyField(blank=True, related_name='blocked_extensions', to='api.fileextension')),
('obligated_extensions', models.ManyToManyField(blank=True, related_name='obligated_extensions', to='api.fileextension')),
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='structure_checks', to='api.project')),
],
),
migrations.DeleteModel(
name='Checks',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.0.2 on 2024-03-06 11:53

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


class Migration(migrations.Migration):

dependencies = [
('api', '0003_remove_project_checks_extracheck_structurecheck_and_more'),
]

operations = [
migrations.AddField(
model_name='submission',
name='structure_checks_passed',
field=models.BooleanField(default=False),
),
migrations.CreateModel(
name='ExtraChecksResult',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('passed', models.BooleanField(default=False)),
('extra_check', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='results', to='api.extracheck')),
('submission', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='extra_checks_results', to='api.submission')),
],
),
]
18 changes: 18 additions & 0 deletions backend/api/migrations/0005_alter_project_max_score.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.2 on 2024-03-06 14:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0004_submission_structure_checks_passed_extrachecksresult'),
]

operations = [
migrations.AlterField(
model_name='project',
name='max_score',
field=models.PositiveSmallIntegerField(default=20),
),
]
62 changes: 46 additions & 16 deletions backend/api/models/checks.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,60 @@
from django.db import models
from api.models.project import Project
from api.models.extension import FileExtension


class FileExtension(models.Model):
"""Model that represents a file extension."""
class StructureCheck(models.Model):
"""Model that represents a structure check for a project.
This means that the structure of a submission is checked.
These checks are obligated to pass."""

# ID check should be generated automatically
# ID should be generated automatically

extension = models.CharField(max_length=10, unique=True)
# Name of the structure check
name = models.CharField(
max_length=100,
blank=False,
null=False
)

def __str__(self) -> str:
return str(self.extension)
# Link to the project
project = models.ForeignKey(
Project,
on_delete=models.CASCADE,
related_name="structure_checks"
)

# Obligated extensions
obligated_extensions = models.ManyToManyField(
FileExtension,
related_name="obligated_extensions",
blank=True
)

# Blocked extensions
blocked_extensions = models.ManyToManyField(
FileExtension,
related_name="blocked_extensions",
blank=True
)

class Checks(models.Model):
"""Model that represents checks for a project."""

# ID check should be generated automatically
class ExtraCheck(models.Model):
"""Model that represents an extra check for a project.
These checks are not obligated to pass."""

dockerfile = models.FileField(blank=True, null=True)
# ID should be generated automatically

# Link to the file extensions that are allowed
allowed_file_extensions = models.ManyToManyField(
FileExtension, related_name="checks_allowed", blank=True
# Link to the project
project = models.ForeignKey(
Project,
on_delete=models.CASCADE,
related_name="extra_checks"
)

# Link to the file extensions that are forbidden
forbidden_file_extensions = models.ManyToManyField(
FileExtension, related_name="checks_forbidden", blank=True
# Run script
# TODO set upload_to
run_script = models.FileField(
blank=False,
null=False
)
12 changes: 12 additions & 0 deletions backend/api/models/extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.db import models


class FileExtension(models.Model):
"""Model that represents a file extension."""

# ID should be generated automatically

extension = models.CharField(
max_length=10,
unique=True
)
30 changes: 19 additions & 11 deletions backend/api/models/project.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import timedelta, datetime
from datetime import datetime
from django.db import models
from django.utils import timezone
from api.models.checks import Checks
from api.models.course import Course


Expand All @@ -28,13 +27,18 @@ class Project(models.Model):

deadline = models.DateTimeField(blank=False, null=False)

# Check entity that is linked to the project
checks = models.ForeignKey(
Checks,
# If the checks are deleted, the project should remain
on_delete=models.SET_NULL,
blank=True,
null=True,
# Max score that can be achieved in the project
max_score = models.PositiveSmallIntegerField(
blank=False,
null=False,
default=20
)

# Size of the groups than can be formed
group_size = models.PositiveSmallIntegerField(
blank=False,
null=False,
default=1
)

# Course that the project belongs to
Expand All @@ -48,18 +52,22 @@ class Project(models.Model):
)

def deadline_approaching_in(self, days=7):
"""Returns True if the deadline is approaching in the next days."""
now = timezone.now()
approaching_date = now + timezone.timedelta(days=days)
return now <= self.deadline <= approaching_date

def deadline_passed(self):
"""Returns True if the deadline has passed."""
now = timezone.now()
return now > self.deadline

def toggle_visible(self):
self.visible = not (self.visible)
"""Toggles the visibility of the project."""
self.visible = not self.visible
self.save()

def toggle_archived(self):
self.archived = not (self.archived)
"""Toggles the archived status of the project."""
self.archived = not self.archived
self.save()
Loading
Loading