Exemple #1
0
class TimeClockApp(App):
    session = ObjectProperty()
    time_clock = ObjectProperty()
    time_aux = ObjectProperty()
    last_entry = ObjectProperty()

    def build(self):
        engine = create_engine('sqlite:///time_clock.db')
        Base.metadata.bind = engine
        DBSession = sessionmaker(bind=engine)
        self.session = DBSession()
        self.time_aux = TimeAux()
        self.time_clock = TimeClockRoot()
        self.last_entry = self.get_last_entry()
        Clock.schedule_interval(self.update, 1)
        return self.time_clock

    def update(self, dt):
        self.time_aux.update()

    def get_all(self):
        if self.session.query(func.count(TimeClockEntries.id)).scalar() == 0:
            return []
        return self.session.query(TimeClockEntries).all()

    def add(self, obj):
        self.session.add(obj)
        self.session.commit()

    def add_entry(self):
        entry = TimeClockEntries(time_stamp_in=None,
                                 time_stamp_out=None)
        self.add(entry)
        return entry

    def get_last_entry(self):
        if self.session.query(func.count(TimeClockEntries.id)).scalar() == 0:
            return None
        return self.session.query(TimeClockEntries).order_by(TimeClockEntries.id.desc()).first()

    def on_tap(self, instance):
        if not self.last_entry or self.last_entry.time_stamp_out:
            self.last_entry = self.add_entry()
        time_stamp = self.time_aux.time_stamp()
        if not self.last_entry.time_stamp_in:
            self.last_entry.time_stamp_in = time_stamp
        else:
            self.last_entry.time_stamp_out = time_stamp
        self.session.commit()
        self.time_clock.ids.entries.generate_list_view()

    def add_new(self, time_stamp, action):
        self.session.add(TimeClockTable(time_stamp=time_stamp, action=action))
        self.session.commit()

    def current_date(self):
        return self.time_aux.current_date()
Exemple #2
0
 def build(self):
     engine = create_engine('sqlite:///time_clock.db')
     Base.metadata.bind = engine
     DBSession = sessionmaker(bind=engine)
     self.session = DBSession()
     self.time_aux = TimeAux()
     self.time_clock = TimeClockRoot()
     self.last_entry = self.get_last_entry()
     Clock.schedule_interval(self.update, 1)
     return self.time_clock