diff --git a/bulletin/sheets/xls/future.xls b/bulletin/sheets/xls/future.xls
new file mode 100644
index 0000000..f370e31
Binary files /dev/null and b/bulletin/sheets/xls/future.xls differ
diff --git a/bulletin/templates/bulletin/_form.html b/bulletin/templates/bulletin/_form.html
index ca37802..c6c02af 100644
--- a/bulletin/templates/bulletin/_form.html
+++ b/bulletin/templates/bulletin/_form.html
@@ -70,9 +70,7 @@
- {% with 'xls/'|add:goal_file as file_static %}
-
{% trans "Click to download a xls file with the data of the goals" %}
- {% endwith %}
+
{% trans "Click to download a xls file with the data of the goals" %}
{% render_field form.file_content class='file-selector' %}
diff --git a/bulletin/urls.py b/bulletin/urls.py
index 4b84991..44124ea 100644
--- a/bulletin/urls.py
+++ b/bulletin/urls.py
@@ -11,4 +11,5 @@ urlpatterns = [
url(r'^view/(?P[\w_-]+)/$', views.InsideView.as_view(), name = 'view'),
url(r'^chart/(?P[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'),
url(r'^send-message/(?P[\w_-]+)/$', views.SendMessage.as_view(), name = 'send_message'),
+ url(r'^download_file/(?P[\w_-]+)/$', views.download_excel, name = 'download_file'),
]
diff --git a/bulletin/views.py b/bulletin/views.py
index 117b385..928ff3f 100644
--- a/bulletin/views.py
+++ b/bulletin/views.py
@@ -6,6 +6,8 @@ from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import JsonResponse
+from os import path
+
from amadeus.permissions import has_subject_permissions, has_resource_permissions
from .utils import brodcast_dificulties
from goals.models import Goals,GoalItem,MyGoals
@@ -386,7 +388,7 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView):
itens_da_meta = sorted(list(metas), key = lambda met: met.id)
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)+".xls"
+ context['goal_file'] = str(meta_geral.slug)
return context
@@ -405,6 +407,23 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView):
return success_url
+def download_excel(request, file):
+ filepath = 'bulletin/sheets/xls/' + file + '.xls'
+
+ if not path.exists(filepath):
+ raise Http404()
+
+ response = HttpResponse(open(filepath, 'rb').read())
+ response['Content-Type'] = 'application/force-download'
+ response['Pragma'] = 'public'
+ response['Expires'] = '0'
+ response['Cache-Control'] = 'must-revalidate, post-check=0, pre-check=0'
+ response['Content-Disposition'] = 'attachment; filename=%s' % (file + '.xls')
+ response['Content-Transfer-Encoding'] = 'binary'
+ response['Content-Length'] = str(path.getsize(filepath))
+
+ return response
+
def create_excel_file(estudantes,metas,meta):
workbook = xlwt.Workbook()
worksheet = workbook.add_sheet(u'Bulletin')
@@ -426,7 +445,7 @@ def create_excel_file(estudantes,metas,meta):
contador_estudante += 1
path1 = os.path.join(settings.BASE_DIR,'bulletin')
- path2 = os.path.join(path1,'static')
+ path2 = os.path.join(path1,'sheets')
path3 = os.path.join(path2,'xls')
nome = str(meta.slug) + ".xls"
@@ -576,7 +595,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView):
itens_da_meta = sorted(list(metas), key = lambda met: met.id)
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)+".xls"
+ context['goal_file'] = str(meta_geral.slug)
return context
--
libgit2 0.21.2