diff options
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 71 |
1 files changed, 60 insertions, 11 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 84cad1e..9ba4afd 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1,3 +1,4 @@ +# Python Imports from __future__ import unicode_literals, division from datetime import datetime, timedelta import uuid @@ -8,14 +9,6 @@ from ruamel.yaml.scalarstring import PreservedScalarString from ruamel.yaml.comments import CommentedMap from random import sample from collections import Counter, defaultdict - -from django.db import models -from django.contrib.auth.models import User, Group, Permission -from django.core.exceptions import ValidationError -from django.contrib.contenttypes.models import ContentType -from taggit.managers import TaggableManager -from django.utils import timezone -from django.core.files import File import glob try: @@ -31,14 +24,29 @@ import zipfile import tempfile from textwrap import dedent from ast import literal_eval -from .file_utils import extract_files, delete_files + +# Django Imports +from django.db import models +from django.contrib.auth.models import User, Group, Permission +from django.core.exceptions import ValidationError +from django.contrib.contenttypes.models import ContentType +from taggit.managers import TaggableManager +from django.utils import timezone +from django.core.files import File +from django.contrib.contenttypes.fields import ( + GenericForeignKey, GenericRelation +) +from django.contrib.contenttypes.models import ContentType from django.template import Context, Template +from django.conf import settings +from django.forms.models import model_to_dict + +# Local Imports from yaksh.code_server import ( submit, get_result as get_result_from_code_server ) from yaksh.settings import SERVER_POOL_PORT, SERVER_HOST_NAME -from django.conf import settings -from django.forms.models import model_to_dict +from .file_utils import extract_files, delete_files from grades.models import GradingSystem languages = ( @@ -286,6 +294,11 @@ class Lesson(models.Model): help_text="Please upload video files in mp4, ogv, webm format" ) + video_path = models.CharField( + max_length=255, default=None, null=True, blank=True, + help_text="Youtube id, vimeo id, others" + ) + def __str__(self): return "{0}".format(self.name) @@ -1337,6 +1350,8 @@ class Question(models.Model): # Solution for the question. solution = models.TextField(blank=True) + content = GenericRelation("TableOfContents") + tc_code_types = { "python": [ ("standardtestcase", "Standard TestCase"), @@ -2730,6 +2745,40 @@ class Comment(ForumBase): self.post_field.title) +class TableOfContents(models.Model): + toc_types = ((1, "Topic"), (2, "Graded Quiz"), (3, "Exercise"), (4, "Poll")) + course = models.ForeignKey(Course, on_delete=models.CASCADE, + related_name='course') + lesson = models.ForeignKey(Lesson, on_delete=models.CASCADE, + related_name='contents') + time = models.CharField(max_length=100, default=0) + content = models.IntegerField(choices=toc_types) + content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) + object_id = models.PositiveIntegerField() + content_object = GenericForeignKey() + + class Meta: + verbose_name_plural = "Table Of Contents" + + def get_toc_text(self): + if self.content == 1: + content_name = Topic.objects.get(id=self.object_id).name + else: + content_name = Question.objects.get(id=self.object_id).summary + return content_name + + def __str__(self): + return f"TOC for {self.lesson.name} with {self.get_content_display()}" + + +class Topic(models.Model): + name = models.CharField(max_length=255) + content = GenericRelation(TableOfContents) + + def __str__(self): + return f"{self.name}" + + class MicroManager(models.Model): manager = models.ForeignKey(User, on_delete=models.CASCADE, related_name='micromanaging', null=True) |