virtual_command_model changes -> model parser needs modification -> also the model relations between recorden model and virtual command may be removed \(not done yet\)

This commit is contained in:
2020-08-14 15:59:24 +02:00
parent b18f9ba616
commit 3ae6db1184
2 changed files with 37 additions and 12 deletions

View File

@@ -34,6 +34,7 @@ virtual_command_recorder_table = db.Table('virtual_command_recorder',
ondelete="CASCADE"),
primary_key=True))
# probably useless!!
# This is the association table for the many-to-many relationship between
# virtual commands and recorder commands.
virtual_command_recorder_model_table = db.Table('virtual_command_recorder_model',
@@ -49,6 +50,9 @@ virtual_command_recorder_model_table = db.Table('virtual_command_recorder_model'
primary_key=True))
# probably useless!!
class VirtualCommand(db.Model):
id = db.Column(db.Integer, autoincrement=True, primary_key=True)
created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow())
@@ -61,15 +65,19 @@ class VirtualCommand(db.Model):
recorder_commands = db.relationship('RecorderCommand', secondary=virtual_command_recorder_command_table,
back_populates='virtual_commands')
_command_default_params_json_string = db.Column(db.UnicodeText, default='')
# probably useless!!
recorder_model_commands = db.relationship('RecorderModel', secondary=virtual_command_recorder_model_table,
back_populates='virtual_commands')
# probably useless!!
# parent_virtual_command = db.relationship('VirtualCommand', back_populates='child_virtual_commands')
parent_virtual_command_id = db.Column(db.Integer, db.ForeignKey('virtual_command.id'))
child_virtual_commands = db.relationship('VirtualCommand',
backref=backref('parent_virtual_command', remote_side=[id]))
command_order_string = db.Column(db.String)
_command_order_json_string = db.Column(db.String, default='')
def __init__(self, **kwargs):
super(VirtualCommand, self).__init__(**kwargs)
@@ -93,13 +101,26 @@ class VirtualCommand(db.Model):
@hybrid_property
def command_order(self):
if self.command_order_string is None:
if self._command_order_json_string is None:
return []
return json.loads(self.command_order_string)
return json.loads(self._command_order_json_string)
@command_order.setter
def command_order(self, ordered_list_of_commands: list):
self.command_order_string = json.dumps(ordered_list_of_commands)
self._command_order_json_string = json.dumps(ordered_list_of_commands)
@hybrid_property
def command_default_params(self) -> list:
return json.loads(self._command_default_params_json_string)
@command_default_params.setter
def command_default_params(self, value: list):
self._command_default_params_json_string = json.dumps(value)
def add_command_default_param(self, param_name: str, value: str):
command_default_params = json.loads(self._command_default_params_json_string)
command_default_params.append({'param_name': param_name, 'value': value})
self._command_default_params_json_string = json.dumps(command_default_params)
def __str__(self):
return self.name