mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-08-12 17:57:43 +00:00
(Added) groups add function.
This commit is contained in:
@@ -93,9 +93,43 @@ class Destination(BaseModel):
|
||||
def __str__(self) -> str:
|
||||
return f"{self.path}"
|
||||
|
||||
class Group(BaseModel):
|
||||
label = CharField(unique=True)
|
||||
|
||||
@staticmethod
|
||||
def create_save(label:str, source_labels:list[str]):
|
||||
group = Group.create(
|
||||
label=label,
|
||||
sources=[],
|
||||
)
|
||||
for source_label in source_labels:
|
||||
# continue:
|
||||
src = Source.get(label=source_label)
|
||||
group_src, _ = GroupSource.get_or_create(group=group, source=src)
|
||||
group.save()
|
||||
return group
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.label}"
|
||||
|
||||
def __repl__(self) -> str:
|
||||
return f"{self.label}"
|
||||
|
||||
class GroupSource(BaseModel):
|
||||
group = ForeignKeyField(Group, backref='sources')
|
||||
source = ForeignKeyField(Source)
|
||||
|
||||
def create_tables():
|
||||
with db:
|
||||
db.create_tables([Source, Path, Destination, SyncCommand], safe=True)
|
||||
tables = [
|
||||
Source,
|
||||
Path,
|
||||
Destination,
|
||||
SyncCommand,
|
||||
Group,
|
||||
GroupSource
|
||||
]
|
||||
db.create_tables(tables, safe=True)
|
||||
|
||||
def all_labels():
|
||||
with db:
|
||||
@@ -104,3 +138,6 @@ def all_labels():
|
||||
def all_labels_except(labels):
|
||||
with db:
|
||||
return Source.select(Source.label).where(Source.label.not_in(labels))
|
||||
|
||||
def count_all_labels_except(labels):
|
||||
return len(all_labels_except(labels))
|
||||
|
||||
Reference in New Issue
Block a user