From ade9e9f78290072a184752a48ccee220d1ef371a Mon Sep 17 00:00:00 2001 From: prathamesh Date: Fri, 5 Dec 2014 15:50:09 +0530 Subject: Modified make file. Make file takes file name as an argument. Now multiple calls can be made to make file since it will execute different file names. So if multiple users cals for certificate at the same time, then there wont be a problem. --- certificate/certificate_template/Makefile | 22 ++++++-------- certificate/certificate_template/iitb-logo.png | Bin 56700 -> 50099 bytes certificate/views.py | 40 +++++++++++++------------ 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/certificate/certificate_template/Makefile b/certificate/certificate_template/Makefile index a032d23..22b221c 100644 --- a/certificate/certificate_template/Makefile +++ b/certificate/certificate_template/Makefile @@ -19,23 +19,19 @@ help: @echo "help Show this help." @echo "" -# certificate -participant_cert: SLC2014Pcertificate.pdf - -SLC2014Pcertificate.pdf: SLC2014Pcertificate.tex fossee-logo.png bashful.sty - pdflatex -shell-escape SLC2014Pcertificate.tex +name = $(file_name) -paper_cert: SLC2014Acertificate.pdf - -SLC2014Acertificate.pdf: SLC2014Acertificate.tex fossee-logo.png bashful.sty - pdflatex -shell-escape SLC2014Acertificate.tex +# certificate +participant_cert: $(name).tex fossee-logo.png bashful.sty + pdflatex -shell-escape $(name).tex -workshop_cert: SLC2014Wcertificate.pdf +paper_cert: $(name).tex fossee-logo.png bashful.sty + pdflatex -shell-escape $(name).tex -SLC2014Wcertificate.pdf: SLC2014Wcertificate.tex fossee-logo.png bashful.sty - pdflatex -shell-escape SLC2014Wcertificate.tex +workshop_cert: $(name).tex fossee-logo.png bashful.sty + pdflatex -shell-escape $(name).tex clean: @echo "removing all tmp+pdf files" - -rm -rvf *.pdf *~ *.aux *.log *.vrb *.out *.toc *.nav *.snm + -rm -rvf $(name)*.pdf *~ $(name).aux $(name).log $(name).tex *.vrb *.out *.toc *.nav *.snm -rm -rvf *.std* *.sh diff --git a/certificate/certificate_template/iitb-logo.png b/certificate/certificate_template/iitb-logo.png index 89ec1cc..2915da3 100644 Binary files a/certificate/certificate_template/iitb-logo.png and b/certificate/certificate_template/iitb-logo.png differ diff --git a/certificate/views.py b/certificate/views.py index 5f642a5..2539c4f 100644 --- a/certificate/views.py +++ b/certificate/views.py @@ -52,7 +52,6 @@ def download(request): if not user: context["notregistered"] = 1 return render_to_response('download.html', context, context_instance=ci) - print user if len(user) > 1: context['workshops'] = user context['v'] = 'workshop' @@ -67,22 +66,24 @@ def download(request): hexa = hex(id).replace('0x','').zfill(6).upper() serial_no = '{0}{1}{2}{3}'.format(purpose, year, hexa, type) qrcode = '{0}\n{1}'.format(name, serial_no) + file_name = '{0}{1}'.format(email,id) + file_name = file_name.replace('.', '') try: old_user = Certificate.objects.get(email=email, serial_no=serial_no) - certificate = create_certificate(certificate_path, name, qrcode, type, paper, workshop) + certificate = create_certificate(certificate_path, name, 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: - certificate = create_certificate(certificate_path, name, qrcode, type, paper, workshop) + certificate = create_certificate(certificate_path, name, 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) certi_obj.save() return certificate[0] if certificate[1]: - _clean_certificate_certificate(certificate_path) + _clean_certificate_certificate(certificate_path, file_name) context['error'] = True return render_to_response('download.html', context, ci) return render_to_response('download.html', context, ci) @@ -134,43 +135,44 @@ def _get_detail(serial_no): return purpose, year, serial_no[-1] -def create_certificate(certificate_path, name, qrcode, type, paper=None, workshop=None): - error = False +def create_certificate(certificate_path, name, qrcode, type, paper, workshop, file_name): + error = False try: + download_file_name = None if type == 'P': template = 'template_SLC2014Pcertificate' - file_name = 'SLC2014Pcertificate' + download_file_name = 'SLC2014Pcertificate.pdf' elif type == 'A': template = 'template_SLC2014Acertificate' - file_name = 'SLC2014Acertificate' + download_file_name = 'SLC2014Acertificate.pdf' elif type == 'W': template = 'template_SLC2014Wcertificate' - file_name = 'SLC2014Wcertificate' + download_file_name = 'SLC2014Wcertificate.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, code=qrcode) + content_tex = content.safe_substitute(name=name, qr_code=qrcode) elif type == 'A': - content_tex = content.safe_substitute(name=name, code=qrcode, + content_tex = content.safe_substitute(name=name, qr_code=qrcode, paper=paper) elif type == 'W': - content_tex = content.safe_substitute(name=name, code=qrcode, + content_tex = content.safe_substitute(name=name, qr_code=qrcode, workshop=workshop) 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) + 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' % (file_name) + filename=%s' % (download_file_name) response.write(pdf.read()) - _clean_certificate_certificate(certificate_path) + _clean_certificate_certificate(certificate_path, file_name) return [response, False] else: error = True @@ -179,19 +181,19 @@ def create_certificate(certificate_path, name, qrcode, type, paper=None, worksho error = True return [None, error] -def _clean_certificate_certificate(path): - clean_process = subprocess.Popen('make -C {0} clean'.format(path), +def _clean_certificate_certificate(path, file_name): + clean_process = subprocess.Popen('make -C {0} clean file_name={1}'.format(path, file_name), shell=True) clean_process.wait() -def _make_certificate_certificate(path, type): +def _make_certificate_certificate(path, type, file_name): if type == 'P': command = 'participant_cert' elif type == 'A': command = 'paper_cert' elif type == 'W': command = 'workshop_cert' - process = subprocess.Popen('timeout 15 make -C {0} {1}'.format(path, command), + 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] return process.returncode, err -- cgit