Skip to content

Commit

Permalink
Make it impossible to use invalid languages
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGrace2282 committed Nov 14, 2024
1 parent 9218317 commit 0dd6d52
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tin/apps/assignments/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, course, *args, **kwargs):
self.fields["description"].widget.attrs.update({"id": "description"})

# don't allow using deprecated versions of languages
self.fields["language_details"].queryset = Language.objects.filter(is_deprecated=False)
self.fields["language_details"].queryset = Language.active.all()

# Prevent changing the language of an assignment after it has been created
instance = getattr(self, "instance", None)
Expand Down
8 changes: 8 additions & 0 deletions tin/apps/assignments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,11 @@ def run(self, assignment: Assignment):
assignment.save()


class ActiveLanguageManager(models.Manager):
def get_queryset(self) -> models.QuerySet:
return super().get_queryset().filter(is_deprecated=False).exclude(path="/dev/null")


class Language(models.Model):
"""Which version of a language is used for an assignment.
Expand All @@ -707,6 +712,9 @@ class Language(models.Model):
help_text="The version of the executable. 0 if executable is /dev/null."
)

objects = models.Manager()
active = ActiveLanguageManager()

class Meta:
ordering = ["-version"]

Expand Down
5 changes: 1 addition & 4 deletions tin/apps/venvs/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
class VenvForm(forms.ModelForm):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.fields["language"].queryset = Language.objects.filter(
language="P",
is_deprecated=False,
)
self.fields["language"].queryset = Language.active.filter(language="P")

class Meta:
model = Venv
Expand Down

0 comments on commit 0dd6d52

Please sign in to comment.