Skip to content

Commit

Permalink
added image model and url validators
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonzorn committed Jul 23, 2024
1 parent dbaa4ee commit 86497a4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions nlightreader/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from .chapter_model import Chapter
from .character_model import Character
from .sort_models import Order, Kind, Genre
from .image_model import Image
28 changes: 28 additions & 0 deletions nlightreader/models/image_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from types import NoneType

import validators


class Image:
def __init__(self, image_id: str, page_number: int, url: str | None):
self.id = image_id
self.page_number = page_number
self.__url = None

self.url = url

@property
def url(self):
return self.__url

@url.setter
def url(self, url: str | None):
if not isinstance(url, (str, NoneType)):
raise TypeError(f"Url must be str or None got {type(url)}")
if url is not None and not validators.url(url):
raise ValueError(f"Url {url} is not valid")
self.__url = url

@staticmethod
def get_empty_instance():
return Image("", 1, None)
5 changes: 4 additions & 1 deletion nlightreader/models/manga_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from types import NoneType
from typing import override

import validators
from PySide6.QtCore import QLocale

from nlightreader.consts.enums import Nl
Expand Down Expand Up @@ -71,7 +72,9 @@ def preview_url(self):
@preview_url.setter
def preview_url(self, url: str | None):
if not isinstance(url, (str, NoneType)):
raise TypeError(f"Preview url must be str got {type(url)}")
raise TypeError(f"Preview url must be str or None got {type(url)}")
if url is not None and not validators.url(url):
raise ValueError(f"Url {url} is not valid")
self.__preview_url = url

@property
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ render-html>=1.0.1
requests>=2.28.1
requests-oauthlib>=1.3.1
SQLAlchemy>=2.0.25
validators>=0.33.0
1 change: 1 addition & 0 deletions requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ render-html>=1.0.1
requests>=2.28.1
requests-oauthlib>=1.3.1
SQLAlchemy>=2.0.25
validators>=0.33.0

0 comments on commit 86497a4

Please sign in to comment.