diff options
Diffstat (limited to 'certificate/views.py')
-rwxr-xr-x | certificate/views.py | 223 |
1 files changed, 219 insertions, 4 deletions
diff --git a/certificate/views.py b/certificate/views.py index 7ec08d0..19c161b 100755 --- a/certificate/views.py +++ b/certificate/views.py @@ -2,13 +2,17 @@ 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 Drupal_WS, Osdag_WS, eSim_WS, Internship_participant,Internship16_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, Scipy_TA_2016, Scipy_participant_2016, Scipy_speaker_2016, Scipy_workshop_2016, eSim_WS, Internship_participant,Internship16_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 import hashlib from certificate.forms import FeedBackForm from collections import OrderedDict +from django.core.mail import EmailMultiAlternatives +from django.views.decorators.csrf import csrf_exempt + + # Create your views here. def index(request): @@ -137,6 +141,9 @@ def verification(serial, _type): elif purpose == 'SciPy India': detail = OrderedDict([('Name', name), ('Event', purpose), ('Days', '14 - 16 December'), ('Year', year)]) + elif purpose == 'SciPy India 2016': + detail = OrderedDict([('Name', name), ('Event', purpose), + ('Days', '10 - 11 December'), ('Year', year)]) elif purpose == 'OpenFOAM Symposium': detail = OrderedDict([('Name', name), ('Event', purpose), ('Days', '27 February'), ('Year', year)]) @@ -158,11 +165,13 @@ def verification(serial, _type): ('Project', 'FreeEDA Textbook Companion'), ('Books completed', ','.join(books))]) else: detail = '{0} had attended {1} {2}'.format(name, purpose, year) - elif type == 'A': + elif type == 'A' or type == 'T': 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 purpose == 'SciPy India 2016': + detail = OrderedDict([('Name', name), ('Event', purpose), ('paper', paper), ('Days', '10 - 11 December'), ('Year', year)]) elif purpose == 'OpenFOAM Symposium': detail = OrderedDict([('Name', name), ('Event', purpose), ('paper', paper), ('Days', '27 February'), ('Year', year)]) elif purpose == 'FOSSEE Internship': @@ -216,9 +225,9 @@ def verification(serial, _type): detail['Year'] = year else: detail = '{0} had attended {1} {2}'.format(name, purpose, year) - elif type == 'A': + elif type == 'A' or type == 'T': detail = '{0} had presented paper on {3} in the {1} {2}'.format(name, purpose, year, paper) - elif type == 'W': + elif type == 'W' : detail = '{0} had attended workshop on {3} in the {1} {2}'.format(name, purpose, year, workshop) context['detail'] = detail except Certificate.DoesNotExist: @@ -247,6 +256,8 @@ def _get_detail(serial_no): purpose = 'Scilab Conference' elif serial_no[0:3] == 'SPC': purpose = 'SciPy India' + elif serial_no[0:3] == 'S16': + purpose = 'SciPy India 2016' elif serial_no[0:3] == 'DCM': purpose = 'DrupalCamp Mumbai' elif serial_no[0:3] == 'FET': @@ -336,6 +347,8 @@ def _make_certificate_certificate(path, type, file_name): command = 'paper_cert' elif type == 'W': command = 'workshop_cert' + elif type == 'T': + command = 'workshop_cert' process = subprocess.Popen('timeout 15 make -C {0} {1} file_name={2}'.format(path, command, file_name), stderr = subprocess.PIPE, shell = True) err = process.communicate()[1] @@ -1264,12 +1277,14 @@ def drupal_workshop_download(request): if certificate[1]: _clean_certificate_certificate(certificate_path, file_name) context['error'] = True + context['err'] = certificate[0] 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 + err = None try: download_file_name = None template = 'template_DWS2016Pcertificate' @@ -1709,6 +1724,206 @@ def create_scipy_certificate_2015(certificate_path, name, qrcode, type, paper, w error = True return [None, error] +@csrf_exempt +def scipy_feedback_2016(request): + return render_to_response('scipy_feedback_2016.html') + + +@csrf_exempt +def scipy_download_2016(request): + context = {} + err = "" + ci = RequestContext(request) + cur_path = os.path.dirname(os.path.realpath(__file__)) + certificate_path = '{0}/scipy_template_2016/'.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_2016.objects.filter(email=email) + if not user: + context["notregistered"] = 1 + return render_to_response('scipy_download_2016.html', context, context_instance=ci) + else: + user = user[0] + paper = "paper name temporary" + elif type == 'A': + if paper: + user = Scipy_speaker_2016.objects.filter(email=email, paper=paper) + if user: + user = [user[0]] + else: + user = Scipy_speaker_2016.objects.filter(email=email) + if not user: + context["notregistered"] = 1 + return render_to_response('scipy_download_2016.html', context, context_instance=ci) + if len(user) > 1: + context['user_papers'] = user + context['v'] = 'paper' + return render_to_response('scipy_download_2016.html', context, context_instance=ci) + else: + user = user[0] + paper = user.paper + elif type == 'W': + if paper: + user = Scipy_workshop_2016.objects.filter(email=email, paper=paper) + if user: + user = [user[0]] + else: + user = Scipy_workshop_2016.objects.filter(email=email) + if not user: + context["notregistered"] = 1 + return render_to_response('scipy_download_2016.html', context, context_instance=ci) + if len(user) > 1: + context['user_papers'] = user + context['v'] = 'paper' + return render_to_response('scipy_download_2016.html', context, context_instance=ci) + else: + user = user[0] + paper = user.paper + elif type == 'T': + if paper: + user = Scipy_TA_2016.objects.filter(email=email, paper=paper) + if user: + user = [user[0]] + else: + user = Scipy_TA_2016.objects.filter(email=email) + if not user: + context["notregistered"] = 1 + return render_to_response('scipy_download_2016.html', context, context_instance=ci) + if len(user) > 1: + context['user_papers'] = user + context['v'] = 'paper' + return render_to_response('scipy_download_2016.html', context, context_instance=ci) + else: + user = user[0] + paper = user.paper + name = user.name + email = user.email + 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, 'email' : email} + certificate = create_scipy_certificate_2016(certificate_path, details, qrcode, type, paper, workshop, file_name) + if not certificate[1]: + old_user.counter = old_user.counter + 1 + old_user.save() + context['error'] = False + return render_to_response( 'scipy_download_2016.html', context) + 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, 'email': email} + certificate = create_scipy_certificate_2016(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 render(request, 'scipy_download_2016.html') + + if certificate[1]: + _clean_certificate_certificate(certificate_path, file_name) + context['error'] = True + return render_to_response('scipy_download_2016.html', context, ci) + context['message'] = '' + return render_to_response('scipy_download_2016.html', context, ci) + + +@csrf_exempt +def create_scipy_certificate_2016(certificate_path, name, qrcode, type, paper, workshop, file_name): + error = False + try: + download_file_name = None + if type == 'P': + template = 'template_SPC2016Pcertificate' + download_file_name = 'SPC2016Pcertificate.pdf' + elif type == 'W': + template = 'template_SPC2016Wcertificate' + download_file_name = 'SPC2016Wcertificate.pdf' + elif type == 'A': + template = 'template_SPC2016Acertificate' + download_file_name = 'SPC2016Acertificate.pdf' + elif type == 'T': + template = 'template_SPC2016Tcertificate' + download_file_name = 'SPC2016Tcertificate.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) + elif type == 'W': + content_tex = content.safe_substitute(name=name['name'].title(), + serial_key=name['serial_key'], qr_code=qrcode, paper=paper) + elif type == 'T': + 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) + + + if return_value == 0: + pdf = open('{0}{1}.pdf'.format(certificate_path, file_name) , 'r') + path = os.path.join(certificate_path, str(file_name)+ ".pdf") + + try : + sender_name = "scipy" + sender_email = "scipy@fossee.in" + subject = "SciPy India 2016 - Certificate" + to = ['scipy@fossee.in', name['email'],] + + message = """ Dear Participant,<br>Please find attached the participation certificate for SciPy India 2016.<br>If you wish to print this certificate, for optimal printing, please follow these instructions:<br><br>Recommended Paper: Ivory (Matt or Glossy) White <br>Recommended GSM: Minimum of 170<br>Size: Letter size (8.5 x 11 in)<br>Print Settings: Fit to page<br><br>Regards,<br>SciPy India Team + """ + email = EmailMultiAlternatives( + subject,'', + sender_email, to, + headers={"Content-type":"text/html;charset=iso-8859-1"} + ) + email.attach_alternative(message, "text/html") + email.attach_file(path) + email.send(fail_silently=True) + + except Exception as e: + pass + _clean_certificate_certificate(certificate_path, file_name) + return [None, False] + else: + error = True + + except Exception, e: + error = True + return [None, error] + ############################################################################### # OpenFOAM Symposium 2016 |