diff options
Diffstat (limited to 'certificate/views.py')
-rwxr-xr-x | certificate/views.py | 132 |
1 files changed, 67 insertions, 65 deletions
diff --git a/certificate/views.py b/certificate/views.py index b3d6c5e..a82bcc0 100755 --- a/certificate/views.py +++ b/certificate/views.py @@ -1823,55 +1823,16 @@ def scipy_download_2016(request): 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_2016(certificate_path, details, qrcode, type, paper, workshop, file_name) - # print "==========", certificate[1] - # if not certificate[1]: - # old_user.counter = old_user.counter + 1 - # old_user.save() - # return render(request, 'scipy_download_2016.html') - # 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_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) - - - - 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_2016(certificate_path, details, qrcode, type, paper, workshop, file_name) + print "==========", certificate[1] if not certificate[1]: old_user.counter = old_user.counter + 1 old_user.save() - return certificate[0] + return render(request, 'scipy_download_2016.html') except Certificate.DoesNotExist: uniqueness = False num = 5 @@ -1890,7 +1851,7 @@ def scipy_download_2016(request): 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] + return render(request, 'scipy_download_2016.html') if certificate[1]: _clean_certificate_certificate(certificate_path, file_name) @@ -1900,6 +1861,45 @@ def scipy_download_2016(request): return render_to_response('scipy_download_2016.html', context, ci) + + + # 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_2016(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_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 certificate[0] + + # 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) + + def create_scipy_certificate_2016(certificate_path, name, qrcode, type, paper, workshop, file_name): error = False try: @@ -1932,34 +1932,36 @@ def create_scipy_certificate_2016(certificate_path, name, qrcode, type, paper, 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 + 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()) + path = os.path.join(certificate_path, str(file_name)+ ".pdf") + print "path-------------", path + try : + subject = 'subject' + from_email = 'from_email@gmail.com' + to = ['inbox.komal@gmail.com',] + message = path + msg = EmailMultiAlternatives(subject, message, from_email, [to]) + # msg.attach_file(path) + msg.content_subtype = "html" + msg.send() + except Exception as e: + print e _clean_certificate_certificate(certificate_path, file_name) - return [response, False] + return [None, False] else: error = True - # 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") - # print "path-------------", path - # try : - # subject = 'subject' - # from_email = 'from_email@gmail.com' - # to = ['inbox.komal@gmail.com',] - # message = path - # msg = EmailMultiAlternatives(subject, message, from_email, [to]) - # msg.attach_file(path) - # msg.content_subtype = "html" - # msg.send() - # except Exception as e: - # print e - # return [None, False] - # else: - # error = True except Exception, e: error = True return [None, error] |