From 2e670c06ecb225535e10c73483a9213fab9b2d4c Mon Sep 17 00:00:00 2001 From: tanshu Date: Mon, 29 Feb 2016 23:41:08 +0530 Subject: [PATCH] Fix: Updated to match the fingerprint uploader to the new attendance machine --- brewman/models/voucher.py | 9 --------- brewman/views/fingerprint.py | 16 +++++++++++----- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/brewman/models/voucher.py b/brewman/models/voucher.py index 3417dd46..f67b2e01 100644 --- a/brewman/models/voucher.py +++ b/brewman/models/voucher.py @@ -351,15 +351,6 @@ class Fingerprint(Base): def query(cls): return DBSession.query(cls) - def create(self): - old = DBSession.query(Fingerprint).filter(Fingerprint.date == self.date) \ - .filter(Fingerprint.employee_id == self.employee_id).first() - if old is None: - DBSession.add(self) - return self - else: - return old - class DbImage(Base): __tablename__ = 'images' diff --git a/brewman/views/fingerprint.py b/brewman/views/fingerprint.py index 62a4329a..d8e5573b 100644 --- a/brewman/views/fingerprint.py +++ b/brewman/views/fingerprint.py @@ -15,7 +15,7 @@ __author__ = 'tanshu' def show_list(request): filename = request.POST['uploadedFile'].filename input_file = request.POST['uploadedFile'].file - reader = csv.reader(read_file(input_file), delimiter=";") + reader = csv.reader(read_file(input_file), delimiter="\t") for row in reader: add_fingerprint(row) transaction.commit() @@ -35,12 +35,18 @@ def read_file(input_file): def add_fingerprint(row): try: - employee_code = int(row[0]) - date = datetime.datetime.strptime(row[3] + ' ' + row[4], '%m/%d/%Y %H:%M') + employee_code = int(row[2]) + date = datetime.datetime.strptime(row[6], '%Y/%m/%d %H:%M:%S') except ValueError: return - employee_id = Employee.by_code(employee_code).id - Fingerprint(employee_id=employee_id, date=date).create() + employee = Employee.by_code(employee_code) + if employee is not None: + fp = Fingerprint(employee_id=employee.id, date=date) + old = DBSession.query(Fingerprint).filter(Fingerprint.date == date) \ + .filter(Fingerprint.employee_id == employee.id).first() + if old is None: + DBSession.add(fp) + def get_prints(employee_id, date):