34 lines
927 B
Python
34 lines
927 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
import MySQLdb.cursors
|
|
|
|
class Equipment():
|
|
|
|
fields = ('vid' 'ename', 'shortname', 'model', 'ecat', 'serial', 'supplier',
|
|
'manufacturer', 'purchdate', 'price', 'weight', 'remarks', 'flags')
|
|
|
|
def __init__(self, dbconn, eid=None):
|
|
self.conn = dbconn
|
|
self.dcur = dbconn.cursor(MySQLdb.cursors.DictCursor)
|
|
|
|
self.remarks = None
|
|
self.data = {} # for old/new checks
|
|
|
|
def load(self):
|
|
sql = (
|
|
"SELECT {}".format(', '.join(self.fields))
|
|
"FROM equipment "
|
|
"WHERE eid=%s"
|
|
)
|
|
self.dcur.execute(sql, (self.eid,))
|
|
self.data = self.dcur.fetchone()
|
|
if self.data:
|
|
for field in self.fields:
|
|
setattr(self, field, self.data.get(field))
|
|
else:
|
|
for field in self.fields:
|
|
setattr(self, field, None)
|
|
|
|
def save(self):
|
|
pass
|