Skip to content

Commit

Permalink
fix(utils, apps): update relative paths for images #5
Browse files Browse the repository at this point in the history
  • Loading branch information
tyronejosee committed Jul 2, 2024
1 parent 9fe2c93 commit fbab4c8
Show file tree
Hide file tree
Showing 37 changed files with 1,220 additions and 94 deletions.
2 changes: 0 additions & 2 deletions apps/animes/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class TimezoneChoices(TextChoices):
GMT = "GMT", _("Greenwich Mean Time")
CET = "CET", _("Central European Time")

# TODO: Add more


class StatusChoices(TextChoices):

Expand Down
21 changes: 21 additions & 0 deletions apps/animes/migrations/0003_alter_anime_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.0.1 on 2024-07-02 19:20

import apps.utils.paths
import apps.utils.validators
import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('animes', '0002_alter_anime_duration'),
]

operations = [
migrations.AlterField(
model_name='anime',
name='image',
field=models.ImageField(blank=True, null=True, upload_to=apps.utils.paths.image_path, validators=[django.core.validators.FileExtensionValidator(allowed_extensions=['jpg', 'webp']), apps.utils.validators.ImageSizeValidator(max_height=1280, max_width=909), apps.utils.validators.FileSizeValidator(limit_mb=2)], verbose_name='image'),
),
]
18 changes: 11 additions & 7 deletions apps/animes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.core.validators import FileExtensionValidator
from django.utils.translation import gettext as _

from apps.utils.paths import picture_image_path
from apps.utils.paths import image_path
from apps.utils.models import BaseModel
from apps.utils.mixins import SlugMixin
from apps.utils.validators import FileSizeValidator, ImageSizeValidator
Expand Down Expand Up @@ -55,7 +55,7 @@ def __str__(self):
return str(self.string)


class Anime(BaseModel, SlugMixin):
class Anime(SlugMixin, BaseModel):
"""Model definition for Anime."""

name = models.CharField(_("name (eng)"), max_length=255, unique=True)
Expand All @@ -74,7 +74,7 @@ class Anime(BaseModel, SlugMixin):
)
image = models.ImageField(
_("image"),
upload_to=picture_image_path,
upload_to=image_path,
blank=True,
null=True,
validators=[
Expand Down Expand Up @@ -191,13 +191,17 @@ class Meta:
verbose_name = _("anime")
verbose_name_plural = _("animes")

def __str__(self):
return str(self.name)

def save(self, *args, **kwargs):
self.set_name_rom()
self.set_slug()
super().save(*args, **kwargs)

def set_name_rom(self):
if not self.name_rom:
self.name_rom = self.name
super(SlugMixin, self).save(*args, **kwargs)

def __str__(self):
return str(self.name)

def calculate_score(self, user_score):
# Calculate new score based on the existing score and the user's score
Expand Down
10 changes: 5 additions & 5 deletions apps/characters/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .choices import RoleChoices


class Character(BaseModel, SlugMixin):
class Character(SlugMixin, BaseModel):
"""Model definition for Character."""

name = models.CharField(_("name"), max_length=255)
Expand All @@ -40,15 +40,17 @@ class Character(BaseModel, SlugMixin):
mangas = models.ManyToManyField(Manga, through="CharacterManga", blank=True)
favorites = models.PositiveIntegerField(_("favorites"), default=0)

# TODO: Check for possible errors

objects = CharacterManager()

class Meta:
ordering = ["pk"]
verbose_name = _("character")
verbose_name_plural = _("characters")

def save(self, *args, **kwargs):
self.set_slug()
super().save(*args, **kwargs)

def __str__(self):
return str(self.name)

Expand Down Expand Up @@ -102,7 +104,6 @@ class CharacterAnime(BaseModel):
limit_choices_to={"is_available": True},
on_delete=models.CASCADE,
)
# TODO: Remove

class Meta:
ordering = ["pk"]
Expand Down Expand Up @@ -133,7 +134,6 @@ class CharacterManga(BaseModel):
on_delete=models.CASCADE,
limit_choices_to={"is_available": True},
)
# TODO: Remove

