mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-21 23:01:00 +00:00
Fixes developed from mypy_django script (#312)
This commit is contained in:
parent
cc7824394b
commit
165d84abbf
5 changed files with 14 additions and 8 deletions
|
@ -188,7 +188,7 @@ class Emoji(StatorModel):
|
||||||
return self.fullcode
|
return self.fullcode
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def emojis_from_content(cls, content: str, domain: Domain | None) -> list[str]:
|
def emojis_from_content(cls, content: str, domain: Domain | None) -> list["Emoji"]:
|
||||||
"""
|
"""
|
||||||
Return a parsed and sanitized of emoji found in content without
|
Return a parsed and sanitized of emoji found in content without
|
||||||
the surrounding ':'.
|
the surrounding ':'.
|
||||||
|
|
|
@ -8,13 +8,17 @@ from django.core.files.base import ContentFile
|
||||||
from PIL import Image, ImageOps
|
from PIL import Image, ImageOps
|
||||||
|
|
||||||
|
|
||||||
|
class ImageFile(File):
|
||||||
|
image: Image
|
||||||
|
|
||||||
|
|
||||||
def resize_image(
|
def resize_image(
|
||||||
image: File,
|
image: File,
|
||||||
*,
|
*,
|
||||||
size: tuple[int, int],
|
size: tuple[int, int],
|
||||||
cover=True,
|
cover=True,
|
||||||
keep_format=False,
|
keep_format=False,
|
||||||
) -> File:
|
) -> ImageFile:
|
||||||
"""
|
"""
|
||||||
Resizes an image to fit insize the given size (cropping one dimension
|
Resizes an image to fit insize the given size (cropping one dimension
|
||||||
to fit if needed)
|
to fit if needed)
|
||||||
|
@ -28,10 +32,10 @@ def resize_image(
|
||||||
new_image_bytes = io.BytesIO()
|
new_image_bytes = io.BytesIO()
|
||||||
if keep_format:
|
if keep_format:
|
||||||
resized_image.save(new_image_bytes, format=img.format)
|
resized_image.save(new_image_bytes, format=img.format)
|
||||||
file = File(new_image_bytes)
|
file = ImageFile(new_image_bytes)
|
||||||
else:
|
else:
|
||||||
resized_image.save(new_image_bytes, format="webp")
|
resized_image.save(new_image_bytes, format="webp")
|
||||||
file = File(new_image_bytes, name="image.webp")
|
file = ImageFile(new_image_bytes, name="image.webp")
|
||||||
file.image = resized_image
|
file.image = resized_image
|
||||||
return file
|
return file
|
||||||
|
|
||||||
|
|
|
@ -245,7 +245,7 @@ class HttpSignature:
|
||||||
and response.status_code != 404
|
and response.status_code != 404
|
||||||
):
|
):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"POST error to {uri}: {response.status_code} {response.content}"
|
f"POST error to {uri}: {response.status_code} {response.content!r}"
|
||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ class BaseProxyView(View):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_remote_url(self):
|
def get_remote_url(self) -> str:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,8 @@ class StatorModel(models.Model):
|
||||||
concrete model yourself.
|
concrete model yourself.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
state: StateField
|
||||||
|
|
||||||
# If this row is up for transition attempts (which it always is on creation!)
|
# If this row is up for transition attempts (which it always is on creation!)
|
||||||
state_ready = models.BooleanField(default=True)
|
state_ready = models.BooleanField(default=True)
|
||||||
|
|
||||||
|
@ -75,11 +77,11 @@ class StatorModel(models.Model):
|
||||||
return cls._meta.get_field("state").graph
|
return cls._meta.get_field("state").graph
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_age(self) -> int:
|
def state_age(self) -> float:
|
||||||
return (timezone.now() - self.state_changed).total_seconds()
|
return (timezone.now() - self.state_changed).total_seconds()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def atransition_schedule_due(cls, now=None) -> models.QuerySet:
|
async def atransition_schedule_due(cls, now=None):
|
||||||
"""
|
"""
|
||||||
Finds instances of this model that need to run and schedule them.
|
Finds instances of this model that need to run and schedule them.
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue