Forgot to add fingerprint.py to the repository.

This commit is contained in:
Tanshu 2012-11-30 23:22:32 +05:30
parent 8331b18cce
commit 5f4e96be88
2 changed files with 37 additions and 1 deletions

View File

@ -23,7 +23,7 @@
<label for="uploadFingerprints" class="control-label"></label>
<div class="controls">
<input type="file" id="uploadFingerprints" ng-model="upFile" onchange="angular.element(this).scope().setFile(this)" />
<input type="file" id="uploadFingerprints" onchange="angular.element(this).scope().setFile(this)" />
<button class="btn" ng-click="uploadFingerprints()">Upload</button>
</div>
</div>

View File

@ -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()