Working kimai filtering, diable requests_cache for now

This commit is contained in:
3wc 2023-10-27 23:27:48 +01:00
parent 4b85921b3e
commit 65f16a252c
3 changed files with 16 additions and 10 deletions

View File

@ -193,9 +193,7 @@ class KimaiScreen(ListScreen):
def _refresh(self, filter_query=None): def _refresh(self, filter_query=None):
self.table.clear() self.table.clear()
projects = KimaiProject.list( projects = KimaiProject.list(self.db_manager, filter_query)
self.db_manager
)
self.table.add_rows( self.table.add_rows(
[ [

View File

@ -242,9 +242,13 @@ class KimaiProject(BaseORM):
self.db_manager.get_conn().commit() self.db_manager.get_conn().commit()
@staticmethod @staticmethod
def list(db_manager): def list(db_manager, filter_query=None):
cursor = db_manager.get_cursor() cursor = db_manager.get_cursor()
cursor.execute(""" where = ""
if filter_query is not None:
where = "WHERE kimai_projects.name LIKE ? or kimai_customers.name like ?"
sql = f"""
SELECT SELECT
kimai_projects.id, kimai_projects.id,
COALESCE(kimai_projects.name, ""), COALESCE(kimai_projects.name, ""),
@ -256,9 +260,13 @@ class KimaiProject(BaseORM):
kimai_customers kimai_customers
ON ON
kimai_customers.id = kimai_projects.customer_id kimai_customers.id = kimai_projects.customer_id
GROUP BY {where}
kimai_customers.id """
""")
if filter_query is not None:
cursor.execute(sql, ("%{}%".format(filter_query),) * 2)
else:
cursor.execute(sql)
rows = cursor.fetchall() rows = cursor.fetchall()
return [KimaiProject(db_manager, row[0], row[1], row[2], row[3]) for row in rows] return [KimaiProject(db_manager, row[0], row[1], row[2], row[3]) for row in rows]

View File

@ -1,5 +1,5 @@
import requests import requests
import requests_cache # import requests_cache
import os import os
@ -20,7 +20,7 @@ class KimaiAPI(object):
} }
def __init__(self): def __init__(self):
requests_cache.install_cache('kimai', backend='sqlite', expire_after=1800) # requests_cache.install_cache('kimai', backend='sqlite', expire_after=1800)
self.customers_json = requests.get( self.customers_json = requests.get(
f'{self.KIMAI_API_URL}/customers?visible=3', headers=self.auth_headers).json() f'{self.KIMAI_API_URL}/customers?visible=3', headers=self.auth_headers).json()
self.projects_json = requests.get( self.projects_json = requests.get(