From 664f5a8fbd953946ede80e3fe30d1c2f1c944499 Mon Sep 17 00:00:00 2001 From: Zambom Date: Tue, 5 Sep 2017 19:48:41 -0300 Subject: [PATCH] Adjusting bulletin files upload/choose --- amadeus/static/js/resources.js | 51 +++++++++++++++++++++++++++++++++++++++++---------- bulletin/forms.py | 2 ++ bulletin/sheets/xls/olhos.xls | Bin 0 -> 5632 bytes bulletin/templates/bulletin/_form.html | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- bulletin/views.py | 6 ++++-- file_link/forms.py | 2 ++ 6 files changed, 102 insertions(+), 41 deletions(-) create mode 100644 bulletin/sheets/xls/olhos.xls diff --git a/amadeus/static/js/resources.js b/amadeus/static/js/resources.js index e067d7f..239e974 100644 --- a/amadeus/static/js/resources.js +++ b/amadeus/static/js/resources.js @@ -135,13 +135,30 @@ 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 = $(e.target).data('mimetypes'); + mimeTypes = $(e.target).data('mimetypes'), + file_id = parent.data('file_id'); + + if ($(e.target).closest("form").prop('id') == "bulletin") { + parent.removeClass('alert-file'); + + var alerts_open = $(e.target).closest("form").find(".alert-file").length; + + if (alerts_open == 0) { + $(submit_btn).prop('disable', false); + $(submit_btn).prop('disabled', false); + } + + $("." + file_id + "-file-errors").hide(); + $("." + file_id + "-file-errors .size").hide(); + $("." + file_id + "-file-errors .format").hide(); + } else { + $(".client-file-errors").hide(); + $(".size").hide(); + $(".format").hide(); + $(submit_btn).prop('disable', false); + $(submit_btn).prop('disabled', false); + } - $(".client-file-errors").hide(); - $(".size").hide(); - $(".format").hide(); - $(submit_btn).prop('disable', false); - $(submit_btn).prop('disabled', false); // process all File objects for (var i = 0, f; f = files[i]; i++) { @@ -150,16 +167,30 @@ function FileSelectHandler(e) { $(submit_btn).prop('disable', true); $(submit_btn).prop('disabled', true); - $(".client-file-errors").show(); - $(".size").show(); + if ($(e.target).closest("form").prop('id') == "bulletin") { + $("." + file_id + "-file-errors").show(); + $("." + file_id + "-file-errors .size").show(); + + parent.addClass('alert-file'); + } else { + $(".client-file-errors").show(); + $(".size").show(); + } } if (!mimeTypes.includes(f.type)) { $(submit_btn).prop('disable', true); $(submit_btn).prop('disabled', true); - $(".client-file-errors").show(); - $(".format").show(); + if ($(e.target).closest("form").prop('id') == "bulletin") { + $("." + file_id + "-file-errors").show(); + $("." + file_id + "-file-errors .format").show(); + + parent.addClass('alert-file'); + } else { + $(".client-file-errors").show(); + $(".format").show(); + } } parent.find('.filedrag').html(f.name); diff --git a/bulletin/forms.py b/bulletin/forms.py index cabcf7f..efab8b3 100644 --- a/bulletin/forms.py +++ b/bulletin/forms.py @@ -39,6 +39,8 @@ class BulletinForm(forms.ModelForm): widgets = { 'content': forms.Textarea, 'brief_description': forms.Textarea, + 'file_content': ResubmitFileWidget(attrs={'accept':'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,application/vnd.oasis.opendocument.spreadsheet,text/csv'}), + 'indicators': ResubmitFileWidget(attrs={'accept':'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,application/vnd.oasis.opendocument.spreadsheet,text/csv'}), } def clean_name(self): diff --git a/bulletin/sheets/xls/olhos.xls b/bulletin/sheets/xls/olhos.xls new file mode 100644 index 0000000..6cd0424 Binary files /dev/null and b/bulletin/sheets/xls/olhos.xls differ diff --git a/bulletin/templates/bulletin/_form.html b/bulletin/templates/bulletin/_form.html index 7aa0a67..0ff1abe 100644 --- a/bulletin/templates/bulletin/_form.html +++ b/bulletin/templates/bulletin/_form.html @@ -1,7 +1,7 @@ {% load static i18n %} {% load widget_tweaks %} -
+ {% csrf_token %} {% render_field form.control_subject %} @@ -48,8 +48,8 @@ {% trans "Click to download a xls file with the data of the goals" %} -
- {% render_field form.file_content class='file-selector' %} +
+ {% render_field form.file_content class='file-selector' data-max_size="1" data-mimetypes=mimeTypes %}
@@ -74,23 +74,36 @@ {{ form.file_content.help_text }} - {% if form.file_content.errors %} - - {% endif %} + +
+ + {% if form.file_content.errors %} + + {% endif %} + + +
-
+
- {% render_field form.indicators class='file-selector' %} + {% render_field form.indicators class='file-selector' data-max_size="1" data-mimetypes=mimeTypes %}
@@ -115,18 +128,29 @@ {{ form.indicators.help_text }} - {% if form.indicators.errors %} - - {% endif %} +
+ + {% if form.indicators.errors %} + + {% endif %} + + {% trans 'Common resources settings' %} diff --git a/bulletin/views.py b/bulletin/views.py index 926391f..a98deef 100644 --- a/bulletin/views.py +++ b/bulletin/views.py @@ -27,7 +27,7 @@ from django.utils import timezone from pendencies.forms import PendenciesForm from .forms import BulletinForm -from .models import Bulletin +from .models import Bulletin, valid_formats from log.models import Log from log.decorators import log_decorator @@ -210,7 +210,7 @@ class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView): context['titulos'] = titulos context['student'] = self.request.POST.get('selected_student', students.first().email) context['students'] = students - + return context class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView): @@ -515,6 +515,7 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): alunos = sorted(list(meta_geral.topic.subject.students.all()), key = lambda e: e.id) create_excel_file(alunos, itens_da_meta,meta_geral) context['goal_file'] = str(meta_geral.slug) + context['mimeTypes'] = valid_formats return context @@ -787,6 +788,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): alunos = sorted(list(meta_geral.topic.subject.students.all()), key = lambda e: e.id) create_excel_file(alunos, itens_da_meta,meta_geral) context['goal_file'] = str(meta_geral.slug) + context['mimeTypes'] = valid_formats return context diff --git a/file_link/forms.py b/file_link/forms.py index 2af554b..bbeb431 100644 --- a/file_link/forms.py +++ b/file_link/forms.py @@ -2,6 +2,7 @@ from django import forms from django.utils.translation import ugettext_lazy as _ from django.utils.html import strip_tags +from resubmit.widgets import ResubmitFileWidget from subjects.models import Tag @@ -35,6 +36,7 @@ class FileLinkForm(forms.ModelForm): 'brief_description': forms.Textarea, 'students': forms.SelectMultiple, 'groups': forms.SelectMultiple, + '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'}), } def clean_name(self): -- libgit2 0.21.2