summaryrefslogtreecommitdiff
path: root/workshop_app
diff options
context:
space:
mode:
authorAkshen2017-06-22 10:49:22 +0530
committerAkshen2017-06-22 10:49:22 +0530
commit9dde06c3ace0cf5ee0a85b17658486ce73991cba (patch)
treed63e3109e8de52949363e880d5f177878ea26a54 /workshop_app
parent81458d0cd8e68a99cd2b429aaf38fa4f33d12e22 (diff)
downloadworkshop_booking-9dde06c3ace0cf5ee0a85b17658486ce73991cba.tar.gz
workshop_booking-9dde06c3ace0cf5ee0a85b17658486ce73991cba.tar.bz2
workshop_booking-9dde06c3ace0cf5ee0a85b17658486ce73991cba.zip
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
Diffstat (limited to 'workshop_app')
-rw-r--r--workshop_app/forms.py10
-rw-r--r--workshop_app/templates/workshop_app/booking.html2
-rw-r--r--workshop_app/templates/workshop_app/index.html2
-rw-r--r--workshop_app/templates/workshop_app/view_workshoptype_details.html2
-rw-r--r--workshop_app/templates/workshop_app/view_workshoptype_list.html2
-rw-r--r--workshop_app/urls.py2
-rw-r--r--workshop_app/views.py54
7 files changed, 33 insertions, 41 deletions
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. <br> 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 @@
<tr >
<td id="instructor-name">{{ workshop.1 }}</td>
<td
- id="workshop-name">{{ workshop.2 }} <a href="{{URL_ROOT}}/pdf_view/{{workshop.2.workshoptype_name}}" >
+ id="workshop-name">{{ workshop.2 }} <a href="{{URL_ROOT}}/file_view/{{workshop.4}}" >
<span class="glyphicon glyphicon-info-sign"></span>
</a> </td>
<td id="workshop-date{{ forloop.counter }}">{{ workshop.0 }}</td>
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 @@
<br><br>
</div>
<div class="col-md-3" style="align-items: center;">
- <a href="{{ URL_ROOT }}/pdf_view/flowchart" >
+ <a href="{{ URL_ROOT }}/file_view/flowchart" >
<img src="{{ URL_ROOT}}/static/workshop_app/img/part.png"><br><br>
How to Participate</a>
<br><br>
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 @@
<td scope="row" id="{{ forloop.counter }}">{{ forloop.counter }}</td>
<td>{{ w.workshoptype_name }}</td>
<td>{{ w.workshoptype_duration }}</td>
- <td><a href="{{URL_ROOT}}/pdf_view/{{ w.workshoptype_name }}"class="btn btn-default btn-sm" class="accordion-toggle" >View Workshop Details</a></td>
+ <td><a href="{{URL_ROOT}}/file_view/{{ w.id }}" class="btn btn-default btn-sm" class="accordion-toggle" >View Workshop Details</a></td>
</tr>
</tbody>
{% 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 @@
<td scope="row" id="{{ forloop.counter }}">{{ forloop.counter }}</td>
<td>{{ w.workshoptype_name }}</td>
<td>{{ w.workshoptype_duration }}</td>
- <td><a class="btn btn-default btn-sm" href="{{URL_ROOT}}/pdf_view/{{ w.workshoptype_name }}">View Workshop Details</a></td>
+ <td><a class="btn btn-default btn-sm" href="{{URL_ROOT}}/file_view/{{ w.id }}">View Workshop Details</a></td>
{% if request.user.profile.position == 'coordinator' %}
{% endif %}
</tr>
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<workshop_title>[\w|\W]+)$', views.pdf_view),
+ url(r'^file_view/(?P<workshop_title>[\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})
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-