Skip to content

Commit

Permalink
Change forms, models, settings and template
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
adityacp committed Sep 25, 2020
1 parent 8444e93 commit 0c5f2af
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
4 changes: 4 additions & 0 deletions online_test/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@
# 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 = [
Expand Down
16 changes: 10 additions & 6 deletions yaksh/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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
Expand Down Expand Up @@ -530,9 +531,6 @@ def __init__(self, *args, **kwargs):
"""),
}
)
self.fields['video_file'].widget.attrs.update(
{'class': "custom-file-input"}
)

class Meta:
model = Lesson
Expand All @@ -548,6 +546,12 @@ def clean_video_file(self):
"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):
Expand All @@ -557,16 +561,16 @@ def clean_video_path(self):
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

Expand Down
2 changes: 1 addition & 1 deletion yaksh/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
9 changes: 2 additions & 7 deletions yaksh/templates/yaksh/add_lesson.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,8 @@ <h3>Description Preview</h3>
<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:
Expand Down

0 comments on commit 0c5f2af

Please sign in to comment.