Add edit page, dialog based item page. Consider switching to popups.

This commit is contained in:
Cole Deck
2024-12-20 21:40:24 +00:00
parent 2a8de79adb
commit 27169ff8a0
16 changed files with 686 additions and 137 deletions

View File

@@ -24,7 +24,7 @@ class office(Model):
class location(Model):
name = CharField()
locationid = AutoField()
locationid = CharField(unique=True, primary_key=True)
description = CharField(null=True)
parent = ForeignKeyField('self', null=True, backref="sublocations")
@@ -42,6 +42,7 @@ class item(Model):
description = CharField(null=True)
serial = CharField(null=True)
checkout = BooleanField(default=False)
checkout_loc = ForeignKeyField(location, backref="items_checkedout_here", null=True)
checkout_user = ForeignKeyField(user, backref="items_held", null=True)
checkout_start = DateTimeField(null=True)
checkout_end = DateTimeField(null=True)
@@ -70,7 +71,13 @@ class component(Model):
def init():
print("Connecting to database...")
db.connect()
import time
while True:
try:
db.connect()
break
except:
time.sleep(1)
print("Checking & creating tables...")
db.create_tables([location, office, item, component, user])
print("Database initialized.")
@@ -81,6 +88,10 @@ def init():
#print(add)
#print(type(add))
for itm in add:
try:
itm["location"] = item.select().where(item.barcode==itm["barcode"])[0].loc.name
except:
pass
print(itm)
#print(type(itm))
search.add_document(itm)
@@ -115,17 +126,65 @@ def search_item(query, filters: dict={}):
def find_item(barcode):
return search.get_barcode(barcode)
def create_item(fullname, serial, officename, barcode, location=None, description=None, manufacturer=None, mac=None, fwver=None):
def find_item_location(barcode):
try:
return item.select().where(item.barcode==barcode).loc
except:
return False
def create_item(fullname, serial, officename, barcode, locationid=None, description=None, manufacturer=None, mac=None, fwver=None):
try:
off = office(name=officename)
off.save(force_insert=True)
except IntegrityError:
pass
try:
loc = get_location_id(locationid)
if loc == False:
loc = None
else:
print("Found location: " + loc.name)
off = office.select().where(office.name == officename)[0]
itm = item(office=off, barcode=barcode, fullname=fullname, description=description, loc=location, serial=serial, mac=mac, fwver=fwver, manufacturer=manufacturer)
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)
search.add_document(item.select().where(item.barcode==barcode).dicts()[0])
itmdict= item.select().where(item.barcode==barcode).dicts()[0]
try:
itmdict["location"] = loc.name
#print(locationid)
#print(itmdict["location"])
except:
pass
search.add_document(itmdict)
print("item: " + itm.fullname)
return itm
except IntegrityError:
print("Duplicate item " + fullname)
return False
def update_item(fullname, serial, officename, barcode, locationid=None, description=None, manufacturer=None, mac=None, fwver=None):
try:
off = office(name=officename)
off.save(force_insert=True)
except IntegrityError:
pass
try:
loc = get_location_id(locationid)
if loc == False:
loc = None
else:
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()
itmdict= item.select().where(item.barcode==barcode).dicts()[0]
try:
itmdict["location"] = loc.name
#print(locationid)
#print(itmdict["location"])
except:
pass
search.add_document(itmdict)
print("item: " + itm.fullname)
return itm
except IntegrityError:
@@ -196,7 +255,7 @@ def checkout(user, barcode, loc=None):
if itm:
itm.checkout = True
itm.checkout_user = user
itm.loc = loc
itm.checkout_loc = loc
itm.save()
return itm
else:
@@ -207,19 +266,21 @@ def checkin(user, barcode, loc=None):
if itm:
itm.checkout = False
itm.last_user = user
itm.loc = loc
if loc is not None:
itm.loc = loc
itm.save()
return itm
else:
return False
def create_location(name, parent=None):
if parent is not None:
loc = location(name=name, parent=parent)
loc.save()
def create_location(name, barcode, parent=None, description=None):
try:
loc = location(name=name, locationid=barcode, parent=parent, description=description)
loc.save(force_insert=True)
print(loc.name, loc.locationid)
return loc
else:
except:
return False
def _find_parent(loc, parent):
@@ -247,6 +308,21 @@ def get_location(name, parent=None):
return False
except:
return False
def get_location_id(barcode):
try:
print("str" + barcode + "str")
if len(barcode) > 0:
query = location.select()
for loc in query:
print(loc.name, loc.locationid)
if loc.locationid == barcode:
return loc
return False
else:
return False
except:
return False
def get_user(name):
query = user.select().where(user.username == name)