Commit 6456e0bc8462422f766aadbc0716d1b32d49ac94
1 parent
3b4cfe1e
Exists in
master
and in
2 other branches
Adjusting file bugs in pdf link resource
Showing
7 changed files
with
53 additions
and
41 deletions
Show diff stats
amadeus/static/js/resources.js
... | ... | @@ -135,14 +135,7 @@ function FileSelectHandler(e) { |
135 | 135 | parent = $(e.target.offsetParent), |
136 | 136 | max_size = parseInt($(e.target).data("max_size")) * 1024 * 1024, |
137 | 137 | submit_btn = $(e.target).closest("form").find("input[type='submit']"), |
138 | - mimeTypes = ['image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png', | |
139 | - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', | |
140 | - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', | |
141 | - 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', | |
142 | - 'application/vnd.openxmlformats-officedocument.presentationml.presentation', | |
143 | - 'application/vnd.ms-excel','text/html','application/msword','application/vnd.oasis.opendocument.presentation', | |
144 | - 'application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.text', | |
145 | - 'application/pdf', 'application/vnd.ms-powerpoint']; | |
138 | + mimeTypes = $(e.target).data('mimetypes'); | |
146 | 139 | |
147 | 140 | $(".client-file-errors").hide(); |
148 | 141 | $(".size").hide(); |
... | ... | @@ -150,6 +143,9 @@ function FileSelectHandler(e) { |
150 | 143 | $(submit_btn).prop('disable', false); |
151 | 144 | $(submit_btn).prop('disabled', false); |
152 | 145 | |
146 | + console.log($(e.target).data('mimetypes')); | |
147 | + console.log(mimeTypes); | |
148 | + | |
153 | 149 | // process all File objects |
154 | 150 | for (var i = 0, f; f = files[i]; i++) { |
155 | 151 | ... | ... |
file_link/models.py
... | ... | @@ -6,19 +6,19 @@ from django.core.urlresolvers import reverse_lazy |
6 | 6 | |
7 | 7 | from topics.models import Resource |
8 | 8 | |
9 | -def validate_file_extension(value): | |
10 | - valid_formats = [ | |
11 | - 'image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png', | |
12 | - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', | |
13 | - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', | |
14 | - 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', | |
15 | - 'application/vnd.openxmlformats-officedocument.presentationml.presentation', | |
16 | - 'application/vnd.ms-excel','text/html','application/msword','application/vnd.oasis.opendocument.presentation', | |
17 | - 'application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.text', | |
18 | - 'application/pdf', | |
19 | - 'application/vnd.ms-powerpoint' | |
20 | - ] | |
9 | +valid_formats = [ | |
10 | + 'image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png', | |
11 | + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', | |
12 | + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', | |
13 | + 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', | |
14 | + 'application/vnd.openxmlformats-officedocument.presentationml.presentation', | |
15 | + 'application/vnd.ms-excel','text/html','application/msword','application/vnd.oasis.opendocument.presentation', | |
16 | + 'application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.text', | |
17 | + 'application/pdf', | |
18 | + 'application/vnd.ms-powerpoint' | |
19 | +] | |
21 | 20 | |
21 | +def validate_file_extension(value): | |
22 | 22 | if hasattr(value.file, 'content_type'): |
23 | 23 | if not value.file.content_type in valid_formats: |
24 | 24 | 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')) | ... | ... |
file_link/templates/file_links/_form.html
... | ... | @@ -27,7 +27,7 @@ |
27 | 27 | </div> |
28 | 28 | |
29 | 29 | <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> |
30 | - {% render_field form.file_content class='file-selector' data-max_size="10" %} | |
30 | + {% render_field form.file_content class='file-selector' data-max_size="10" data-mimetypes=mimeTypes %} | |
31 | 31 | |
32 | 32 | <div class="input-group common-file-input"> |
33 | 33 | <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}"> | ... | ... |
file_link/views.py
... | ... | @@ -16,7 +16,7 @@ from topics.models import Topic |
16 | 16 | from pendencies.forms import PendenciesForm |
17 | 17 | |
18 | 18 | from .forms import FileLinkForm |
19 | -from .models import FileLink | |
19 | +from .models import FileLink, valid_formats | |
20 | 20 | |
21 | 21 | |
22 | 22 | import datetime |
... | ... | @@ -198,6 +198,7 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
198 | 198 | |
199 | 199 | context['topic'] = topic |
200 | 200 | context['subject'] = topic.subject |
201 | + context['mimeTypes'] = valid_formats | |
201 | 202 | |
202 | 203 | return context |
203 | 204 | |
... | ... | @@ -312,6 +313,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): |
312 | 313 | |
313 | 314 | context['topic'] = topic |
314 | 315 | context['subject'] = topic.subject |
316 | + context['mimeTypes'] = valid_formats | |
315 | 317 | |
316 | 318 | return context |
317 | 319 | ... | ... |
pdf_file/models.py
... | ... | @@ -6,11 +6,11 @@ from django.core.urlresolvers import reverse_lazy |
6 | 6 | |
7 | 7 | from topics.models import Resource |
8 | 8 | # Create your models here. |
9 | +valid_formats = [ | |
10 | + 'application/pdf' | |
11 | +] | |
12 | + | |
9 | 13 | def validate_file_extension(value): |
10 | - valid_formats = [ | |
11 | - 'application/pdf' | |
12 | - ] | |
13 | - | |
14 | 14 | if hasattr(value.file, 'content_type'): |
15 | 15 | if not value.file.content_type in valid_formats: |
16 | 16 | raise ValidationError(_('File not supported, use PDF format instead.')) | ... | ... |
pdf_file/templates/pdf_file/_form.html
... | ... | @@ -25,8 +25,9 @@ |
25 | 25 | </div> |
26 | 26 | {% endif %} |
27 | 27 | </div> |
28 | -<div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> | |
29 | - {% render_field form.file class='file-selector' %} | |
28 | + | |
29 | + <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> | |
30 | + {% render_field form.file class='file-selector' data-max_size="10" data-mimetypes=mimeTypes %} | |
30 | 31 | |
31 | 32 | <div class="input-group common-file-input"> |
32 | 33 | <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}"> |
... | ... | @@ -51,18 +52,29 @@ |
51 | 52 | |
52 | 53 | <span id="helpBlock" class="help-block">{{ form.file.help_text }}</span> |
53 | 54 | |
54 | - {% if form.file.errors %} | |
55 | - <div class="alert alert-danger alert-dismissible" role="alert"> | |
56 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
57 | - <span aria-hidden="true">×</span> | |
58 | - </button> | |
59 | - <ul> | |
60 | - {% for error in form.file.errors %} | |
61 | - <li>{{ error }}</li> | |
62 | - {% endfor %} | |
63 | - </ul> | |
64 | - </div> | |
65 | - {% endif %} | |
55 | + </div> | |
56 | + | |
57 | + {% if form.file.errors %} | |
58 | + <div class="alert alert-danger alert-dismissible" role="alert"> | |
59 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
60 | + <span aria-hidden="true">×</span> | |
61 | + </button> | |
62 | + <ul> | |
63 | + {% for error in form.file.errors %} | |
64 | + <li>{{ error }}</li> | |
65 | + {% endfor %} | |
66 | + </ul> | |
67 | + </div> | |
68 | + {% endif %} | |
69 | + | |
70 | + <div class="col-lg-12 col-md-12 col-sm-12 alert alert-danger alert-dismissible client-file-errors" style="display:none" role="alert"> | |
71 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
72 | + <span aria-hidden="true">×</span> | |
73 | + </button> | |
74 | + <ul> | |
75 | + <li class="size" style="display:none">{% trans "The file is too large. It should have less than 10MB." %}</li> | |
76 | + <li class="format" style="display:none">{% trans 'File not supported.' %}</li> | |
77 | + </ul> | |
66 | 78 | </div> |
67 | 79 | |
68 | 80 | <legend>{% trans 'Common resources settings' %}</legend> | ... | ... |
pdf_file/views.py
... | ... | @@ -16,7 +16,7 @@ from django.http import HttpResponse, Http404 |
16 | 16 | |
17 | 17 | from log.mixins import LogMixin |
18 | 18 | from topics.models import Topic, Resource |
19 | -from .models import PDFFile | |
19 | +from .models import PDFFile, valid_formats | |
20 | 20 | from pendencies.forms import PendenciesForm |
21 | 21 | |
22 | 22 | from chat.models import Conversation, TalkMessages, ChatVisualizations |
... | ... | @@ -204,6 +204,7 @@ class PDFFileCreateView(LoginRequiredMixin, LogMixin , generic.CreateView): |
204 | 204 | |
205 | 205 | context['topic'] = topic |
206 | 206 | context['subject'] = topic.subject |
207 | + context['mimeTypes'] = valid_formats | |
207 | 208 | |
208 | 209 | return context |
209 | 210 | |
... | ... | @@ -319,6 +320,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): |
319 | 320 | |
320 | 321 | context['topic'] = topic |
321 | 322 | context['subject'] = topic.subject |
323 | + context['mimeTypes'] = valid_formats | |
322 | 324 | |
323 | 325 | return context |
324 | 326 | ... | ... |