diff options
-rw-r--r-- | online_test/settings.py | 4 | ||||
-rw-r--r-- | yaksh/forms.py | 16 | ||||
-rw-r--r-- | yaksh/models.py | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/add_lesson.html | 9 |
4 files changed, 17 insertions, 14 deletions
diff --git a/online_test/settings.py b/online_test/settings.py index 3b89c28..11ab0ef 100644 --- a/online_test/settings.py +++ b/online_test/settings.py @@ -160,6 +160,10 @@ PRODUCTION_URL = 'your_project_url' # If this variable is kept <True> in production, email will not be verified. IS_DEVELOPMENT = True +# Video File upload size +MAX_UPLOAD_SIZE = 52428800 + + DEFAULT_FROM_EMAIL = EMAIL_HOST_USER TEMPLATES = [ diff --git a/yaksh/forms.py b/yaksh/forms.py index cc5daaf..c179081 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -9,6 +9,7 @@ from django.contrib.auth import authenticate from django.contrib.auth.models import User from django.conf import settings from django.utils import timezone +from django.template.defaultfilters import filesizeformat from textwrap import dedent try: from string import letters @@ -530,9 +531,6 @@ class LessonForm(forms.ModelForm): """), } ) - self.fields['video_file'].widget.attrs.update( - {'class': "custom-file-input"} - ) class Meta: model = Lesson @@ -548,6 +546,12 @@ class LessonForm(forms.ModelForm): "Please upload video files in {0} format".format( ", ".join(actual_extension)) ) + if file.size > settings.MAX_UPLOAD_SIZE: + raise forms.ValidationError( + f"Video file size must be less than "\ + f"{filesizeformat(settings.MAX_UPLOAD_SIZE)}. " + f"Current size is {filesizeformat(file.size)}" + ) return file def clean_video_path(self): @@ -557,16 +561,16 @@ class LessonForm(forms.ModelForm): value = literal_eval(path) if not isinstance(value, dict): raise forms.ValidationError( - "Value must be dictionary as shown in sample" + "Value must be dictionary e.g {'youtube': 'video-id'}" ) else: if len(value) > 1: raise forms.ValidationError( - "Only one of the video name should be entered" + "Only one type of video path is allowed" ) except ValueError: raise forms.ValidationError( - "Value must be dictionary as shown in sample" + "Value must be dictionary e.g {'youtube': 'video-id'}" ) return path diff --git a/yaksh/models.py b/yaksh/models.py index 6a6fe12..7757951 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -289,7 +289,7 @@ class Lesson(models.Model): # A video file video_file = models.FileField( - upload_to=get_file_dir, default=None, + upload_to=get_file_dir, max_length=255, default=None, null=True, blank=True, help_text="Please upload video files in mp4, ogv, webm format" ) diff --git a/yaksh/templates/yaksh/add_lesson.html b/yaksh/templates/yaksh/add_lesson.html index 8d889f3..329a8e0 100644 --- a/yaksh/templates/yaksh/add_lesson.html +++ b/yaksh/templates/yaksh/add_lesson.html @@ -92,13 +92,8 @@ <span class="badge badge-info"> {{lesson_form.video_file.help_text}} </span> - <div class="input-group mb-3"> - <div class="custom-file"> - {{lesson_form.video_file}} - <label class="custom-file-label" for="id_video_file"> - Choose file - </label> - </div> + <div class="col-md-4"> + {{lesson_form.video_file}} </div> <br> Lesson Files: |