diff options
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | certificate/__init__.py | 0 | ||||
-rw-r--r-- | certificate/admin.py | 3 | ||||
-rw-r--r-- | certificate/migrations/0001_initial.py | 68 | ||||
-rw-r--r-- | certificate/migrations/0002_certificate_name.py | 20 | ||||
-rw-r--r-- | certificate/migrations/__init__.py | 0 | ||||
-rw-r--r-- | certificate/models.py | 43 | ||||
-rw-r--r-- | certificate/templates/base.html | 39 | ||||
-rw-r--r-- | certificate/templates/download.html | 14 | ||||
-rw-r--r-- | certificate/templates/verify.html | 12 | ||||
-rw-r--r-- | certificate/tests.py | 3 | ||||
-rw-r--r-- | certificate/urls.py | 13 | ||||
-rw-r--r-- | certificate/views.py | 137 | ||||
-rw-r--r-- | fossee_project/__init__.py | 0 | ||||
-rw-r--r-- | fossee_project/urls.py | 13 | ||||
-rw-r--r-- | fossee_project/wsgi.py | 14 | ||||
-rwxr-xr-x | manage.py | 10 |
17 files changed, 394 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..46c5a4e --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.bak +*.*~ +*.pyc +*.swo +*.swp diff --git a/certificate/__init__.py b/certificate/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/certificate/__init__.py diff --git a/certificate/admin.py b/certificate/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/certificate/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/certificate/migrations/0001_initial.py b/certificate/migrations/0001_initial.py new file mode 100644 index 0000000..b802da2 --- /dev/null +++ b/certificate/migrations/0001_initial.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +from django.conf import settings + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Certificate', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('email', models.CharField(max_length=50, null=True, blank=True)), + ('serial_no', models.CharField(max_length=50)), + ('counter', models.IntegerField()), + ], + options={ + }, + bases=(models.Model,), + ), + migrations.CreateModel( + name='Event', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('purpose', models.CharField(max_length=25, choices=[(b'SLC', b'Scilab Conference'), (b'SPC', b'Scipy Conference'), (b'PTC', b'Python Textbook Companion'), (b'STC', b'Scilab Textbook Companion')])), + ('start_date', models.DateTimeField()), + ('end_date', models.DateTimeField()), + ], + options={ + }, + bases=(models.Model,), + ), + migrations.CreateModel( + name='Profile', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('uin', models.CharField(max_length=50)), + ('attendance', models.NullBooleanField()), + ('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)), + ], + options={ + }, + bases=(models.Model,), + ), + migrations.CreateModel( + name='Scilab_import', + fields=[ + ('id', models.IntegerField(serialize=False, primary_key=True)), + ('ticket_number', models.IntegerField(default=0)), + ('name', models.CharField(max_length=50, null=True, blank=True)), + ('email', models.CharField(max_length=50, null=True, blank=True)), + ('ticket', models.CharField(max_length=50, null=True, blank=True)), + ('date', models.CharField(max_length=50, null=True, blank=True)), + ('order_id', models.IntegerField(default=0, null=True, blank=True)), + ('purpose', models.CharField(default=b'SLC', max_length=10)), + ], + options={ + 'managed': True, + }, + bases=(models.Model,), + ), + ] diff --git a/certificate/migrations/0002_certificate_name.py b/certificate/migrations/0002_certificate_name.py new file mode 100644 index 0000000..99f6efc --- /dev/null +++ b/certificate/migrations/0002_certificate_name.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('certificate', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='certificate', + name='name', + field=models.CharField(default='ABC', max_length=100), + preserve_default=False, + ), + ] diff --git a/certificate/migrations/__init__.py b/certificate/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/certificate/migrations/__init__.py diff --git a/certificate/models.py b/certificate/models.py new file mode 100644 index 0000000..b7b8142 --- /dev/null +++ b/certificate/models.py @@ -0,0 +1,43 @@ +from django.db import models +from django.contrib.auth.models import User +# Create your models here. + +events = ( + ('SLC', 'Scilab Conference'), + ('SPC', 'Scipy Conference'), + ('PTC', 'Python Textbook Companion'), + ('STC', 'Scilab Textbook Companion'), + ) + +class Profile(models.Model): + user = models.OneToOneField(User) + # other details + uin = models.CharField(max_length=50) #2 intialletters + 6 hexadigits + attendance = models.NullBooleanField() + +class Event(models.Model): + purpose = models.CharField(max_length=25, choices=events) + start_date = models.DateTimeField() + end_date = models.DateTimeField() + # other details + +class Certificate(models.Model): + name = models.CharField(max_length=100) + email = models.CharField(max_length=50, null=True, blank=True) + serial_no = models.CharField(max_length=50) #purpose+uin+1stletter + counter = models.IntegerField() + +class Scilab_import(models.Model): + ''' Autogenerated model file csvimport Mon Dec 1 07:46:00 2014 ''' + id = models.IntegerField(primary_key=True, null=False) + ticket_number = models.IntegerField(default=0, null=False, blank=False) + name = models.CharField(max_length=50, null=True, blank=True) + email = models.CharField(max_length=50, null=True, blank=True) + ticket = models.CharField(max_length=50, null=True, blank=True) + date = models.CharField(max_length=50, null=True, blank=True) + order_id = models.IntegerField(default=0, null=True, blank=True) + purpose = models.CharField(max_length=10, default='SLC') + + + class Meta: + managed = True diff --git a/certificate/templates/base.html b/certificate/templates/base.html new file mode 100644 index 0000000..2e437f3 --- /dev/null +++ b/certificate/templates/base.html @@ -0,0 +1,39 @@ +{% load compress %} +{% load static %} +<html> + <head> + <title> + {% block title %} + FOSSEE Project + {% endblock %} + </title> + {% compress css %} + <link rel="stylesheet" href="{% static 'website/css/bootstrap.min.css' %}" type="text/css" media="screen" charset="utf-8" /> + {% endcompress %} + </head> + <body> + <div id="page-wrapper"> + <div id="content-wrapper"> + {% block content %} + {% endblock %} + </div> <!-- /#content-wrapper --> + + <div id="footer-wrapper" class="container"> + <div class="pull-left"> + ©2013 <a href="http://fossee.in" target="_blank">fossee.in</a> + </div> + <div class="pull-right"> + Developed at IIT Bombay + </div> + </div> <!-- /#footer-wrapper --> + </div> <!-- /#page-wrapper --> + + {% compress js %} + <script src="{% static 'website/js/jquery.min.js' %}"></script> + <script src="{% static 'website/js/bootstrap.min.js' %}"></script> + {% block javascript %} + <!-- overide with custom javascript --> + {% endblock %} + {% endcompress %} + </body> +</html> diff --git a/certificate/templates/download.html b/certificate/templates/download.html new file mode 100644 index 0000000..3a2fdd1 --- /dev/null +++ b/certificate/templates/download.html @@ -0,0 +1,14 @@ +<html> + <body> + <form action="" method="post"> + + {% csrf_token %} + {{error}} + {{err}} + <center><table class=span1> + Email: <input type=text name=email> + </table></center> + <center><button class="btn" type="submit">Submit</button></center> + </form> + </body> +<html> diff --git a/certificate/templates/verify.html b/certificate/templates/verify.html new file mode 100644 index 0000000..55668d5 --- /dev/null +++ b/certificate/templates/verify.html @@ -0,0 +1,12 @@ +<html> + <body> + <form action="" method="post"> + {{detail}} + {% csrf_token %} + <center><table class=span1> + Serial Number: <input type=text name=serial_no> + </table></center> + <center><button class="btn" type="submit">Submit</button></center> + </form> + </body> +<html> diff --git a/certificate/tests.py b/certificate/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/certificate/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/certificate/urls.py b/certificate/urls.py new file mode 100644 index 0000000..04f2f8a --- /dev/null +++ b/certificate/urls.py @@ -0,0 +1,13 @@ +from django.conf.urls import patterns, include, url + +from django.contrib import admin +admin.autodiscover() + +urlpatterns = patterns('', + # Examples: + # url(r'^$', 'fossee_project.views.home', name='home'), + # url(r'^blog/', include('blog.urls')), + + url(r'^download/', 'certificate.views.download', name='download'), + url(r'^verify/', 'certificate.views.verify', name='verify'), +) diff --git a/certificate/views.py b/certificate/views.py new file mode 100644 index 0000000..32b1358 --- /dev/null +++ b/certificate/views.py @@ -0,0 +1,137 @@ +from django.shortcuts import render +from django.http import HttpResponse +from django.shortcuts import render_to_response +from django.template import RequestContext +from certificate.models import Scilab_import, Certificate, Event +import subprocess +import os +from string import Template + +# Create your views here. +def download(request): + email = request.POST.get('email') + + context = {} + err = "" + ci = RequestContext(request) + cur_path = os.path.dirname(os.path.realpath(__file__)) + certificate_path = '{0}/certificate_template/'.format(cur_path) + + if request.method == 'POST': + try: + user = Scilab_import.objects.get(email=email) + except Scilab_import.DoesNotExist: + return HttpResponse('Entered email is not registered') + name = user.name + purpose = user.purpose + year = '14' + id = int(user.id) + hexa = hex(id).replace('0x','').zfill(6).upper() + type = 'P' + serial_no = '{0}{1}{2}{3}'.format(purpose, year, hexa, type) + qrcode = '{0}\n{1}'.format(name, serial_no) + try: + old_user = Certificate.objects.get(email=email, serial_no=serial_no) + certificate = create_certificate(certificate_path, name, qrcode) + 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) + if not certificate[1]: + certi_obj = Certificate(name=name, email=email, serial_no=serial_no, counter=1) + certi_obj.save() + return certificate[0] + + if certificate[1]: + _clean_certificate_certificate(certificate_path) + context['error'] = True + return render_to_response('download.html', context, ci) + return render_to_response('download.html', context, ci) + +def verify(request): + context = {} + ci = RequestContext(request) + detail = None + if request.method == 'POST': + serial_no = request.POST.get('serial_no') + try: + certificate = Certificate.objects.get(serial_no=serial_no) + except Certificate.DoesNotExist: + return HttpResponse('Invalid Serial Number') + else: + name = certificate.name + purpose, year, type = _get_detail(serial_no) + if type == 'P': + detail = '{0} had attended {1} {2}'.format(name, purpose, year) + elif type == 'A': + detail = '{0} had presented paper in the {1} {2}'.format(name, purpose, year) + elif type == 'E': + detail = '{0} had attended workshop in the {1} {2}'.format(name, purpose, year) + context['detail'] = detail + print detail + return render_to_response('verify.html', context, ci) + return render_to_response('verify.html',{}, ci) + +def _get_detail(serial_no): + if serial_no[0:3] == 'SLC': + purpose = 'Scilab Conference' + elif serial_no[0:3] == 'SPC': + purpose = 'SciPy India' + + if serial_no[3:5] == '14': + year = '2014' + elif serial_no[3:5] == '15': + year = '2015' + + #if serial_no[-1] == 'P': + # type = 'Participant' + #elif serial_no[-1] == 'A': + + #type = 'Paper' + #elif serial_no[-1] == 'W': + # type = 'Workshop' + return purpose, year, serial_no[-1] + + +def create_certificate(certificate_path, name, qrcode): + error = False + try: + template_file = open('{0}template_certificate'.format\ + (certificate_path), 'r') + content = Template(template_file.read()) + template_file.close() + content_tex = content.safe_substitute(name=name, code=qrcode) + create_tex = open('{0}certificate.tex'.format\ + (certificate_path), 'w') + create_tex.write(content_tex) + create_tex.close() + return_value, err = _make_certificate_certificate(certificate_path) + if return_value == 0: + file_name = 'certificate.pdf' + pdf = open('{0}{1}'.format(certificate_path, file_name) , 'r') + response = HttpResponse(content_type='application/pdf') + response['Content-Disposition'] = 'attachment; \ + filename=%s' % (file_name) + response.write(pdf.read()) + _clean_certificate_certificate(certificate_path) + return [response, False] + else: + error = True + except Exception, e: + error = True + return [None, error] + +def _clean_certificate_certificate(path): + clean_process = subprocess.Popen('make -C {0} clean'.format(path), + shell=True) + clean_process.wait() + +def _make_certificate_certificate(path): + process = subprocess.Popen('timeout 15 make -C {0} certificate'.format(path), + stderr = subprocess.PIPE, shell = True) + err = process.communicate()[1] + return process.returncode, err + + return HttpResponse("DOWNLAOD") diff --git a/fossee_project/__init__.py b/fossee_project/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/fossee_project/__init__.py diff --git a/fossee_project/urls.py b/fossee_project/urls.py new file mode 100644 index 0000000..162dd5d --- /dev/null +++ b/fossee_project/urls.py @@ -0,0 +1,13 @@ +from django.conf.urls import patterns, include, url + +from django.contrib import admin +admin.autodiscover() + +urlpatterns = patterns('', + # Examples: + # url(r'^$', 'fossee_project.views.home', name='home'), + # url(r'^blog/', include('blog.urls')), + + url(r'^admin/', include(admin.site.urls)), + url(r'^certificate/', include('certificate.urls')), +) diff --git a/fossee_project/wsgi.py b/fossee_project/wsgi.py new file mode 100644 index 0000000..621d5df --- /dev/null +++ b/fossee_project/wsgi.py @@ -0,0 +1,14 @@ +""" +WSGI config for fossee_project project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/ +""" + +import os +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fossee_project.settings") + +from django.core.wsgi import get_wsgi_application +application = get_wsgi_application() diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..83dddfe --- /dev/null +++ b/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fossee_project.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) |