Native gui first steps: storage, box and companies are editable

This commit is contained in:
thooge committed 2026-10-21 17:16:55 +02:00
1 parent 1eea4058bf
commit 06a9834688
47 files changed
+3119 -883

No files matched your search

+121 -53
View File
@@ -1,14 +1,21 @@
# SPDX-License-Identifier: WTFPL
"""
Dropdowns and database enums
from enum import IntEnum
dropdowns can change
"""
Dropdowns, Database enums and Table numbers
dropdowns contents can change
enums are static
TBD
- language
- dateformat
- dimensions (measurement)
"""
class Dropdown:
class Dropdown(IntEnum):
HULL_TYPE = 1
COMPANY_TYPE = 2
STORAGE_TYPE = 3
@@ -25,54 +32,73 @@ class Dropdown:
BBN_VESSELDATA = 14
MEASUREMENT_CATEGORY = 15
Dependencies = {
HULL_TYPE: (
# unused
),
COMPANY_TYPE: (
('company', 'comptype'),
('company', 'comptype2')
),
STORAGE_TYPE: (
('storage', 'stype'),
),
EQUIPMENT_CATEGORY: (
('equipment', 'ecat'),
),
PROVISION_CATEGORY: (
('provisions', 'provcat'),
),
PROVISION_UNIT: (
('provisions', 'unit'),
),
FUSE_TYPE: (
('fuse', 'ftype'),
),
UNIT: (
('measurement', 'unit'),
),
BOX_TYPE: (
('box', 'boxtype'),
),
FUSE_BLOCK: (
('fuse', 'location'),
),
CABLE_TYPE: (
('cable', 'cabletype'),
),
CABLE_TECHNAME: (
('cable', 'techname'),
),
INVENTORY_CATEGORY: (
('inventory', 'invcat'),
),
BBN_VESSELDATA: (
#unused
),
MEASUREMENT_CATEGORY: (
('measurement', 'mcat'),
)
}
DropdownDeps = {
Dropdown.HULL_TYPE: (
# unused
),
Dropdown.COMPANY_TYPE: (
('company', 'comptype'),
('company', 'comptype2')
),
Dropdown.STORAGE_TYPE: (
('storage', 'stype'),
),
Dropdown.EQUIPMENT_CATEGORY: (
('equipment', 'ecat'),
),
Dropdown.PROVISION_CATEGORY: (
('provisions', 'provcat'),
),
Dropdown.PROVISION_UNIT: (
('provisions', 'unit'),
),
Dropdown.FUSE_TYPE: (
('fuse', 'ftype'),
),
Dropdown.UNIT: (
('measurement', 'unit'),
),
Dropdown.BOX_TYPE: (
('box', 'boxtype'),
),
Dropdown.FUSE_BLOCK: (
('fuse', 'location'),
),
Dropdown.CABLE_TYPE: (
('cable', 'cabletype'),
),
Dropdown.CABLE_TECHNAME: (
('cable', 'techname'),
),
Dropdown.INVENTORY_CATEGORY: (
('inventory', 'invcat'),
),
Dropdown.BBN_VESSELDATA: (
#unused
),
Dropdown.MEASUREMENT_CATEGORY: (
('measurement', 'mcat'),
)
}
class Table(IntEnum):
VESSEL = (1, "base")
USERS = (2, "base")
COMPANIES = (3, "companies")
STORAGE = (4, "storage")
BOXES = (5, "boxes")
EQUIPMENT = (6, "equipment")
#INVENTORY = (7, "inventory")
PROJECTS = (8, "projects")
CABLES = (9, "cables")
FUSES = (10, "fuses")
TAGS = (11, "tags")
def __new__(cls, value, module):
obj = int.__new__(cls, value)
obj._value_ = value
obj.module = module
return obj
class Lookup:
@@ -80,6 +106,7 @@ class Lookup:
self.db = db
self._enums = {}
self._dropdowns = {}
self._revision_ts = {} # tracking list revisions
def load(self):
self._load_enums()
@@ -87,7 +114,7 @@ class Lookup:
def _load_enums(self):
"""
TODO translation via gettext needed
translation via gettext from db schema
"""
db_enums = {
'cable.cablecond': ('cable', 'cablecond'),
@@ -98,8 +125,11 @@ class Lookup:
'document.doctype': ('document', 'doctype'),
'document.roleaccess': ('document', 'roleaccess'),
'dropdown.flags': ('dropdown', 'flags'),
'equipment.econd': ('equipment', 'econd'),
'equipment.flags': ('equipment', 'flags'),
'inventory.conttype': ('inventory', 'conttype'),
'inventory.invcond': ('inventory', 'invcond'),
'inventory.flags': ('inventory', 'flags'),
'maintenance.maintstate': ('maintenance', 'maintstate'),
'measurement.accuracy': ('measurement', 'accuracy'),
'note.notetype': ('note', 'notetype'),
@@ -138,12 +168,27 @@ class Lookup:
self._dropdowns[ddid] = {}
self._dropdowns[ddid][ddval] = ddtext
def reload_dropdown(self, ddid):
self._dropdowns[ddid] = {}
sql = (
"SELECT ddval, ddtext "
"FROM dropdown "
"WHERE ddid=%s "
"ORDER BY sort, ddval"
)
self.db.cur.execute(sql)
for ddval, ddtext in self.db.cur.fetchall():
self._dropdowns[ddid][ddval] = ddtext
def enum(self, name):
return self._enums[name]
def dropdown(self, ddid):
return self._dropdowns[ddid]
def iter_dropdowns(self):
yield from self._dropdowns.keys()
def user(self):
self.db.cur.execute("SELECT userid, displayname FROM user ORDER BY displayname")
return dict(self.db.cur.fetchall())
@@ -181,6 +226,19 @@ class Lookup:
storagelist[row[0]] = "{} ({}) - {}".format(row[1], row[2], row[3])
return storagelist
def box(self, vid):
boxlist = {}
sql = (
"SELECT b.boxid, b.label, b.content "
"FROM box AS b LEFT JOIN storage AS s USING (sid) "
"WHERE s.vid=%s OR s.vid IS NULL "
"ORDER BY b.label"
)
self.db.cur.execute(sql, (vid,))
for row in self.db.cur.fetchall():
boxlist[row[0]] = "{} - {}".format(row[1], row[2])
return boxlist
def equipment(self, vid):
sql = (
"SELECT eid, ename "
@@ -221,6 +279,16 @@ class Lookup:
self.db.cur.execute(sql, (vid,))
return dict(self.db.cur.fetchall())
def project(self, vid):
sql = (
"SELECT projid, projname "
"FROM project "
"WHERE vid=%s "
"ORDER BY projname"
)
self.db.cur.execute(sql, (vid,))
return dict(self.db.cur.fetchall())
def refresh(self):
# TODO ugly hack please improve
self._load_dropdowns()