diff --git a/Dockerfile b/Dockerfile index b8c22d4..f98dad4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,12 @@ FROM python:3.13-slim +#ENV PYTHONPATH=/usr/lib/python3/dist-packages +RUN python3 -m venv venv COPY requirements.txt ./ -RUN pip3 install -r requirements.txt +RUN ./venv/bin/pip install --no-cache-dir -r requirements.txt +#RUN pip3 install -r requirements.txt COPY *.py *.txt *.toml ./ COPY inventory ./inventory -CMD ["rio", "run", "--release", "--public", "--port", "8000"] +#ENV PYTHONPATH=/inventory +CMD ["./venv/bin/python3", "-m", "rio", "run", "--release", "--public", "--port", "8000"] EXPOSE 8000 \ No newline at end of file diff --git a/db_classes.py b/db_classes.py index 877cb9d..8e9206a 100644 --- a/db_classes.py +++ b/db_classes.py @@ -1,7 +1,12 @@ from peewee import * from search import InventorySearch as ivs +from playhouse.shortcuts import ReconnectMixin -db = MySQLDatabase('inventory', thread_safe=True, user='inventory', password='nfrwnfprifbwef', host='database', port=3306) +class ReconnectMySQLDatabase(ReconnectMixin, MySQLDatabase): + pass + +# auto-reconnect if mysql disconnects +db = ReconnectMySQLDatabase('inventory', thread_safe=True, user='inventory', password='nfrwnfprifbwef', host='database', port=3306) search = None class user(Model): @@ -144,7 +149,8 @@ def create_item(fullname, serial, officename, barcode, locationid=None, descript if loc == False: loc = None else: - print("Found location: " + loc.name) + pass + #print("Found location: " + loc.name) off = office.select().where(office.name == officename)[0] itm = item(office=off, barcode=barcode, fullname=fullname, description=description, loc=loc, serial=serial, mac=mac, fwver=fwver, manufacturer=manufacturer) itm.save(force_insert=True) @@ -156,7 +162,7 @@ def create_item(fullname, serial, officename, barcode, locationid=None, descript except: pass search.add_document(itmdict) - print("item: " + itm.fullname) + print("added item: " + itm.fullname) return itm except IntegrityError: print("Duplicate item " + fullname) @@ -174,7 +180,8 @@ def update_item(fullname, serial, officename, barcode, locationid=None, descript if loc == False: loc = None else: - print("Found location: " + loc.name) + pass + #print("Found location: " + loc.name) off = office.select().where(office.name == officename)[0] itm = item(office=off, barcode=barcode, fullname=fullname, description=description, loc=loc, serial=serial, mac=mac, fwver=fwver, manufacturer=manufacturer) itm.save() @@ -186,7 +193,7 @@ def update_item(fullname, serial, officename, barcode, locationid=None, descript except: pass search.add_document(itmdict) - print("item: " + itm.fullname) + print("updated item: " + itm.fullname) return itm except IntegrityError: print("Duplicate item " + fullname) @@ -215,7 +222,7 @@ def create_component(parentitem, name, barcode, serial=None, description=None): try: cmp = component(owner=itm, name=name, barcode=barcode, description=description, serial=serial) cmp.save(force_insert=True) - print("component: " + cmp.name) + print("added component: " + cmp.name) return cmp except IntegrityError: print("Duplicate component " + name) @@ -347,6 +354,12 @@ def user_login(username, password): return user.password == password else: return False + +def check_db_connection(): + query = office.select() + if len(query) > 0: + # require the query to fire by checking it's return length + pass def test(): costa = create_user("Costa Aralis", "caralpwtwfpis", "12345") diff --git a/inventory/__init__.py b/inventory/__init__.py index e9be5e8..45162f9 100644 --- a/inventory/__init__.py +++ b/inventory/__init__.py @@ -75,3 +75,4 @@ app = rio.App( assets_dir=Path(__file__).parent / "assets", ) +#app.run_as_web_server(host='0.0.0.0',port=8000) \ No newline at end of file diff --git a/inventory/pages/browse_page.py b/inventory/pages/browse_page.py index 5adcc72..68e9c03 100644 --- a/inventory/pages/browse_page.py +++ b/inventory/pages/browse_page.py @@ -52,6 +52,7 @@ class BrowsePage(rio.Component): @rio.event.on_populate async def _search(self, query=searchtext): self.office = self.session[comps.Settings].office + #print("Office:",self.office) self.filters['office'] = self.office diff --git a/requirements.txt b/requirements.txt index 8d5ad65..b19d41c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ peewee pymysql rio-ui==0.10.4 meilisearch #==0.31.5 -mac-vendor-lookup \ No newline at end of file +mac-vendor-lookup +