def load_info_screen_data(self): "This method runs in main thread and does the backend DB fetching without slowing the UI" today = date.today() info_screen = self.get_screen('info_screen') good_count, bad_count = Deed.get_gb_count(self.db, today) info_screen.lbl_gc_today.text = str(good_count) info_screen.lbl_bc_today.text = str(bad_count) end_date = today start_date = end_date - timedelta(days=today.weekday()) good_count, bad_count = Deed.get_gb_count(self.db, start_date, end_date) info_screen.lbl_gc_week.text = str(good_count) info_screen.lbl_bc_week.text = str(bad_count) last_day_of_month = calendar.monthrange(today.year, today.month)[1] start_date = date(year=today.year, month=today.month, day=1) end_date = date(year=today.year, month=today.month, day=last_day_of_month) good_count, bad_count = Deed.get_gb_count(self.db, start_date, end_date) info_screen.lbl_gc_month.text = str(good_count) info_screen.lbl_bc_month.text = str(bad_count) start_date = date(year=today.year, month=1, day=1) end_date = date(year=today.year, month=12, day=31) good_count, bad_count = Deed.get_gb_count(self.db, start_date, end_date) info_screen.lbl_gc_year.text = str(good_count) info_screen.lbl_bc_year.text = str(bad_count) good_count, bad_count = Deed.get_gb_count(self.db) info_screen.lbl_gc_lifetime.text = str(good_count) info_screen.lbl_bc_lifetime.text = str(bad_count)
def do_action(self, action): "Called for good or bad button presses" rec = Deed() if 'good' == action: rec.good = True elif 'bad' == action: rec.good = False if '' != self.txt_msg.text: rec.description = self.txt_msg.text self.db.add(rec) self.db.commit() self.set_status("Deed saved!") self.txt_msg.text = u'' plyer.notification.notify("Good or Bad?", "Action is " + str(action))
def sync_load_success(self, req, result): self.set_status("Data recieved for sync load!") print(result) if 'deeds' in result: for deed in result['deeds']: print(deed) deed_rec = Deed.from_dict(deed) if not self.db.query(Deed).filter_by(timestamp=deed_rec.timestamp).first(): print("inserting record") self.db.add(deed_rec) else: print("Record already present, not inserting") self.db.commit() print("Deeds loaded from sync server")
def is_user_has_any_deed(user: User) -> bool: return ( Deed.select() .where((Deed.user == user) & (Deed.date_created >= datetime.now() - timedelta(days=2 * 365))) .exists() )