Commit 664f5a8fbd953946ede80e3fe30d1c2f1c944499
1 parent
ddbdf642
Exists in
master
and in
2 other branches
Adjusting bulletin files upload/choose
Showing
6 changed files
with
102 additions
and
41 deletions
Show diff stats
amadeus/static/js/resources.js
@@ -135,13 +135,30 @@ function FileSelectHandler(e) { | @@ -135,13 +135,30 @@ function FileSelectHandler(e) { | ||
135 | parent = $(e.target.offsetParent), | 135 | parent = $(e.target.offsetParent), |
136 | max_size = parseInt($(e.target).data("max_size")) * 1024 * 1024, | 136 | max_size = parseInt($(e.target).data("max_size")) * 1024 * 1024, |
137 | submit_btn = $(e.target).closest("form").find("input[type='submit']"), | 137 | submit_btn = $(e.target).closest("form").find("input[type='submit']"), |
138 | - mimeTypes = $(e.target).data('mimetypes'); | 138 | + mimeTypes = $(e.target).data('mimetypes'), |
139 | + file_id = parent.data('file_id'); | ||
140 | + | ||
141 | + if ($(e.target).closest("form").prop('id') == "bulletin") { | ||
142 | + parent.removeClass('alert-file'); | ||
143 | + | ||
144 | + var alerts_open = $(e.target).closest("form").find(".alert-file").length; | ||
145 | + | ||
146 | + if (alerts_open == 0) { | ||
147 | + $(submit_btn).prop('disable', false); | ||
148 | + $(submit_btn).prop('disabled', false); | ||
149 | + } | ||
150 | + | ||
151 | + $("." + file_id + "-file-errors").hide(); | ||
152 | + $("." + file_id + "-file-errors .size").hide(); | ||
153 | + $("." + file_id + "-file-errors .format").hide(); | ||
154 | + } else { | ||
155 | + $(".client-file-errors").hide(); | ||
156 | + $(".size").hide(); | ||
157 | + $(".format").hide(); | ||
158 | + $(submit_btn).prop('disable', false); | ||
159 | + $(submit_btn).prop('disabled', false); | ||
160 | + } | ||
139 | 161 | ||
140 | - $(".client-file-errors").hide(); | ||
141 | - $(".size").hide(); | ||
142 | - $(".format").hide(); | ||
143 | - $(submit_btn).prop('disable', false); | ||
144 | - $(submit_btn).prop('disabled', false); | ||
145 | 162 | ||
146 | // process all File objects | 163 | // process all File objects |
147 | for (var i = 0, f; f = files[i]; i++) { | 164 | for (var i = 0, f; f = files[i]; i++) { |
@@ -150,16 +167,30 @@ function FileSelectHandler(e) { | @@ -150,16 +167,30 @@ function FileSelectHandler(e) { | ||
150 | $(submit_btn).prop('disable', true); | 167 | $(submit_btn).prop('disable', true); |
151 | $(submit_btn).prop('disabled', true); | 168 | $(submit_btn).prop('disabled', true); |
152 | 169 | ||
153 | - $(".client-file-errors").show(); | ||
154 | - $(".size").show(); | 170 | + if ($(e.target).closest("form").prop('id') == "bulletin") { |
171 | + $("." + file_id + "-file-errors").show(); | ||
172 | + $("." + file_id + "-file-errors .size").show(); | ||
173 | + | ||
174 | + parent.addClass('alert-file'); | ||
175 | + } else { | ||
176 | + $(".client-file-errors").show(); | ||
177 | + $(".size").show(); | ||
178 | + } | ||
155 | } | 179 | } |
156 | 180 | ||
157 | if (!mimeTypes.includes(f.type)) { | 181 | if (!mimeTypes.includes(f.type)) { |
158 | $(submit_btn).prop('disable', true); | 182 | $(submit_btn).prop('disable', true); |
159 | $(submit_btn).prop('disabled', true); | 183 | $(submit_btn).prop('disabled', true); |
160 | 184 | ||
161 | - $(".client-file-errors").show(); | ||
162 | - $(".format").show(); | 185 | + if ($(e.target).closest("form").prop('id') == "bulletin") { |
186 | + $("." + file_id + "-file-errors").show(); | ||
187 | + $("." + file_id + "-file-errors .format").show(); | ||
188 | + | ||
189 | + parent.addClass('alert-file'); | ||
190 | + } else { | ||
191 | + $(".client-file-errors").show(); | ||
192 | + $(".format").show(); | ||
193 | + } | ||
163 | } | 194 | } |
164 | 195 | ||
165 | parent.find('.filedrag').html(f.name); | 196 | parent.find('.filedrag').html(f.name); |
bulletin/forms.py
@@ -39,6 +39,8 @@ class BulletinForm(forms.ModelForm): | @@ -39,6 +39,8 @@ class BulletinForm(forms.ModelForm): | ||
39 | widgets = { | 39 | widgets = { |
40 | 'content': forms.Textarea, | 40 | 'content': forms.Textarea, |
41 | 'brief_description': forms.Textarea, | 41 | 'brief_description': forms.Textarea, |
42 | + 'file_content': ResubmitFileWidget(attrs={'accept':'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,application/vnd.oasis.opendocument.spreadsheet,text/csv'}), | ||
43 | + 'indicators': ResubmitFileWidget(attrs={'accept':'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,application/vnd.oasis.opendocument.spreadsheet,text/csv'}), | ||
42 | } | 44 | } |
43 | 45 | ||
44 | def clean_name(self): | 46 | def clean_name(self): |
No preview for this file type
bulletin/templates/bulletin/_form.html
1 | {% load static i18n %} | 1 | {% load static i18n %} |
2 | {% load widget_tweaks %} | 2 | {% load widget_tweaks %} |
3 | 3 | ||
4 | -<form method="post" action="" enctype="multipart/form-data"> | 4 | +<form id="bulletin" method="post" action="" enctype="multipart/form-data"> |
5 | {% csrf_token %} | 5 | {% csrf_token %} |
6 | 6 | ||
7 | {% render_field form.control_subject %} | 7 | {% render_field form.control_subject %} |
@@ -48,8 +48,8 @@ | @@ -48,8 +48,8 @@ | ||
48 | 48 | ||
49 | <label for="{{ form.file_content.auto_id }}">{{ form.file_content.label }} <span>*</span></label> | 49 | <label for="{{ form.file_content.auto_id }}">{{ form.file_content.label }} <span>*</span></label> |
50 | <a href="{% url 'bulletin:download_file' file=goal_file %}"> {% trans "Click to download a xls file with the data of the goals" %}</a> | 50 | <a href="{% url 'bulletin:download_file' file=goal_file %}"> {% trans "Click to download a xls file with the data of the goals" %}</a> |
51 | - <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> | ||
52 | - {% render_field form.file_content class='file-selector' %} | 51 | + <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput" data-file_id="{{ form.file_content.auto_id }}"> |
52 | + {% render_field form.file_content class='file-selector' data-max_size="1" data-mimetypes=mimeTypes %} | ||
53 | 53 | ||
54 | <div class="input-group common-file-input"> | 54 | <div class="input-group common-file-input"> |
55 | <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}"> | 55 | <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}"> |
@@ -74,23 +74,36 @@ | @@ -74,23 +74,36 @@ | ||
74 | 74 | ||
75 | <span id="helpBlock" class="help-block">{{ form.file_content.help_text }}</span> | 75 | <span id="helpBlock" class="help-block">{{ form.file_content.help_text }}</span> |
76 | 76 | ||
77 | - {% if form.file_content.errors %} | ||
78 | - <div class="alert alert-danger alert-dismissible" role="alert"> | ||
79 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
80 | - <span aria-hidden="true">×</span> | ||
81 | - </button> | ||
82 | - <ul> | ||
83 | - {% for error in form.file_content.errors %} | ||
84 | - <li>{{ error }}</li> | ||
85 | - {% endfor %} | ||
86 | - </ul> | ||
87 | - </div> | ||
88 | - {% endif %} | 77 | + |
78 | + </div> | ||
79 | + | ||
80 | + {% if form.file_content.errors %} | ||
81 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
82 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
83 | + <span aria-hidden="true">×</span> | ||
84 | + </button> | ||
85 | + <ul> | ||
86 | + {% for error in form.file_content.errors %} | ||
87 | + <li>{{ error }}</li> | ||
88 | + {% endfor %} | ||
89 | + </ul> | ||
90 | + </div> | ||
91 | + {% endif %} | ||
92 | + | ||
93 | + <div class="col-lg-12 col-md-12 col-sm-12 alert alert-danger alert-dismissible {{ form.file_content.auto_id }}-file-errors" style="display:none" role="alert"> | ||
94 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
95 | + <span aria-hidden="true">×</span> | ||
96 | + </button> | ||
97 | + <ul> | ||
98 | + <li class="size" style="display:none">{% trans "The file is too large. It should have less than 1MB." %}</li> | ||
99 | + <li class="format" style="display:none">{% trans 'File not supported.' %}</li> | ||
100 | + </ul> | ||
89 | </div> | 101 | </div> |
102 | + <br clear="all" /> | ||
90 | 103 | ||
91 | - <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> | 104 | + <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput" data-file_id="{{ form.indicators.auto_id }}"> |
92 | <label for="{{ form.indicators.auto_id }}">{{ form.indicators.label }} <span>*</span></label> | 105 | <label for="{{ form.indicators.auto_id }}">{{ form.indicators.label }} <span>*</span></label> |
93 | - {% render_field form.indicators class='file-selector' %} | 106 | + {% render_field form.indicators class='file-selector' data-max_size="1" data-mimetypes=mimeTypes %} |
94 | 107 | ||
95 | <div class="input-group common-file-input"> | 108 | <div class="input-group common-file-input"> |
96 | <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}"> | 109 | <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}"> |
@@ -115,18 +128,29 @@ | @@ -115,18 +128,29 @@ | ||
115 | 128 | ||
116 | <span id="helpBlock" class="help-block">{{ form.indicators.help_text }}</span> | 129 | <span id="helpBlock" class="help-block">{{ form.indicators.help_text }}</span> |
117 | 130 | ||
118 | - {% if form.indicators.errors %} | ||
119 | - <div class="alert alert-danger alert-dismissible" role="alert"> | ||
120 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
121 | - <span aria-hidden="true">×</span> | ||
122 | - </button> | ||
123 | - <ul> | ||
124 | - {% for error in form.indicators.errors %} | ||
125 | - <li>{{ error }}</li> | ||
126 | - {% endfor %} | ||
127 | - </ul> | ||
128 | - </div> | ||
129 | - {% endif %} | 131 | + </div> |
132 | + | ||
133 | + {% if form.indicators.errors %} | ||
134 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
135 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
136 | + <span aria-hidden="true">×</span> | ||
137 | + </button> | ||
138 | + <ul> | ||
139 | + {% for error in form.indicators.errors %} | ||
140 | + <li>{{ error }}</li> | ||
141 | + {% endfor %} | ||
142 | + </ul> | ||
143 | + </div> | ||
144 | + {% endif %} | ||
145 | + | ||
146 | + <div class="col-lg-12 col-md-12 col-sm-12 alert alert-danger alert-dismissible {{ form.indicators.auto_id }}-file-errors" style="display:none" role="alert"> | ||
147 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
148 | + <span aria-hidden="true">×</span> | ||
149 | + </button> | ||
150 | + <ul> | ||
151 | + <li class="size" style="display:none">{% trans "The file is too large. It should have less than 1MB." %}</li> | ||
152 | + <li class="format" style="display:none">{% trans 'File not supported.' %}</li> | ||
153 | + </ul> | ||
130 | </div> | 154 | </div> |
131 | 155 | ||
132 | <legend>{% trans 'Common resources settings' %}</legend> | 156 | <legend>{% trans 'Common resources settings' %}</legend> |
bulletin/views.py
@@ -27,7 +27,7 @@ from django.utils import timezone | @@ -27,7 +27,7 @@ from django.utils import timezone | ||
27 | from pendencies.forms import PendenciesForm | 27 | from pendencies.forms import PendenciesForm |
28 | 28 | ||
29 | from .forms import BulletinForm | 29 | from .forms import BulletinForm |
30 | -from .models import Bulletin | 30 | +from .models import Bulletin, valid_formats |
31 | 31 | ||
32 | from log.models import Log | 32 | from log.models import Log |
33 | from log.decorators import log_decorator | 33 | from log.decorators import log_decorator |
@@ -210,7 +210,7 @@ class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView): | @@ -210,7 +210,7 @@ class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView): | ||
210 | context['titulos'] = titulos | 210 | context['titulos'] = titulos |
211 | context['student'] = self.request.POST.get('selected_student', students.first().email) | 211 | context['student'] = self.request.POST.get('selected_student', students.first().email) |
212 | context['students'] = students | 212 | context['students'] = students |
213 | - | 213 | + |
214 | return context | 214 | return context |
215 | 215 | ||
216 | class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView): | 216 | class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView): |
@@ -515,6 +515,7 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | @@ -515,6 +515,7 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | ||
515 | alunos = sorted(list(meta_geral.topic.subject.students.all()), key = lambda e: e.id) | 515 | alunos = sorted(list(meta_geral.topic.subject.students.all()), key = lambda e: e.id) |
516 | create_excel_file(alunos, itens_da_meta,meta_geral) | 516 | create_excel_file(alunos, itens_da_meta,meta_geral) |
517 | context['goal_file'] = str(meta_geral.slug) | 517 | context['goal_file'] = str(meta_geral.slug) |
518 | + context['mimeTypes'] = valid_formats | ||
518 | 519 | ||
519 | 520 | ||
520 | return context | 521 | return context |
@@ -787,6 +788,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): | @@ -787,6 +788,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): | ||
787 | alunos = sorted(list(meta_geral.topic.subject.students.all()), key = lambda e: e.id) | 788 | alunos = sorted(list(meta_geral.topic.subject.students.all()), key = lambda e: e.id) |
788 | create_excel_file(alunos, itens_da_meta,meta_geral) | 789 | create_excel_file(alunos, itens_da_meta,meta_geral) |
789 | context['goal_file'] = str(meta_geral.slug) | 790 | context['goal_file'] = str(meta_geral.slug) |
791 | + context['mimeTypes'] = valid_formats | ||
790 | 792 | ||
791 | return context | 793 | return context |
792 | 794 |
file_link/forms.py
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | from django import forms | 2 | from django import forms |
3 | from django.utils.translation import ugettext_lazy as _ | 3 | from django.utils.translation import ugettext_lazy as _ |
4 | from django.utils.html import strip_tags | 4 | from django.utils.html import strip_tags |
5 | +from resubmit.widgets import ResubmitFileWidget | ||
5 | 6 | ||
6 | from subjects.models import Tag | 7 | from subjects.models import Tag |
7 | 8 | ||
@@ -35,6 +36,7 @@ class FileLinkForm(forms.ModelForm): | @@ -35,6 +36,7 @@ class FileLinkForm(forms.ModelForm): | ||
35 | 'brief_description': forms.Textarea, | 36 | 'brief_description': forms.Textarea, |
36 | 'students': forms.SelectMultiple, | 37 | 'students': forms.SelectMultiple, |
37 | 'groups': forms.SelectMultiple, | 38 | 'groups': forms.SelectMultiple, |
39 | + 'file_content': ResubmitFileWidget(attrs={'accept':'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'}), | ||
38 | } | 40 | } |
39 | 41 | ||
40 | def clean_name(self): | 42 | def clean_name(self): |