From 5f4e96be8845bbb113845f71655d8096d5b98412 Mon Sep 17 00:00:00 2001 From: Tanshu Date: Fri, 30 Nov 2012 23:22:32 +0530 Subject: [PATCH] Forgot to add fingerprint.py to the repository. --- .../static/partial/employee-functions.html | 2 +- brewman/brewman/views/fingerprint.py | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 brewman/brewman/views/fingerprint.py diff --git a/brewman/brewman/static/partial/employee-functions.html b/brewman/brewman/static/partial/employee-functions.html index 9a32304b..05287ab3 100644 --- a/brewman/brewman/static/partial/employee-functions.html +++ b/brewman/brewman/static/partial/employee-functions.html @@ -23,7 +23,7 @@
- +
diff --git a/brewman/brewman/views/fingerprint.py b/brewman/brewman/views/fingerprint.py new file mode 100644 index 00000000..43d710f8 --- /dev/null +++ b/brewman/brewman/views/fingerprint.py @@ -0,0 +1,36 @@ +import csv +import datetime +from io import StringIO +from pyramid.view import view_config +from brewman.models.voucher import Fingerprint + +__author__ = 'tanshu' + +@view_config(request_method='POST', route_name='fingerprint', renderer='json', permission='Authenticated') +def show_list(request): + filename = request.POST['uploadedFile'].filename + input_file = request.POST['uploadedFile'].file + reader = csv.reader(read_file(input_file), delimiter=";") + for row in reader: + add_fingerprint(row) + return filename + + +def read_file(input_file): + input_file.seek(0) + output = "" + while 1: + data = input_file.read(2 << 16) + if not data: + break + output += data.decode('utf-8') + return StringIO(output) + + +def add_fingerprint(row): + try: + employee_code = int(row[0]) + date = datetime.datetime.strptime(row[3] + ' ' + row[4], '%m/%d/%Y %H:%M') + except ValueError: + return + Fingerprint(employee_code=employee_code, date=date).create()