summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFOSSEE2016-08-04 14:58:08 +0530
committerFOSSEE2016-08-04 14:58:08 +0530
commitfeaa8d15760f96ce34f3a41cd07acfea992a6728 (patch)
tree4acb72e80902ce7886adb115ce985f0d939b8ec5
parent40222ea2da51de9a40bb793156ff48cd05bbbff4 (diff)
downloadcertificate-generator-feaa8d15760f96ce34f3a41cd07acfea992a6728.tar.gz
certificate-generator-feaa8d15760f96ce34f3a41cd07acfea992a6728.tar.bz2
certificate-generator-feaa8d15760f96ce34f3a41cd07acfea992a6728.zip
Drupal Workshop Certificate Template
-rwxr-xr-xcertificate/models.py8
-rw-r--r--certificate/templates/drupal_workshop_download.html60
-rwxr-xr-xcertificate/templates/index.html1
-rwxr-xr-xcertificate/urls.py2
-rwxr-xr-xcertificate/views.py109
5 files changed, 177 insertions, 3 deletions
diff --git a/certificate/models.py b/certificate/models.py
index 55a8979..5a28e04 100755
--- a/certificate/models.py
+++ b/certificate/models.py
@@ -12,7 +12,8 @@ events = (
('OFC', 'OpenFOAM Symposium'),
('FIC', 'Fossee Internship'),
('OWS', 'Osdag Workshop'),
- ('EWS', 'eSim Workshop')
+ ('EWS', 'eSim Workshop'),
+ ('DWS', 'Drupal Workshop'),
)
class Profile(models.Model):
@@ -158,6 +159,11 @@ class Osdag_WS(models.Model):
email = models.EmailField()
purpose = models.CharField(max_length=10, default='OWS')
+class Drupal_WS(models.Model):
+ name = models.CharField(max_length=200)
+ email = models.EmailField()
+ purpose = models.CharField(max_length=10, default='DWS')
+
class eSim_WS(models.Model):
name = models.CharField(max_length=200)
email = models.EmailField()
diff --git a/certificate/templates/drupal_workshop_download.html b/certificate/templates/drupal_workshop_download.html
new file mode 100644
index 0000000..b35f70e
--- /dev/null
+++ b/certificate/templates/drupal_workshop_download.html
@@ -0,0 +1,60 @@
+{% extends 'base.html' %}
+{% block header%}
+ <h1> Drupal Workshop 2016</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 User/Email</h4>
+ </div>
+ <div class="modal-body">
+ {% if notregistered == 1 %}
+ Please enter a proper email address.
+ {% endif %}
+ </div>
+ </div>
+ </div>
+ </div>
+ <form class="col-lg-12" action="{% url 'certificate:drupal_workshop_download' %}" method="post">
+ {% csrf_token %}
+ {{ message }}
+ <hr>
+ <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>
+
+ <div class="modal fade" id="errorModal" tabindex="-1" role="dialog" aria-labelledby="errorModalLabel" 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">Problem in downloading</h4>
+ </div>
+ <div class="modal-body">
+ Sorry could not process your certificate. Kindly contact the FOSSEE team.
+ </div>
+ </div>
+ </div>
+ </div>
+{% endblock %}
+
+{% block javascript %}
+<script>
+ $(document).ready(function(){
+ error = "{{ error }}"
+ if(error == "True"){
+ $("#errorModal").modal();
+ }
+ notreg = "{{ notregistered }}";
+ if(notreg == "1"){
+ $("#invalidModal").modal();
+ }
+ });
+</script>
+{% endblock %}
diff --git a/certificate/templates/index.html b/certificate/templates/index.html
index cb9c716..3380424 100755
--- 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:drupal_workshop_download' %}" >Drupal Workshop 2016</a></li>
<li><a href="{% url 'certificate:esim_workshop_feedback' %}" >eSim Workshop 2016</a></li>
<li><a href="{% url 'certificate:osdag_workshop_feedback' %}" >Osdag Workshop 2016</a></li>
<li><a href="{% url 'certificate:openfoam_symposium_feedback_2016' %}" >OpenFOAM Symposium 2016</a></li>
diff --git a/certificate/urls.py b/certificate/urls.py
index 7c12ff4..7c04519 100755
--- a/certificate/urls.py
+++ b/certificate/urls.py
@@ -34,7 +34,7 @@ urlpatterns = patterns('certificate.views',
url(r'^openfoam_symposium_download_2016/$', 'openfoam_symposium_download_2016', name='openfoam_symposium_download_2016'),
url(r'^openfoam_symposium_feedback_2016/$', 'openfoam_symposium_feedback_2016', name='openfoam_symposium_feedback_2016'),
url(r'^fossee_internship_cerificate_download/$', 'fossee_internship_cerificate_download', name='fossee_internship_cerificate_download'),
-
+ url(r'^drupal_workshop_download/$', 'drupal_workshop_download', name='drupal_workshop_download'),
)
diff --git a/certificate/views.py b/certificate/views.py
index b875e4c..4149c32 100755
--- 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 Osdag_WS, eSim_WS, Internship_participant, 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, OpenFOAM_Symposium_participant_2016, OpenFOAM_Symposium_speaker_2016
+from certificate.models import Drupal_WS, Osdag_WS, eSim_WS, Internship_participant, 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, OpenFOAM_Symposium_participant_2016, OpenFOAM_Symposium_speaker_2016
import subprocess
import os
from string import Template
@@ -126,6 +126,10 @@ def verification(serial, _type):
faculty = Osdag_WS.objects.get(email=certificate.email)
detail = OrderedDict([('Name', name), ('Event', purpose),
('Days', '4 June'), ('Year', year)])
+ elif purpose == 'Drupal Workshop':
+ faculty = Drupal_WS.objects.get(email=certificate.email)
+ detail = OrderedDict([('Name', name), ('Event', purpose),
+ ('Days', '30 July'), ('Year', year)])
elif purpose == 'eSim Workshop':
faculty = eSim_WS.objects.get(email=certificate.email)
detail = OrderedDict([('Name', name), ('Event', purpose),
@@ -248,6 +252,8 @@ def _get_detail(serial_no):
purpose = 'eSim Faculty Meet'
elif serial_no[0:3] == 'OWS':
purpose = 'Osdag Workshop'
+ elif serial_no[0:3] == 'DWS':
+ purpose = 'Drupal Workshop'
elif serial_no[0:3] == 'EWS':
purpose = 'eSim Workshop'
elif serial_no[0:3] == 'OFC':
@@ -1186,6 +1192,107 @@ def create_osdag_workshop_certificate(certificate_path, name, qrcode, type, pape
error = True
return [None, error]
+def drupal_workshop_download(request):
+ context = {}
+ err = ""
+ ci = RequestContext(request)
+ cur_path = os.path.dirname(os.path.realpath(__file__))
+ certificate_path = '{0}/drupal_workshop_template/'.format(cur_path)
+
+ if request.method == 'POST':
+ email = request.POST.get('email').strip()
+ type = request.POST.get('type', 'P')
+ paper = None
+ workshop = None
+ if type == 'P':
+ user = Drupal_WS.objects.filter(email=email)
+ if not user:
+ context["notregistered"] = 1
+ return render_to_response('drupal_workshop_download.html',
+ context, context_instance=ci)
+ else:
+ user = user[0]
+ name = user.name
+ purpose = user.purpose
+ year = '16'
+ 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_drupal_workshop_certificate(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_drupal_workshop_certificate(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('drupal_workshop_download.html', context, ci)
+ context['message'] = ''
+ return render_to_response('drupal_workshop_download.html', context, ci)
+
+def create_drupal_workshop_certificate(certificate_path, name, qrcode, type, paper, workshop, file_name):
+ error = False
+ try:
+ download_file_name = None
+ template = 'template_DWS2016Pcertificate'
+ download_file_name = 'DWS2016Pcertificate.pdf'
+
+ template_file = open('{0}{1}'.format\
+ (certificate_path, template), 'r')
+ content = Template(template_file.read())
+ template_file.close()
+
+ content_tex = content.safe_substitute(name=name['name'].title(),
+ serial_key = name['serial_key'], qr_code=qrcode)
+ 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)
+ 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]
+
def esim_workshop_download(request):
context = {}
err = ""