class Meta:
ordering = ["pk"]
Expand Down
4 changes: 4 additions & 0 deletions apps/clubs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class Meta:
def __str__(self):
return str(self.name)

def save(self, *args, **kwargs):
self.set_slug()
super().save(*args, **kwargs)


class ClubMember(BaseModel):
"""Model definition for ClubMember."""
Expand Down
6 changes: 0 additions & 6 deletions apps/genres/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ class GenreViewSet(ListCacheMixin, LogicalDeleteMixin, ModelViewSet):
serializer_class = GenreWriteSerializer
pagination_class = LargeSetPagination
search_fields = ["name"]
# filterset_class = GenreFilter
# TODO: Add filter

def get_queryset(self):
return Genre.objects.get_available()
Expand Down Expand Up @@ -132,8 +130,6 @@ class ThemeViewSet(ListCacheMixin, LogicalDeleteMixin, ModelViewSet):
permission_classes = [IsContributor]
serializer_class = ThemeWriteSerializer
search_fields = ["name"]
# filterset_class = ThemeFilter
# TODO: Add filter

def get_queryset(self):
return Theme.objects.get_available()
Expand Down Expand Up @@ -166,8 +162,6 @@ class DemographicViewSet(ListCacheMixin, LogicalDeleteMixin, ModelViewSet):
permission_classes = [IsContributor]
serializer_class = DemographicWriteSerializer
search_fields = ["name"]
# filterset_class = DemographicFilter
# TODO: Add filter

def get_queryset(self):
return Demographic.objects.get_available()
Expand Down
1 change: 0 additions & 1 deletion apps/mangas/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class MangaAdmin(ImportExportModelAdmin, BaseAdmin):
list_editable = ["is_available"]
readonly_fields = [
"pk",
"slug",
"created_at",
"updated_at",
]
Expand Down
21 changes: 21 additions & 0 deletions apps/mangas/migrations/0002_alter_manga_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.0.1 on 2024-07-02 19:20

import apps.utils.paths
import apps.utils.validators
import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mangas', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='manga',
name='image',
field=models.ImageField(blank=True, null=True, upload_to=apps.utils.paths.image_path, validators=[django.core.validators.FileExtensionValidator(allowed_extensions=['jpg', 'webp']), apps.utils.validators.ImageSizeValidator(max_height=1280, max_width=909), apps.utils.validators.FileSizeValidator(limit_mb=2)], verbose_name='image'),
),
]
18 changes: 11 additions & 7 deletions apps/mangas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.core.validators import FileExtensionValidator
from django.utils.translation import gettext as _

from apps.utils.paths import picture_image_path
from apps.utils.paths import image_path
from apps.utils.models import BaseModel
from apps.utils.mixins import SlugMixin
from apps.utils.validators import FileSizeValidator, ImageSizeValidator
Expand Down Expand Up @@ -32,7 +32,7 @@ def __str__(self):
return self.name


class Manga(BaseModel, SlugMixin):
class Manga(SlugMixin, BaseModel):
"""Model definition for Manga."""

name = models.CharField(_("name (eng)"), max_length=255, unique=True)
Expand All @@ -48,7 +48,7 @@ class Manga(BaseModel, SlugMixin):
)
image = models.ImageField(
_("image"),
upload_to=picture_image_path,
upload_to=image_path,
blank=True,
null=True,
validators=[
Expand Down Expand Up @@ -119,13 +119,17 @@ class Meta:
verbose_name = _("manga")
verbose_name_plural = _("mangas")

def __str__(self):
return str(self.name)

def save(self, *args, **kwargs):
self.set_name_rom()
self.set_slug()
super().save(*args, **kwargs)

def set_name_rom(self):
if not self.name_rom:
self.name_rom = self.name
super(SlugMixin, self).save(*args, **kwargs)

def __str__(self):
return str(self.name)

def calculate_score(self, user_score):
# Calculate score based on the existing score and the user's score
Expand Down
19 changes: 19 additions & 0 deletions apps/news/migrations/0003_alter_news_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.1 on 2024-07-02 19:20

import apps.utils.paths
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('news', '0002_alter_news_author_id'),
]

operations = [
migrations.AlterField(
model_name='news',
name='image',
field=models.ImageField(upload_to=apps.utils.paths.image_path, verbose_name='image'),
),
]
18 changes: 18 additions & 0 deletions apps/news/migrations/0004_news_slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.1 on 2024-07-02 21:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('news', '0003_alter_news_image'),
]

