From 41e9e16567d4f580b0068bd064aedb53bbab5c0f Mon Sep 17 00:00:00 2001 From: Akshen Date: Tue, 28 May 2019 18:22:53 +0530 Subject: Upload FileValidator added --- fossee_manim/forms.py | 2 +- fossee_manim/models.py | 10 +++++++++- fossee_manim/templates/fossee_manim/faqs.html | 8 ++++++++ fossee_manim/templates/fossee_manim/guidelines.html | 4 ++-- fossee_manim/templates/fossee_manim/honorarium.html | 8 ++++++++ fossee_manim/urls.py | 3 ++- fossee_manim/views.py | 3 +++ 7 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 fossee_manim/templates/fossee_manim/faqs.html create mode 100644 fossee_manim/templates/fossee_manim/honorarium.html (limited to 'fossee_manim') diff --git a/fossee_manim/forms.py b/fossee_manim/forms.py index 8edfb5c..3b9ca2e 100644 --- a/fossee_manim/forms.py +++ b/fossee_manim/forms.py @@ -280,7 +280,7 @@ class UploadAnimationForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(UploadAnimationForm, self).__init__(*args, **kwargs) - self.fields['video_path'].label = "Animation" + self.fields['video_path'].label = "Animation(.mp4 only)" class Meta: model = AnimationStats 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 diff --git a/fossee_manim/templates/fossee_manim/faqs.html b/fossee_manim/templates/fossee_manim/faqs.html new file mode 100644 index 0000000..72c3f44 --- /dev/null +++ b/fossee_manim/templates/fossee_manim/faqs.html @@ -0,0 +1,8 @@ +{% extends 'fossee_manim/base.html' %} + + {% block title %} + Animation Guidelines + {% endblock %} + +{% block content %} +{% endblock %} \ No newline at end of file diff --git a/fossee_manim/templates/fossee_manim/guidelines.html b/fossee_manim/templates/fossee_manim/guidelines.html index 2d034a2..1ab7eef 100644 --- a/fossee_manim/templates/fossee_manim/guidelines.html +++ b/fossee_manim/templates/fossee_manim/guidelines.html @@ -1,7 +1,7 @@ {% extends 'fossee_manim/base.html' %} {% block title %} - FOSSEE Animation + Animation Guidelines {% endblock %} {% block content %} @@ -93,7 +93,7 @@