From c6b41c861972a0a6953fbb2c4878fd4145667a47 Mon Sep 17 00:00:00 2001 From: janmax <mail-github@jmx.io> Date: Fri, 10 Nov 2017 23:11:53 +0100 Subject: [PATCH] Removed slug fields from models --- backend/core/migrations/0001_initial.py | 4 --- backend/core/models.py | 35 +++---------------------- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/backend/core/migrations/0001_initial.py b/backend/core/migrations/0001_initial.py index 39b10c6d..7fd6cdad 100644 --- a/backend/core/migrations/0001_initial.py +++ b/backend/core/migrations/0001_initial.py @@ -56,7 +56,6 @@ class Migration(migrations.Migration): ('score', models.PositiveIntegerField(default=0)), ('created', models.DateTimeField(auto_now_add=True)), ('modified', models.DateTimeField(auto_now=True)), - ('slug', models.SlugField(default=core.models.random_slug, editable=False, unique=True)), ('status', models.IntegerField(choices=[(0, 'editable'), (1, 'request reassignment'), (2, 'request review'), (3, 'accepted')], default=0)), ('origin', models.IntegerField(choices=[(0, 'was empty'), (1, 'passed unittests'), (2, 'did not compile'), (3, 'could not link'), (4, 'created by a human. yak!')], default=4)), ], @@ -77,7 +76,6 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('has_logged_in', models.BooleanField(default=False)), - ('matrikel_no', models.CharField(default=core.models.random_matrikel_no, max_length=8, unique=True)), ('exam', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='students', to='core.ExamType')), ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='student', to=settings.AUTH_USER_MODEL)), ], @@ -92,7 +90,6 @@ class Migration(migrations.Migration): ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('seen_by_student', models.BooleanField(default=False)), ('text', models.TextField(blank=True)), - ('slug', models.SlugField(default=core.models.random_slug, editable=False, unique=True)), ('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='submissions', to='core.Student')), ], options={ @@ -109,7 +106,6 @@ class Migration(migrations.Migration): ('full_score', models.PositiveIntegerField(default=0)), ('description', models.TextField()), ('solution', models.TextField()), - ('slug', models.SlugField(default=core.models.random_slug, editable=False, unique=True)), ], options={ 'verbose_name': 'SubmissionType', diff --git a/backend/core/models.py b/backend/core/models.py index abfd54d6..1d1b23b1 100644 --- a/backend/core/models.py +++ b/backend/core/models.py @@ -19,17 +19,6 @@ from django.db.models import (BooleanField, Case, Count, F, IntegerField, Q, from django.db.models.functions import Coalesce -def random_slug(slug_length: int = 16) -> str: - """Used for all the slug fields in the application instead of relying on - the primary keys. They are not cryptographically secure since random is - used. - - Returns: - str: a random string of lowercase ACSII letter - """ - return ''.join(sample(ascii_lowercase, slug_length)) - - def random_matrikel_no() -> str: """Use as a default value for student's matriculation number. @@ -100,8 +89,6 @@ class SubmissionType(models.Model): name : CharField The original title of the exam. This is wildly used as an identifier by the preprocessing scripts. - slug : SlugField - unique TODO: is this needed? solution : TextField A sample solution or a correction guideline """ @@ -109,8 +96,6 @@ class SubmissionType(models.Model): full_score = models.PositiveIntegerField(default=0) description = models.TextField() solution = models.TextField() - slug = models.SlugField( - editable=False, unique=True, default=random_slug) def __str__(self) -> str: return self.name @@ -221,10 +206,10 @@ class Student(models.Model): s.type: s.feedback.score if hasattr(s, 'feedback') else 0 for s in self.submissions.all() }) - else: - return OrderedDict({ - t.name: 0 for t in SubmissionType.objects.all() - }) + + return OrderedDict({ + t.name: 0 for t in SubmissionType.objects.all() + }) @classmethod def get_overall_score_annotated_submission_list(cls): @@ -313,8 +298,6 @@ class Submission(models.Model): ---------- seen_by_student : BooleanField True if the student saw his accepted feedback. - slug : SlugField - Slug for identification in domains student : OneToOneField The student how cause all of this text : TextField @@ -324,10 +307,6 @@ class Submission(models.Model): """ seen_by_student = models.BooleanField(default=False) text = models.TextField(blank=True) - slug = models.SlugField( - editable=False, - unique=True, - default=random_slug) type = models.ForeignKey( SubmissionType, on_delete=models.PROTECT, @@ -429,8 +408,6 @@ class Feedback(models.Model): score : PositiveIntegerField A score that has been assigned to he submission. Is final if it was accepted. - slug : SlugField - The slug for identification in urls STATUS : The status determines Description status : PositiveIntegerField @@ -449,10 +426,6 @@ class Feedback(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) - slug = models.SlugField( - editable=False, - unique=True, - default=random_slug) of_submission = models.OneToOneField( Submission, on_delete=models.CASCADE, -- GitLab