diff --git a/amadeus/static/js/resources.js b/amadeus/static/js/resources.js index f32f4ef..36ed694 100644 --- a/amadeus/static/js/resources.js +++ b/amadeus/static/js/resources.js @@ -135,14 +135,7 @@ function FileSelectHandler(e) { parent = $(e.target.offsetParent), max_size = parseInt($(e.target).data("max_size")) * 1024 * 1024, submit_btn = $(e.target).closest("form").find("input[type='submit']"), - mimeTypes = ['image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', - 'application/vnd.openxmlformats-officedocument.presentationml.presentation', - 'application/vnd.ms-excel','text/html','application/msword','application/vnd.oasis.opendocument.presentation', - 'application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.text', - 'application/pdf', 'application/vnd.ms-powerpoint']; + mimeTypes = $(e.target).data('mimetypes'); $(".client-file-errors").hide(); $(".size").hide(); @@ -150,6 +143,9 @@ function FileSelectHandler(e) { $(submit_btn).prop('disable', false); $(submit_btn).prop('disabled', false); + console.log($(e.target).data('mimetypes')); + console.log(mimeTypes); + // process all File objects for (var i = 0, f; f = files[i]; i++) { diff --git a/file_link/models.py b/file_link/models.py index 5652310..ec2b89c 100644 --- a/file_link/models.py +++ b/file_link/models.py @@ -6,19 +6,19 @@ from django.core.urlresolvers import reverse_lazy from topics.models import Resource -def validate_file_extension(value): - valid_formats = [ - 'image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', - 'application/vnd.openxmlformats-officedocument.presentationml.presentation', - 'application/vnd.ms-excel','text/html','application/msword','application/vnd.oasis.opendocument.presentation', - 'application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.text', - 'application/pdf', - 'application/vnd.ms-powerpoint' - ] +valid_formats = [ + 'image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', + 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + 'application/vnd.ms-excel','text/html','application/msword','application/vnd.oasis.opendocument.presentation', + 'application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.text', + 'application/pdf', + 'application/vnd.ms-powerpoint' +] +def validate_file_extension(value): if hasattr(value.file, 'content_type'): if not value.file.content_type in valid_formats: raise ValidationError(_('Please select a valid file. The uploaded file must have one of the following extensions: .doc, .docx, .html, .jpg, .odp, .ods, .odt, .pdf, .png, .ppt, .pptx, .xlx e .xlsx')) diff --git a/file_link/templates/file_links/_form.html b/file_link/templates/file_links/_form.html index 5fa2ed8..ddbf584 100644 --- a/file_link/templates/file_links/_form.html +++ b/file_link/templates/file_links/_form.html @@ -27,7 +27,7 @@
- {% render_field form.file_content class='file-selector' data-max_size="10" %} + {% render_field form.file_content class='file-selector' data-max_size="10" data-mimetypes=mimeTypes %}
diff --git a/file_link/views.py b/file_link/views.py index 3aadecf..b3bf464 100644 --- a/file_link/views.py +++ b/file_link/views.py @@ -16,7 +16,7 @@ from topics.models import Topic from pendencies.forms import PendenciesForm from .forms import FileLinkForm -from .models import FileLink +from .models import FileLink, valid_formats import datetime @@ -198,6 +198,7 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): context['topic'] = topic context['subject'] = topic.subject + context['mimeTypes'] = valid_formats return context @@ -312,6 +313,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): context['topic'] = topic context['subject'] = topic.subject + context['mimeTypes'] = valid_formats return context diff --git a/pdf_file/models.py b/pdf_file/models.py index 38d502f..e1078d8 100644 --- a/pdf_file/models.py +++ b/pdf_file/models.py @@ -6,11 +6,11 @@ from django.core.urlresolvers import reverse_lazy from topics.models import Resource # Create your models here. +valid_formats = [ + 'application/pdf' +] + def validate_file_extension(value): - valid_formats = [ - 'application/pdf' - ] - if hasattr(value.file, 'content_type'): if not value.file.content_type in valid_formats: raise ValidationError(_('File not supported, use PDF format instead.')) diff --git a/pdf_file/templates/pdf_file/_form.html b/pdf_file/templates/pdf_file/_form.html index 2cce843..e227513 100644 --- a/pdf_file/templates/pdf_file/_form.html +++ b/pdf_file/templates/pdf_file/_form.html @@ -25,8 +25,9 @@
{% endif %}
-
- {% render_field form.file class='file-selector' %} + +
+ {% render_field form.file class='file-selector' data-max_size="10" data-mimetypes=mimeTypes %}
@@ -51,18 +52,29 @@ {{ form.file.help_text }} - {% if form.file.errors %} - - {% endif %} +
+ + {% if form.file.errors %} + + {% endif %} + + {% trans 'Common resources settings' %} diff --git a/pdf_file/views.py b/pdf_file/views.py index e1b90a9..35ff3bc 100644 --- a/pdf_file/views.py +++ b/pdf_file/views.py @@ -16,7 +16,7 @@ from django.http import HttpResponse, Http404 from log.mixins import LogMixin from topics.models import Topic, Resource -from .models import PDFFile +from .models import PDFFile, valid_formats from pendencies.forms import PendenciesForm from chat.models import Conversation, TalkMessages, ChatVisualizations @@ -204,6 +204,7 @@ class PDFFileCreateView(LoginRequiredMixin, LogMixin , generic.CreateView): context['topic'] = topic context['subject'] = topic.subject + context['mimeTypes'] = valid_formats return context @@ -319,6 +320,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): context['topic'] = topic context['subject'] = topic.subject + context['mimeTypes'] = valid_formats return context -- libgit2 0.21.2