summaryrefslogtreecommitdiff
path: root/certificate/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'certificate/views.py')
-rwxr-xr-xcertificate/views.py115
1 files changed, 113 insertions, 2 deletions
diff --git a/certificate/views.py b/certificate/views.py
index 6a0ffb6..4e5819f 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 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 Osdag_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
@@ -122,6 +122,10 @@ 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 == 'Osdag Workshop':
+ faculty = Osdag_WS.objects.get(email=certificate.email)
+ detail = OrderedDict([('Name', name), ('Event', purpose),
+ ('Days', '4 June'), ('Year', year)])
elif purpose == 'SciPy India':
detail = OrderedDict([('Name', name), ('Event', purpose),
('Days', '14 - 16 December'), ('Year', year)])
@@ -238,6 +242,8 @@ def _get_detail(serial_no):
purpose = 'Scilab Arduino Workshop'
elif serial_no[0:3] == 'ESM':
purpose = 'eSim Faculty Meet'
+ elif serial_no[0:3] == 'OWS':
+ purpose = 'Osdag Workshop'
elif serial_no[0:3] == 'OFC':
purpose = 'OpenFOAM Symposium'
elif serial_no[0:3] == 'FIC':
@@ -646,6 +652,7 @@ def create_drupal_certificate(certificate_path, name, qrcode, type, paper, works
return [None, error]
+
def tbc_freeeda_download(request):
context = {}
err = ""
@@ -1035,10 +1042,114 @@ def create_arduino_certificate(certificate_path, name, qrcode, type, paper, work
return [None, error]
+def osdag_workshop_download(request):
+ context = {}
+ err = ""
+ ci = RequestContext(request)
+ cur_path = os.path.dirname(os.path.realpath(__file__))
+ certificate_path = '{0}/osdag_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 = Osdag_WS.objects.filter(email=email)
+ if not user:
+ context["notregistered"] = 1
+ return render_to_response('osdag_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_osdag_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_osdag_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('osdag_workshop_download.html', context, ci)
+ context['message'] = ''
+ return render_to_response('osdag_workshop_download.html', context, ci)
+
+def osdag_workshop_feedback(request):
+ return render_to_response('osdag_workshop_feedback.html')
+
+def create_osdag_workshop_certificate(certificate_path, name, qrcode, type, paper, workshop, file_name):
+ error = False
+ try:
+ download_file_name = None
+ template = 'template_OWS2016Pcertificate'
+ download_file_name = 'OWS2016Pcertificate.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_google_feedback(request):
return render_to_response('esim_google_feedback.html')
-
def esim_download(request):
context = {}
err = ""