From 9dde06c3ace0cf5ee0a85b17658486ce73991cba Mon Sep 17 00:00:00 2001
From: Akshen
Date: Thu, 22 Jun 2017 10:49:22 +0530
Subject: Adds ZipFile Feature
- pdf_view function changed to file_view
- exclude added in ProposeWorkshopDateForm
- required templated changed for file_view
- zipfile feature included in file_view
---
workshop_app/forms.py | 10 +---
workshop_app/templates/workshop_app/booking.html | 2 +-
workshop_app/templates/workshop_app/index.html | 2 +-
.../workshop_app/view_workshoptype_details.html | 2 +-
.../workshop_app/view_workshoptype_list.html | 2 +-
workshop_app/urls.py | 2 +-
workshop_app/views.py | 54 +++++++++++-----------
7 files changed, 33 insertions(+), 41 deletions(-)
(limited to 'workshop_app')
diff --git a/workshop_app/forms.py b/workshop_app/forms.py
index b5c3d27..90ca733 100644
--- a/workshop_app/forms.py
+++ b/workshop_app/forms.py
@@ -60,12 +60,6 @@ class UserRegistrationForm(forms.Form):
department = forms.ChoiceField(help_text='Department you work/study',
choices=department_choices)
- # Activate when instructor Registration Starts
- # position = forms.ChoiceField(help_text='Select Coordinator if you want to organise a workshop\
- # in your college/school.
Select Instructor if you want to conduct\
- # a workshop.',
- # choices=position_choices
- # )
def clean_username(self):
u_name = self.cleaned_data["username"]
@@ -199,8 +193,8 @@ class ProposeWorkshopDateForm(forms.ModelForm):
class Meta:
model = ProposeWorkshopDate
- fields = ['proposed_workshop_title', 'proposed_workshop_date',
- 'condition_two','condition_three','condition_one']
+ exclude = ['status', 'proposed_workshop_instructor',
+ 'proposed_workshop_coordinator']
widgets = {
'proposed_workshop_date': forms.DateInput(attrs={
'class':'datepicker'}),
diff --git a/workshop_app/templates/workshop_app/booking.html b/workshop_app/templates/workshop_app/booking.html
index 64ecee1..7265889 100644
--- a/workshop_app/templates/workshop_app/booking.html
+++ b/workshop_app/templates/workshop_app/booking.html
@@ -125,7 +125,7 @@
{{ workshop.1 }} |
{{ workshop.2 }}
+ id="workshop-name">{{ workshop.2 }}
|
{{ workshop.0 }} |
diff --git a/workshop_app/templates/workshop_app/index.html b/workshop_app/templates/workshop_app/index.html
index aed85cc..718f9ba 100644
--- a/workshop_app/templates/workshop_app/index.html
+++ b/workshop_app/templates/workshop_app/index.html
@@ -76,7 +76,7 @@
-
+
How to Participate
diff --git a/workshop_app/templates/workshop_app/view_workshoptype_details.html b/workshop_app/templates/workshop_app/view_workshoptype_details.html
index f47cf59..60d63a4 100644
--- a/workshop_app/templates/workshop_app/view_workshoptype_details.html
+++ b/workshop_app/templates/workshop_app/view_workshoptype_details.html
@@ -66,7 +66,7 @@
{{ forloop.counter }} |
{{ w.workshoptype_name }} |
{{ w.workshoptype_duration }} |
-
View Workshop Details |
+
View Workshop Details |
{% endfor %}
diff --git a/workshop_app/templates/workshop_app/view_workshoptype_list.html b/workshop_app/templates/workshop_app/view_workshoptype_list.html
index 12ead53..b053305 100644
--- a/workshop_app/templates/workshop_app/view_workshoptype_list.html
+++ b/workshop_app/templates/workshop_app/view_workshoptype_list.html
@@ -58,7 +58,7 @@
{{ forloop.counter }} |
{{ w.workshoptype_name }} |
{{ w.workshoptype_duration }} |
- View Workshop Details |
+ View Workshop Details |
{% if request.user.profile.position == 'coordinator' %}
{% endif %}
diff --git a/workshop_app/urls.py b/workshop_app/urls.py
index 39ddebb..65b53e3 100644
--- a/workshop_app/urls.py
+++ b/workshop_app/urls.py
@@ -45,7 +45,7 @@ urlpatterns = [
url(r'^create_workshop/$', views.create_workshop),
url(r'^propose_workshop/$', views.propose_workshop),
url(r'^testimonials/$', views.testimonials),
- url(r'^pdf_view/(?P[\w|\W]+)$', views.pdf_view),
+ url(r'^file_view/(?P[\w|\W]+)$', views.file_view),
url(r'^jsi18n/$', django.views.i18n.javascript_catalog, js_info_dict),
]
diff --git a/workshop_app/views.py b/workshop_app/views.py
index 09269e8..a5a7321 100644
--- a/workshop_app/views.py
+++ b/workshop_app/views.py
@@ -25,8 +25,13 @@ from .send_mails import send_email
from django.http import HttpResponse, HttpResponseRedirect
from textwrap import dedent
from django.conf import settings
-from os import listdir, path
+from os import listdir, path, sep
import datetime as dt
+from zipfile import ZipFile
+try:
+ from StringIO import StringIO as string_io
+except ImportError:
+ from io import BytesIO as string_io
__author__ = "Akshen Doke"
__credits__ = ["Mahesh Gudi", "Aditya P.", "Ankit Javalkar",
@@ -819,16 +824,27 @@ def faq(request):
def how_to_participate(request):
return render(request, 'workshop_app/how_to_participate.html')
-def pdf_view(request, workshop_title):
- filename = WorkshopType.objects.filter(workshoptype_name=workshop_title)
- if filename.exists():
- attachment_path = path.join(settings.MEDIA_ROOT, workshop_title.replace(" ","_"))
- pdf_file = open(path.join(attachment_path, \
- '{0}.pdf'.format(workshop_title.replace(" ","_"))), 'rb')
- else:
+def file_view(request, workshop_title):
+ if workshop_title =='flowchart':
pdf_file = open(path.join(settings.MEDIA_ROOT,'flowchart.pdf'), 'rb')
-
- return HttpResponse(pdf_file, content_type="application/pdf")
+ return HttpResponse(pdf_file, content_type="application/pdf")
+ else:
+ filename = WorkshopType.objects.get(id=workshop_title)
+ attachment_path = path.dirname(filename.workshoptype_attachments.path)
+ zipfile_name = string_io()
+ zipfile = ZipFile(zipfile_name, "w")
+ attachments = listdir(attachment_path)
+ for file in attachments:
+ file_path = sep.join((attachment_path, file))
+ zipfile.write(file_path, path.basename(file_path))
+ zipfile.close()
+ zipfile_name.seek(0)
+ response = HttpResponse(content_type='application/zip')
+ response['Content-Disposition'] = 'attachment; filename={0}.zip'.format(
+ filename.workshoptype_name.replace(" ", "_")
+ )
+ response.write(zipfile_name.read())
+ return response
def testimonials(request):
testimonials = Testimonial.objects.all().order_by('-id')
@@ -845,21 +861,3 @@ def testimonials(request):
messages = paginator.page(paginator.num_pages)
return render(request, 'workshop_app/testimonals.html', {"messages":messages})
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
--
cgit