Add model base class and models
- Add Model base class with get_next_id() method - Add Preset model with CRUD operations - Add Profile model with tabs and palette support - Add Group model for device grouping - Add Sequence model for preset sequencing - Add Tab model for organizing device controls - Add Palette model for color collections
This commit is contained in:
40
src/models/profile.py
Normal file
40
src/models/profile.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from models.model import Model
|
||||
|
||||
class Profile(Model):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def create(self, name=""):
|
||||
next_id = self.get_next_id()
|
||||
self[next_id] = {
|
||||
"name": name,
|
||||
"tabs": {},
|
||||
"palette": [],
|
||||
"tab_order": []
|
||||
}
|
||||
self.save()
|
||||
return next_id
|
||||
|
||||
def read(self, id):
|
||||
id_str = str(id)
|
||||
return self.get(id_str, None)
|
||||
|
||||
def update(self, id, data):
|
||||
id_str = str(id)
|
||||
if id_str not in self:
|
||||
return False
|
||||
self[id_str].update(data)
|
||||
self.save()
|
||||
return True
|
||||
|
||||
def delete(self, id):
|
||||
id_str = str(id)
|
||||
if id_str not in self:
|
||||
return False
|
||||
self.pop(id_str)
|
||||
self.save()
|
||||
return True
|
||||
|
||||
def list(self):
|
||||
return list(self.keys())
|
||||
|
||||
Reference in New Issue
Block a user