(Added) source update args function.

This commit is contained in:
2023-03-02 17:22:14 +02:00
parent b99f2a0ffa
commit c063b5a82c
5 changed files with 81 additions and 3 deletions
+20
View File
@@ -37,6 +37,11 @@ class Path(BaseModel):
class SyncCommand(BaseModel):
command = CharField()
@staticmethod
def get_sync_command(args):
sync_cmd, _ = SyncCommand.get_or_create(command=args)
return sync_cmd
def __str__(self) -> str:
return self.command
@@ -45,6 +50,16 @@ class Source(BaseModel):
source = ForeignKeyField(Path)
args = ForeignKeyField(SyncCommand)
@staticmethod
def is_exist(label) -> bool:
return Source.select().where(Source.label == label).exists()
@staticmethod
def get_source(label):
if not Source.is_exist(label):
return None
return Source.select().where(Source.label == label).get()
@staticmethod
def create_save(label:str, source:str, destinations:list[str], args:str):
src_path, _ = Path.get_or_create(path=source)
@@ -61,6 +76,11 @@ class Source(BaseModel):
src.save()
return src
def update_args(self, args):
args_obj = SyncCommand.get_sync_command(args)
self.args = args_obj
self.save()
def __str__(self) -> str:
return f"{self.label}"