summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprathamesh2015-12-16 00:07:34 +0530
committerprathamesh2015-12-16 00:07:34 +0530
commit5121ccac89f3477451fbf2cfaedb623020dbd053 (patch)
tree38664eecf20aebefab485e0a426a143bba603b05
parent1fd6b3a0f674673a31295c757a9bccfbd60bf553 (diff)
downloadcertificate-generator-5121ccac89f3477451fbf2cfaedb623020dbd053.tar.gz
certificate-generator-5121ccac89f3477451fbf2cfaedb623020dbd053.tar.bz2
certificate-generator-5121ccac89f3477451fbf2cfaedb623020dbd053.zip
SciPy India 2015 certificate implementation
-rw-r--r--certificate/models.py13
-rw-r--r--certificate/templates/index.html1
-rw-r--r--certificate/templates/scipy_download_2015.html68
-rw-r--r--certificate/templates/scipy_feedback_2015.html26
-rw-r--r--certificate/urls.py2
-rw-r--r--certificate/views.py169
6 files changed, 278 insertions, 1 deletions
diff --git a/certificate/models.py b/certificate/models.py
index 0d382d3..c558d96 100644
--- a/certificate/models.py
+++ b/certificate/models.py
@@ -148,3 +148,16 @@ class Esim_faculty(models.Model):
name = models.CharField(max_length=200)
email = models.EmailField()
purpose = models.CharField(max_length=10, default='ESM')
+
+
+class Scipy_participant_2015(models.Model):
+ name = models.CharField(max_length=50, null=True, blank=True)
+ email = models.CharField(max_length=50, null=True, blank=True)
+ purpose = models.CharField(max_length=10, default='SPC')
+
+
+class Scipy_speaker_2015(models.Model):
+ name = models.CharField(max_length=300)
+ email = models.CharField(max_length=300)
+ paper = models.CharField(max_length=300)
+ purpose = models.CharField(max_length=10, default='SPC')
diff --git a/certificate/templates/index.html b/certificate/templates/index.html
index bed74b5..49669d1 100644
--- a/certificate/templates/index.html
+++ b/certificate/templates/index.html
@@ -7,6 +7,7 @@
<div style="margin:auto; width:45%">
<p>Below links will take you to a feedback form.<br> Please fill the feedback form and download your <b>e-certificate</b>.</h5></p>
<ul class="nav nav-list">
+ <li><a href="{% url 'certificate:scipy_feedback_2015' %}" >SciPy India Conference 2015</a></li>
<li><a href="{% url 'certificate:esim_google_feedback' %}" >eSim Faculty Meet 2015</a></li>
<li><a href="{% url 'certificate:arduino_google_feedback' %}" >Scilab Arduino Workshop 2015</a></li>
<li><a href="{% url 'certificate:dwsim_feedback' %}" >DWSIM Workshop 2015</a></li>
diff --git a/certificate/templates/scipy_download_2015.html b/certificate/templates/scipy_download_2015.html
new file mode 100644
index 0000000..3448cef
--- /dev/null
+++ b/certificate/templates/scipy_download_2015.html
@@ -0,0 +1,68 @@
+{% extends 'base.html' %}
+{% block header%}
+ <h1> SciPy India Conference 2015 </h1>
+{% endblock %}
+{% block content %}
+ <div class="modal fade" id="invalidModal" tabindex="-1" role="dialog" aria-labelledby="invalidModalLabel" aria-hidden="true">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
+ <h4 class="modal-title" id="invalidModalLabel">Invalid Category</h4>
+ </div>
+ <div class="modal-body">
+ The requested certificate is unavailable for your email address. Please select the appropriate category and retry.
+ </div>
+ </div>
+ </div>
+ </div>
+ <form class="col-lg-12" action="{% url 'certificate:scipy_download_2015' %}" method="post">
+ {% csrf_token %}
+ {{ message }}
+ <hr>
+ <p>Please choose the appropriate category</p>
+ <input type="radio" name="type" id="P" value="P" checked="True">Participant
+ &nbsp;&nbsp;<input type="radio" name="type" id="A" value="A">Speaker
+ <hr>
+ <div id ="paper">
+ {% if user_papers %}
+ <span><h3>Papers presented</h3><span>
+ <div class="radio" style="padding-left:350px;text-align:left">
+ {% for user in user_papers %}
+ <input type="radio" name="paper" value="{{ user.paper }}">{{ user.paper }}<br>
+ {% endfor %}
+ </div>
+ {% endif %}
+ </div>
+ <div class="input-group" style="width:340px;text-align:center;margin:0 auto;">
+ <input style="width:450;" class="form-control input-lg" placeholder="Enter the email address you used for registration" type="text" id="email" name=email>
+ <span class="input-group-btn"><button class="btn btn-lg btn-primary" type="submit">Download Certificate</button></span>
+ </div>
+ </form>
+ <center><h4>Problem in downloading the certificate? Write to us at <a href="mailto:certificates@fossee.in">certificates[at]fossee[dot]in</a></h4>
+{% endblock %}
+
+{% block javascript %}
+<script>
+ $(document).ready(function(){
+ value = "{{ v }}"
+ email = ""
+ error = "{{ error }}"
+ if(error == "True"){
+ $("#invalidModal").modal();
+ }
+ if(value == "paper"){
+ $('#A').prop('checked', true)
+ email = "{{ user_papers.0.email }}";
+ }
+ $('#email').val(email);
+ notreg = "{{ notregistered }}";
+ if(notreg == "1"){
+ $("#invalidModal").modal();
+ }
+ $("[name=type]").change(function(){
+ $("#paper").remove();
+ });
+ });
+</script>
+{% endblock %}
diff --git a/certificate/templates/scipy_feedback_2015.html b/certificate/templates/scipy_feedback_2015.html
new file mode 100644
index 0000000..c485b40
--- /dev/null
+++ b/certificate/templates/scipy_feedback_2015.html
@@ -0,0 +1,26 @@
+{% extends 'base.html' %}
+
+{% block header%}
+ <h1> SciPy India Conference 2015 </h1>
+{% endblock %}
+{% block content %}
+ <div style="width:50%; margin: 0 auto" >
+<form action="{% url 'certificate:scipy_feedback_2015' %}" method="post">
+
+ <h1> Feedback </h1>
+ <p>Your feedback will help us improve our services. Thank you for your time.</p>
+
+ {{ detail }}
+ {% csrf_token %}
+ <table class="table">
+ {{ form }}
+ </table>
+ {% for question in questions %}
+ <label style="float:left">{{ forloop.counter }}. {{ question.question }} </label><br>
+ <textarea cols="80" class="form-control" id="{{ question.id }}" name="{{ question.id }}"></textarea><br>
+ {% endfor %}
+ <button style="float:left" class="btn btn-primary" type="submit">Submit</button>
+ <a style="float:right" href="{% url 'certificate:scipy_download_2015' %}" >Skip feedback and download</a>
+ </form>
+ </div>
+{% endblock %}
diff --git a/certificate/urls.py b/certificate/urls.py
index a162f76..38cec80 100644
--- a/certificate/urls.py
+++ b/certificate/urls.py
@@ -14,6 +14,7 @@ urlpatterns = patterns('certificate.views',
url(r'^verify/(?P<serial_key>.*)/$', 'verify', name='verify-directly'),
url(r'^feedback/$', 'feedback', name='feedback'),
url(r'^scipy_feedback/$', 'scipy_feedback', name='scipy_feedback'),
+ url(r'^scipy_feedback_2015/$', 'scipy_feedback_2015', name='scipy_feedback_2015'),
url(r'^drupal_feedback/$', 'drupal_feedback', name='drupal_feedback'),
url(r'^dwsim_feedback/$', 'dwsim_feedback', name='dwsim_feedback'),
url(r'^arduino_feedback/$', 'arduino_feedback', name='arduino_feedback'),
@@ -25,4 +26,5 @@ urlpatterns = patterns('certificate.views',
url(r'^dwsim_download/$', 'dwsim_download', name='dwsim_download'),
url(r'^arduino_download/$', 'arduino_download', name='arduino_download'),
url(r'^esim_download/$', 'esim_download', name='esim_download'),
+ url(r'^scipy_download_2015/$', 'scipy_download_2015', name='scipy_download_2015'),
)
diff --git a/certificate/views.py b/certificate/views.py
index ac386c1..987e6cf 100644
--- a/certificate/views.py
+++ b/certificate/views.py
@@ -2,7 +2,7 @@ from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import render_to_response, redirect
from django.template import RequestContext
-from certificate.models import Scilab_participant, Certificate, Event, Scilab_speaker, Scilab_workshop, Question, Answer, FeedBack, Scipy_participant, Scipy_speaker, Drupal_camp, Tbc_freeeda, Dwsim_participant, Scilab_arduino, Esim_faculty
+from certificate.models import Scilab_participant, Certificate, Event, Scilab_speaker, Scilab_workshop, Question, Answer, FeedBack, Scipy_participant, Scipy_speaker, Drupal_camp, Tbc_freeeda, Dwsim_participant, Scilab_arduino, Esim_faculty, Scipy_participant_2015, Scipy_speaker_2015
import subprocess
import os
from string import Template
@@ -122,6 +122,9 @@ def verification(serial, _type):
faculty = Esim_faculty.objects.get(email=certificate.email)
detail = OrderedDict([('Name', name), ('Event', purpose),
('Days', '22 August'), ('Year', year)])
+ elif purpose == 'SciPy India':
+ detail = OrderedDict([('Name', name), ('Event', purpose),
+ ('Days', '14 - 16 December'), ('Year', year)])
elif purpose == 'DrupalCamp Mumbai':
drupal_user = Drupal_camp.objects.get(email=certificate.email)
DAY = drupal_user.attendance
@@ -143,6 +146,8 @@ def verification(serial, _type):
elif type == 'A':
detail = '{0} had presented paper on {3} in the {1} {2}'.format\
(name, purpose, year, paper)
+ if purpose == 'SciPy India':
+ detail = OrderedDict([('Name', name), ('Event', purpose), ('paper', paper), ('Days', '14 - 16 December'), ('Year', year)])
elif type == 'W':
detail = '{0} had attended workshop on {3} in the {1} {2}'.format\
(name, purpose, year, workshop)
@@ -1131,4 +1136,166 @@ def create_esim_certificate(certificate_path, name, qrcode, type, paper, worksho
error = True
return [None, error]
+###############################################################################
+# SciPy 2015
+###############################################################################
+def scipy_feedback_2015(request):
+ context = {}
+ ci = RequestContext(request)
+ form = FeedBackForm()
+ questions = Question.objects.filter(purpose='SPC2015')
+ if request.method == 'POST':
+ form = FeedBackForm(request.POST)
+ if form.is_valid():
+ data = form.cleaned_data
+ try:
+ FeedBack.objects.get(email=data['email'].strip(), purpose='SPC2015')
+ context['message'] = 'You have already submitted the feedback. You can download your certificate.'
+ return render_to_response('scipy_download_2015.html', context, ci)
+ except FeedBack.DoesNotExist:
+ feedback = FeedBack()
+ feedback.name = data['name'].strip()
+ feedback.email = data['email'].strip()
+ feedback.purpose = 'SPC2015'
+ feedback.submitted = True
+ feedback.save()
+ for question in questions:
+ answered = request.POST.get('{0}'.format(question.id), None)
+ answer = Answer()
+ answer.question = question
+ answer.answer = answered.strip()
+ answer.save()
+ feedback.answer.add(answer)
+ feedback.save()
+ context['message'] = ''
+ return render_to_response('scipy_download_2015.html', context, ci)
+
+ context['form'] = form
+ context['questions'] = questions
+
+ return render_to_response('scipy_feedback_2015.html', context, ci)
+
+
+def scipy_download_2015(request):
+ context = {}
+ err = ""
+ ci = RequestContext(request)
+ cur_path = os.path.dirname(os.path.realpath(__file__))
+ certificate_path = '{0}/scipy_template_2015/'.format(cur_path)
+
+ if request.method == 'POST':
+ paper = request.POST.get('paper', None)
+ workshop = None
+ email = request.POST.get('email').strip()
+ type = request.POST.get('type')
+ if type == 'P':
+ user = Scipy_participant_2015.objects.filter(email=email)
+ if not user:
+ context["notregistered"] = 1
+ return render_to_response('scipy_download_2015.html', context, context_instance=ci)
+ else:
+ user = user[0]
+ elif type == 'A':
+ if paper:
+ user = Scipy_speaker_2015.objects.filter(email=email, paper=paper)
+ if user:
+ user = [user[0]]
+ else:
+ user = Scipy_speaker_2015.objects.filter(email=email)
+ if not user:
+ context["notregistered"] = 1
+ return render_to_response('scipy_download_2015.html', context, context_instance=ci)
+ if len(user) > 1:
+ context['user_papers'] = user
+ context['v'] = 'paper'
+ return render_to_response('scipy_download_2015.html', context, context_instance=ci)
+ else:
+ user = user[0]
+ paper = user.paper
+ name = user.name
+ purpose = user.purpose
+ year = '15'
+ id = int(user.id)
+ hexa = hex(id).replace('0x','').zfill(6).upper()
+ serial_no = '{0}{1}{2}{3}'.format(purpose, year, hexa, type)
+ serial_key = (hashlib.sha1(serial_no)).hexdigest()
+ file_name = '{0}{1}'.format(email,id)
+ file_name = file_name.replace('.', '')
+ try:
+ old_user = Certificate.objects.get(email=email, serial_no=serial_no)
+ qrcode = 'Verify at: http://fossee.in/certificates/verify/{0} '.format(old_user.short_key)
+ details = {'name': name, 'serial_key': old_user.short_key}
+ certificate = create_scipy_certificate_2015(certificate_path, details, qrcode, type, paper, workshop, file_name)
+ if not certificate[1]:
+ old_user.counter = old_user.counter + 1
+ old_user.save()
+ return certificate[0]
+ except Certificate.DoesNotExist:
+ uniqueness = False
+ num = 5
+ while not uniqueness:
+ present = Certificate.objects.filter(short_key__startswith=serial_key[0:num])
+ if not present:
+ short_key = serial_key[0:num]
+ uniqueness = True
+ else:
+ num += 1
+ qrcode = 'Verify at: http://fossee.in/certificates/verify/{0} '.format(short_key)
+ details = {'name': name, 'serial_key': short_key}
+ certificate = create_scipy_certificate_2015(certificate_path, details,
+ qrcode, type, paper, workshop, file_name)
+ if not certificate[1]:
+ certi_obj = Certificate(name=name, email=email, serial_no=serial_no,
+ counter=1, workshop=workshop, paper=paper, serial_key=serial_key, short_key=short_key)
+ certi_obj.save()
+ return certificate[0]
+
+ if certificate[1]:
+ _clean_certificate_certificate(certificate_path, file_name)
+ context['error'] = True
+ return render_to_response('scipy_download_2015.html', context, ci)
+ context['message'] = ''
+ return render_to_response('scipy_download_2015.html', context, ci)
+
+
+def create_scipy_certificate_2015(certificate_path, name, qrcode, type, paper, workshop, file_name):
+ error = False
+ try:
+ download_file_name = None
+ if type == 'P':
+ template = 'template_SPC2015Pcertificate'
+ download_file_name = 'SPC2015Pcertificate.pdf'
+ elif type == 'A':
+ template = 'template_SPC2015Acertificate'
+ download_file_name = 'SPC2015Acertificate.pdf'
+
+ template_file = open('{0}{1}'.format\
+ (certificate_path, template), 'r')
+ content = Template(template_file.read())
+ template_file.close()
+ if type == 'P':
+ content_tex = content.safe_substitute(name=name['name'].title(),
+ serial_key=name['serial_key'], qr_code=qrcode)
+ elif type == 'A':
+ content_tex = content.safe_substitute(name=name['name'].title(),
+ serial_key=name['serial_key'], qr_code=qrcode, paper=paper)
+ create_tex = open('{0}{1}.tex'.format\
+ (certificate_path, file_name), 'w')
+ create_tex.write(content_tex)
+ create_tex.close()
+ return_value, err = _make_certificate_certificate(certificate_path, type, file_name)
+ print err
+ if return_value == 0:
+ pdf = open('{0}{1}.pdf'.format(certificate_path, file_name) , 'r')
+ response = HttpResponse(content_type='application/pdf')
+ response['Content-Disposition'] = 'attachment; \
+ filename=%s' % (download_file_name)
+ response.write(pdf.read())
+ _clean_certificate_certificate(certificate_path, file_name)
+ return [response, False]
+ else:
+ error = True
+ except Exception, e:
+ error = True
+ return [None, error]