unify album name length

This commit is contained in:
thomas girod
2024-09-08 13:29:33 +02:00
parent 66189d3ab2
commit d148d6b3a5
3 changed files with 85 additions and 70 deletions

View File

@ -16,7 +16,7 @@
from __future__ import annotations
from io import BytesIO
from typing import Self
from typing import ClassVar, Self
from django.conf import settings
from django.core.cache import cache
@ -203,6 +203,20 @@ class SASAlbumManager(models.Manager):
class Album(SasFile):
NAME_MAX_LENGTH: ClassVar[int] = 50
"""Maximum length of an album's name.
[SithFile][core.models.SithFile] have a maximum length
of 256 characters.
However, this limit is too high for albums.
Names longer than 50 characters are harder to read
and harder to display on the SAS page.
It is to be noted, though, that this does not
add or modify any db behaviour.
It's just a constant to be used in views and forms.
"""
class Meta:
proxy = True

View File

@ -34,7 +34,7 @@ from sas.models import Album, PeoplePictureRelation, Picture
class SASForm(forms.Form):
album_name = forms.CharField(
label=_("Add a new album"), max_length=30, required=False
label=_("Add a new album"), max_length=Album.NAME_MAX_LENGTH, required=False
)
images = MultipleImageField(
label=_("Upload images"),
@ -353,6 +353,7 @@ class AlbumEditForm(forms.ModelForm):
model = Album
fields = ["name", "date", "file", "parent", "edit_groups"]
name = forms.CharField(max_length=Album.NAME_MAX_LENGTH, label=_("file name"))
date = forms.DateField(label=_("Date"), widget=SelectDate, required=True)
parent = make_ajax_field(Album, "parent", "files", help_text="")
edit_groups = make_ajax_field(Album, "edit_groups", "groups", help_text="")