operations = [
migrations.AddField(
model_name='news',
name='slug',
field=models.SlugField(blank=True, null=True, unique=True, verbose_name='Slug'),
),
]
11 changes: 8 additions & 3 deletions apps/news/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from django.utils.translation import gettext as _

from apps.utils.models import BaseModel
from apps.utils.paths import picture_image_path
from apps.utils.mixins import SlugMixin
from apps.utils.paths import image_path
from apps.animes.models import Anime
from apps.mangas.models import Manga
from .managers import NewsManager
Expand All @@ -14,13 +15,13 @@
User = settings.AUTH_USER_MODEL


class News(BaseModel):
class News(SlugMixin, BaseModel):
"""Model definition for News."""

name = models.CharField(_("title"), max_length=100)
description = models.CharField(_("description"), max_length=255)
content = models.TextField(_("content"))
image = models.ImageField(_("image"), upload_to=picture_image_path)
image = models.ImageField(_("image"), upload_to=image_path)
source = models.URLField(_("source"), max_length=255)
tag = models.CharField(
_("tag"),
Expand Down Expand Up @@ -49,3 +50,7 @@ class Meta:

def __str__(self):
return str(self.name)

def save(self, *args, **kwargs):
self.set_slug()
super().save(*args, **kwargs)
6 changes: 5 additions & 1 deletion apps/persons/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .choices import CategoryChoices, LanguageChoices


class Person(BaseModel, SlugMixin):
class Person(SlugMixin, BaseModel):
"""Model definition for Person."""

name = models.CharField(_("name"), max_length=255, unique=True)
Expand Down Expand Up @@ -75,6 +75,10 @@ class Meta:
def __str__(self):
return self.name

def save(self, *args, **kwargs):
self.set_slug()
super().save(*args, **kwargs)

@property
def age(self):
today = date.today()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.0.1 on 2024-07-02 21:00

import apps.utils.validators
import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('playlists', '0004_mangalistitem_unique_mangalist_manga'),
]

operations = [
migrations.AlterField(
model_name='animelist',
name='banner',
field=models.ImageField(blank=True, null=True, upload_to='playlists/', validators=[django.core.validators.FileExtensionValidator(allowed_extensions=['jpg', 'webp']), apps.utils.validators.ImageSizeValidator(max_height=1500, max_width=500), apps.utils.validators.FileSizeValidator(limit_mb=1)], verbose_name='banner'),
),
migrations.AlterField(
model_name='mangalist',
name='banner',
field=models.ImageField(blank=True, null=True, upload_to='playlists/', validators=[django.core.validators.FileExtensionValidator(allowed_extensions=['jpg', 'webp']), apps.utils.validators.ImageSizeValidator(max_height=1500, max_width=500), apps.utils.validators.FileSizeValidator(limit_mb=1)], verbose_name='banner'),
),
]
6 changes: 1 addition & 5 deletions apps/playlists/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from apps.utils.models import BaseModel
from apps.utils.validators import FileSizeValidator, ImageSizeValidator
from apps.utils.paths import image_path
from apps.animes.models import Anime
from apps.mangas.models import Manga
from .choices import (
Expand All @@ -21,9 +20,6 @@
User = settings.AUTH_USER_MODEL


# TODO: Add PlaylistItemBase model


class PlaylistBase(BaseModel):
"""Model definition for Playlist (Base)."""

Expand All @@ -36,7 +32,7 @@ class PlaylistBase(BaseModel):
)
banner = models.ImageField(
_("banner"),
upload_to=image_path,
upload_to="playlists/",
blank=True,
null=True,
validators=[
Expand Down
Loading

0 comments on commit fbab4c8

Please sign in to comment.