diff options
author | Akshen | 2019-06-03 11:49:07 +0530 |
---|---|---|
committer | GitHub | 2019-06-03 11:49:07 +0530 |
commit | 242b5f0f208839a2d25b55d11bf73f647d9f5201 (patch) | |
tree | 11ebe0fe791e863d9dbc96701d448d1184b02cd9 /fossee_manim/models.py | |
parent | d6e8d4397a0ff3ea610c253e2648df257587f2bf (diff) | |
parent | cfd45b327a621a6a118954f4b18f5f020720cd10 (diff) | |
download | FOSSEE_animations-242b5f0f208839a2d25b55d11bf73f647d9f5201.tar.gz FOSSEE_animations-242b5f0f208839a2d25b55d11bf73f647d9f5201.tar.bz2 FOSSEE_animations-242b5f0f208839a2d25b55d11bf73f647d9f5201.zip |
Merge pull request #22 from Akshen/develop
Upload FileValidator added
Diffstat (limited to 'fossee_manim/models.py')
-rw-r--r-- | fossee_manim/models.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/fossee_manim/models.py b/fossee_manim/models.py index 7dbfe29..e2ff72c 100644 --- a/fossee_manim/models.py +++ b/fossee_manim/models.py @@ -108,6 +108,14 @@ def attachments(instance, filename): instance.animation.title, str(instance.animation.id), filename) +def validate_file_extension(value): + import os + from django.core.exceptions import ValidationError + ext = os.path.splitext(value.name)[1] # [0] returns path+filename + valid_extensions = ['.mp4'] + if not ext.lower() in valid_extensions: + raise ValidationError(u'Unsupported file extension.') + class Profile(models.Model): """Profile for users(instructors and coordinators)""" @@ -196,7 +204,7 @@ class AnimationStats(models.Model): like = models.PositiveIntegerField(default=0) dislike = models.PositiveIntegerField(default=0) thumbnail = models.ImageField(null=True, blank=True, upload_to=attachments) - video_path = models.FileField(null=True, blank=True, upload_to=attachments) + video_path = models.FileField(null=True, blank=True, upload_to=attachments, validators=[validate_file_extension]) def _create_thumbnail(self): video_path = self.video_path.path |