Made db.create_all() conditional
This commit is contained in:
parent
2c5ed21011
commit
dc126459bc
@ -95,48 +95,3 @@ class User(UserMixin, db.Model):
|
||||
db.session.commit()
|
||||
write('users.log', f'User \'{username}\' was deleted.') # TODO add current user
|
||||
|
||||
class Device(db.Model):
|
||||
id = db.Column(db.String(36), primary_key=True)
|
||||
name = db.Column(db.String(128), nullable=False)
|
||||
mac_address = db.Column(db.String(128), nullable=False)
|
||||
ip_address = db.Column(db.String(128), nullable=False)
|
||||
description = db.Column(db.String(250), nullable=True)
|
||||
|
||||
@property
|
||||
def set_name(self): raise AttributeError('set_name is not a readable attribute.')
|
||||
|
||||
set_name.setter
|
||||
def set_name(self, name:str): self.name = encrypt(name)
|
||||
|
||||
def get_name(self): return decrypt(self.name)
|
||||
|
||||
@property
|
||||
def set_mac_address(self): raise AttributeError('set_mac_address is not a readable attribute.')
|
||||
|
||||
set_mac_address.setter
|
||||
def set_mac_address(self, mac_address:str): self.mac_address = encrypt(mac_address)
|
||||
|
||||
def get_mac_address(self): return decrypt(self.mac_address)
|
||||
|
||||
@property
|
||||
def set_ip_address(self): raise AttributeError('set_ip_address is not a readable attribute.')
|
||||
|
||||
set_ip_address.setter
|
||||
def set_ip_address(self, ip_address:str): self.ip_address = encrypt(ip_address)
|
||||
|
||||
def get_ip_address(self): return decrypt(self.ip_address)
|
||||
|
||||
def add(self):
|
||||
db.session.add(self)
|
||||
db.session.commit()
|
||||
write('commands.log', f'Device \'{self.get_name()}\' was added at the IP address \'{self.get_ip_address()}\' and the MAC address \'{self.get_mac_address()}\'.')
|
||||
return True, f'Device {self.get_name()} was added.'
|
||||
|
||||
def delete(self):
|
||||
name = self.get_name()
|
||||
ip_address = self.get_ip_address()
|
||||
mac_address = self.get_mac_address()
|
||||
db.session.delete(self)
|
||||
db.session.commit()
|
||||
write('commands.log', f'Device \'{name}\' with the IP address {ip_address} and MAC address {mac_address} was deleted.')
|
||||
return True, f'Device {name} was deleted.'
|
Loading…
Reference in New Issue
Block a user