Converting Tag methods to use tag id or name.

This commit is contained in:
Roland 2024-07-30 17:15:01 -06:00
parent 2ad363281f
commit c839acb270
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
22 changed files with 379 additions and 163 deletions

View file

@ -27,7 +27,7 @@ PRETTY_NAME = 'Archive'
logger = logger.getChild(__name__)
__all__ = ['ArchiveDownloader', 'archive_downloader']
__all__ = ['ArchiveDownloader', 'archive_downloader', 'model_archive']
class ArchiveDownloader(Downloader, ABC):

View file

@ -1,7 +1,7 @@
import json
import pathlib
import re
from typing import Iterable, List, Optional, Union
from typing import Iterable, List, Optional
import pytz
from sqlalchemy import Column, Integer, String, ForeignKey, BigInteger
@ -59,6 +59,20 @@ class Archive(Base, ModelHelper):
raise UnknownArchive(f'Cannot find Archive with id {id_}')
return archive
@staticmethod
@optional_session
def get_by_path(path: pathlib.Path | str, session: Session = None) -> Optional['Archive']:
archive = session.query(Archive).join(FileGroup).filter(FileGroup.primary_path == str(path)).one_or_none()
return archive
@staticmethod
@optional_session
def find_by_path(path: pathlib.Path | str, session: Session = None) -> Optional['Archive']:
archive = Archive.get_by_path(path, session)
if archive:
return archive
raise UnknownArchive(f'Cannot find Archive with path: {path}')
def my_paths(self, *mimetypes: str) -> List[pathlib.Path]:
return self.file_group.my_paths(*mimetypes)
@ -285,9 +299,8 @@ class Archive(Base, ModelHelper):
archive = model_archive(file_group, session)
return archive
def add_tag(self, tag_or_tag_name: Union[Tag, str]) -> TagFile:
tag = Tag.get_by_name(tag_or_tag_name) if isinstance(tag_or_tag_name, str) else tag_or_tag_name
return self.file_group.add_tag(tag)
def add_tag(self, tag_id_or_name: int | str) -> TagFile:
return self.file_group.add_tag(tag_id_or_name)
class Domain(Base, ModelHelper):