diff options
author | adityacp | 2020-09-25 10:33:47 +0530 |
---|---|---|
committer | adityacp | 2020-09-25 10:33:47 +0530 |
commit | 0c5f2afb084c0a4efd1715d53909ce2bb07b5883 (patch) | |
tree | f92603125924b8f9621b7e8ee6baf02d3f5b21b7 /yaksh | |
parent | 8444e93ac160f64d03525940f738ff5aa52cd20a (diff) | |
download | online_test-0c5f2afb084c0a4efd1715d53909ce2bb07b5883.tar.gz online_test-0c5f2afb084c0a4efd1715d53909ce2bb07b5883.tar.bz2 online_test-0c5f2afb084c0a4efd1715d53909ce2bb07b5883.zip |
Change forms, models, settings and template
- Add max_upload_size in settings for video file
- Change error messages in forms
- Set the video_file field max_length
- Fix add_lesson template for uploading video file
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/forms.py | 16 | ||||
-rw-r--r-- | yaksh/models.py | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/add_lesson.html | 9 |
3 files changed, 13 insertions, 14 deletions
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: |