Skip to content

Commit 0cb64d5

Browse files
committed
Migrate albums and pictures to their own tables
1 parent b9482a6 commit 0cb64d5

File tree

22 files changed

+696
-289
lines changed

22 files changed

+696
-289
lines changed

core/admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class PageAdmin(admin.ModelAdmin):
7979

8080
@admin.register(SithFile)
8181
class SithFileAdmin(admin.ModelAdmin):
82-
list_display = ("name", "owner", "size", "date", "is_in_sas")
82+
list_display = ("name", "owner", "size", "date")
8383
autocomplete_fields = ("parent", "owner", "moderator")
84-
search_fields = ("name", "parent__name")
84+
search_fields = ("name",)
8585

8686

8787
@admin.register(OperationLog)

core/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class SithFileController(ControllerBase):
7373
)
7474
@paginate(PageNumberPaginationExtra, page_size=50)
7575
def search_files(self, search: Annotated[str, annotated_types.MinLen(1)]):
76-
return SithFile.objects.filter(is_in_sas=False).filter(name__icontains=search)
76+
return SithFile.objects.filter(name__icontains=search)
7777

7878

7979
@api_controller("/group")

core/management/commands/populate.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ def handle(self, *args, **options):
118118
p.save(force_lock=True)
119119

120120
club_root = SithFile.objects.create(name="clubs", owner=root)
121-
sas = SithFile.objects.create(name="SAS", owner=root)
122121
main_club = Club.objects.create(
123122
id=1,
124123
name=settings.SITH_MAIN_CLUB["name"],
@@ -805,14 +804,7 @@ def handle(self, *args, **options):
805804
# SAS
806805
for f in self.SAS_FIXTURE_PATH.glob("*"):
807806
if f.is_dir():
808-
album = Album(
809-
parent=sas,
810-
name=f.name,
811-
owner=root,
812-
is_folder=True,
813-
is_in_sas=True,
814-
is_moderated=True,
815-
)
807+
album = Album(name=f.name, owner=root, is_moderated=True)
816808
album.clean()
817809
album.save()
818810
for p in f.iterdir():
@@ -822,14 +814,8 @@ def handle(self, *args, **options):
822814
name=p.name,
823815
file=file,
824816
owner=root,
825-
is_folder=False,
826-
is_in_sas=True,
827817
is_moderated=True,
828-
mime_type="image/webp",
829-
size=file.size,
830818
)
831-
pict.file.name = p.name
832-
pict.clean()
833819
pict.generate_thumbnails()
834820

835821
img_skia = Picture.objects.get(name="skia.jpg")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Generated by Django 4.2.17 on 2025-01-26 15:01
2+
3+
from typing import TYPE_CHECKING
4+
5+
from django.db import migrations
6+
from django.db.migrations.state import StateApps
7+
8+
if TYPE_CHECKING:
9+
import core.models
10+
11+
12+
def remove_sas_sithfiles(apps: StateApps, schema_editor):
13+
SithFile: type[core.models.SithFile] = apps.get_model("core", "SithFile")
14+
SithFile.objects.all().delete()
15+
16+
17+
class Migration(migrations.Migration):
18+
dependencies = [
19+
("core", "0043_bangroup_alter_group_description_alter_user_groups_and_more"),
20+
]
21+
22+
operations = [
23+
migrations.RunPython(
24+
remove_sas_sithfiles, reverse_code=migrations.RunPython.noop, elidable=True
25+
),
26+
migrations.AlterModelOptions(
27+
name="userban",
28+
options={"verbose_name": "user ban", "verbose_name_plural": "user bans"},
29+
),
30+
migrations.RemoveField(
31+
model_name="sithfile",
32+
name="is_in_sas",
33+
),
34+
]

core/models.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -898,9 +898,6 @@ class SithFile(models.Model):
898898
on_delete=models.CASCADE,
899899
)
900900
asked_for_removal = models.BooleanField(_("asked for removal"), default=False)
901-
is_in_sas = models.BooleanField(
902-
_("is in the SAS"), default=False, db_index=True
903-
) # Allows to query this flag, updated at each call to save()
904901

905902
class Meta:
906903
verbose_name = _("file")
@@ -909,24 +906,12 @@ def __str__(self):
909906
return self.get_parent_path() + "/" + self.name
910907

911908
def save(self, *args, **kwargs):
912-
sas = SithFile.objects.filter(id=settings.SITH_SAS_ROOT_DIR_ID).first()
913-
self.is_in_sas = sas in self.get_parent_list() or self == sas
914909
copy_rights = False
915910
if self.id is None:
916911
copy_rights = True
917912
super().save(*args, **kwargs)
918913
if copy_rights:
919914
self.copy_rights()
920-
if self.is_in_sas:
921-
for user in User.objects.filter(
922-
groups__id__in=[settings.SITH_GROUP_SAS_ADMIN_ID]
923-
):
924-
Notification(
925-
user=user,
926-
url=reverse("sas:moderation"),
927-
type="SAS_MODERATION",
928-
param="1",
929-
).save()
930915

931916
def is_owned_by(self, user: User) -> bool:
932917
if user.is_anonymous:
@@ -939,8 +924,6 @@ def is_owned_by(self, user: User) -> bool:
939924
return user.is_board_member
940925
if user.is_com_admin:
941926
return True
942-
if self.is_in_sas and user.is_in_group(pk=settings.SITH_GROUP_SAS_ADMIN_ID):
943-
return True
944927
return user.id == self.owner_id
945928

946929
def can_be_viewed_by(self, user: User) -> bool:
@@ -1106,18 +1089,6 @@ def _check_fs(self):
11061089
def is_file(self):
11071090
return not self.is_folder
11081091

1109-
@cached_property
1110-
def as_picture(self):
1111-
from sas.models import Picture
1112-
1113-
return Picture.objects.filter(id=self.id).first()
1114-
1115-
@cached_property
1116-
def as_album(self):
1117-
from sas.models import Album
1118-
1119-
return Album.objects.filter(id=self.id).first()
1120-
11211092
def get_parent_list(self):
11221093
parents = []
11231094
current = self.parent

core/views/files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def get_context_data(self, **kwargs):
402402
class FileModerationView(AllowFragment, ListView):
403403
model = SithFile
404404
template_name = "core/file_moderation.jinja"
405-
queryset = SithFile.objects.filter(is_moderated=False, is_in_sas=False)
405+
queryset = SithFile.objects.filter(is_moderated=False)
406406
paginate_by = 100
407407

408408
def dispatch(self, request: HttpRequest, *args, **kwargs):

galaxy/management/commands/generate_galaxy_test_data.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@
2525
from datetime import timedelta
2626
from typing import Final, Optional
2727

28-
from django.conf import settings
2928
from django.core.files.base import ContentFile
3029
from django.core.management.base import BaseCommand
3130
from django.utils import timezone
3231

3332
from club.models import Club, Membership
34-
from core.models import Group, Page, SithFile, User
33+
from core.models import Group, Page, User
3534
from sas.models import Album, PeoplePictureRelation, Picture
3635
from subscription.models import Subscription
3736

@@ -98,13 +97,8 @@ def handle(self, *args, **options):
9897
self.NB_CLUBS = options["club_count"]
9998

10099
root = User.objects.filter(username="root").first()
101-
sas = SithFile.objects.get(id=settings.SITH_SAS_ROOT_DIR_ID)
102100
self.galaxy_album = Album.objects.create(
103-
name="galaxy-register-file",
104-
owner=root,
105-
is_moderated=True,
106-
is_in_sas=True,
107-
parent=sas,
101+
name="galaxy-register-file", owner=root, is_moderated=True
108102
)
109103

110104
self.make_clubs()
@@ -288,14 +282,10 @@ def make_pictures(self):
288282
owner=u,
289283
name=f"galaxy-picture {u} {i // self.NB_USERS}",
290284
is_moderated=True,
291-
is_folder=False,
292285
parent=self.galaxy_album,
293-
is_in_sas=True,
294-
file=ContentFile(RED_PIXEL_PNG),
286+
original=ContentFile(RED_PIXEL_PNG),
295287
compressed=ContentFile(RED_PIXEL_PNG),
296288
thumbnail=ContentFile(RED_PIXEL_PNG),
297-
mime_type="image/png",
298-
size=len(RED_PIXEL_PNG),
299289
)
300290
)
301291
self.picts[i].file.name = self.picts[i].name

locale/fr/LC_MESSAGES/django.po

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
msgid ""
77
msgstr ""
88
"Report-Msgid-Bugs-To: \n"
9-
"POT-Creation-Date: 2025-01-19 18:12+0100\n"
9+
"POT-Creation-Date: 2025-01-26 12:47+0100\n"
1010
"PO-Revision-Date: 2016-07-18\n"
1111
"Last-Translator: Maréchal <[email protected]\n"
1212
"Language-Team: AE info <[email protected]>\n"
@@ -17,7 +17,7 @@ msgstr ""
1717
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
1818

1919
#: accounting/models.py club/models.py com/models.py counter/models.py
20-
#: forum/models.py launderette/models.py
20+
#: forum/models.py launderette/models.py sas/models.py
2121
msgid "name"
2222
msgstr "nom"
2323

@@ -935,10 +935,6 @@ msgstr "rôle"
935935
msgid "description"
936936
msgstr "description"
937937

938-
#: club/models.py
939-
msgid "past member"
940-
msgstr "ancien membre"
941-
942938
#: club/models.py
943939
msgid "Email address"
944940
msgstr "Adresse email"
@@ -948,7 +944,7 @@ msgid "Enter a valid address. Only the root of the address is needed."
948944
msgstr ""
949945
"Entrez une adresse valide. Seule la racine de l'adresse est nécessaire."
950946

951-
#: club/models.py com/models.py core/models.py
947+
#: club/models.py com/models.py core/models.py sas/models.py
952948
msgid "is moderated"
953949
msgstr "est modéré"
954950

@@ -2052,23 +2048,23 @@ msgstr "avoir une notification pour chaque click"
20522048
msgid "get a notification for every refilling"
20532049
msgstr "avoir une notification pour chaque rechargement"
20542050

2055-
#: core/models.py sas/forms.py
2051+
#: core/models.py sas/models.py
20562052
msgid "file name"
20572053
msgstr "nom du fichier"
20582054

2059-
#: core/models.py
2055+
#: core/models.py sas/models.py
20602056
msgid "parent"
20612057
msgstr "parent"
20622058

20632059
#: core/models.py
20642060
msgid "compressed file"
20652061
msgstr "version allégée"
20662062

2067-
#: core/models.py
2063+
#: core/models.py sas/models.py
20682064
msgid "thumbnail"
20692065
msgstr "miniature"
20702066

2071-
#: core/models.py
2067+
#: core/models.py sas/models.py
20722068
msgid "owner"
20732069
msgstr "propriétaire"
20742070

@@ -2092,14 +2088,10 @@ msgstr "type mime"
20922088
msgid "size"
20932089
msgstr "taille"
20942090

2095-
#: core/models.py
2091+
#: core/models.py sas/models.py
20962092
msgid "asked for removal"
20972093
msgstr "retrait demandé"
20982094

2099-
#: core/models.py
2100-
msgid "is in the SAS"
2101-
msgstr "est dans le SAS"
2102-
21032095
#: core/models.py
21042096
msgid "Character '/' not authorized in name"
21052097
msgstr "Le caractère '/' n'est pas autorisé dans les noms de fichier"
@@ -3299,8 +3291,8 @@ msgstr "Nom d'utilisateur, email, ou numéro de compte AE"
32993291

33003292
#: core/views/forms.py
33013293
msgid ""
3302-
"Profile: you need to be visible on the picture, in order to be recognized "
3303-
"(e.g. by the barmen)"
3294+
"Profile: you need to be visible on the picture, in order to be recognized (e."
3295+
"g. by the barmen)"
33043296
msgstr ""
33053297
"Photo de profil: vous devez être visible sur la photo afin d'être reconnu "
33063298
"(par exemple par les barmen)"
@@ -3642,7 +3634,7 @@ msgstr "élément de relevé de caisse"
36423634
msgid "banner"
36433635
msgstr "bannière"
36443636

3645-
#: counter/models.py
3637+
#: counter/models.py sas/models.py
36463638
msgid "event date"
36473639
msgstr "date de l'événement"
36483640

@@ -3906,8 +3898,8 @@ msgstr ""
39063898
#: counter/templates/counter/mails/account_dump.jinja
39073899
msgid "If you think this was a mistake, please mail us at [email protected]."
39083900
msgstr ""
3909-
"Si vous pensez qu'il s'agit d'une erreur, veuillez envoyer un mail à "
3910-
"ae@utbm.fr."
3901+
"Si vous pensez qu'il s'agit d'une erreur, veuillez envoyer un mail à ae@utbm."
3902+
"fr."
39113903

39123904
#: counter/templates/counter/mails/account_dump.jinja
39133905
msgid ""
@@ -4324,11 +4316,11 @@ msgstr "début des candidatures"
43244316
msgid "end candidature"
43254317
msgstr "fin des candidatures"
43264318

4327-
#: election/models.py
4319+
#: election/models.py sas/models.py
43284320
msgid "edit groups"
43294321
msgstr "groupe d'édition"
43304322

4331-
#: election/models.py
4323+
#: election/models.py sas/models.py
43324324
msgid "view groups"
43334325
msgstr "groupe de vue"
43344326

@@ -5143,6 +5135,22 @@ msgstr "Erreur de création de l'album %(album)s : %(msg)s"
51435135
msgid "You already requested moderation for this picture."
51445136
msgstr "Vous avez déjà déposé une demande de retrait pour cette photo."
51455137

5138+
#: sas/models.py
5139+
msgid "The date on which the photos in this album were taken"
5140+
msgstr "La date à laquelle les photos de cet album ont été prises"
5141+
5142+
#: sas/models.py
5143+
msgid "album"
5144+
msgstr "album"
5145+
5146+
#: sas/models.py
5147+
msgid "original image"
5148+
msgstr "image originale"
5149+
5150+
#: sas/models.py
5151+
msgid "compressed image"
5152+
msgstr "version compressée"
5153+
51465154
#: sas/models.py
51475155
msgid "picture"
51485156
msgstr "photo"

sas/admin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
@admin.register(Picture)
2222
class PictureAdmin(admin.ModelAdmin):
23-
list_display = ("name", "parent", "date", "size", "is_moderated")
23+
list_display = ("name", "parent", "is_moderated")
2424
search_fields = ("name",)
25-
autocomplete_fields = ("owner", "parent", "edit_groups", "view_groups", "moderator")
25+
autocomplete_fields = ("owner", "parent", "moderator")
2626

2727

2828
@admin.register(PeoplePictureRelation)
@@ -33,9 +33,9 @@ class PeoplePictureRelationAdmin(admin.ModelAdmin):
3333

3434
@admin.register(Album)
3535
class AlbumAdmin(admin.ModelAdmin):
36-
list_display = ("name", "parent", "date", "owner", "is_moderated")
36+
list_display = ("name", "parent")
3737
search_fields = ("name",)
38-
autocomplete_fields = ("owner", "parent", "edit_groups", "view_groups")
38+
autocomplete_fields = ("parent", "edit_groups", "view_groups")
3939

4040

4141
@admin.register(PictureModerationRequest)

sas/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def fetch_pictures(self, filters: Query[PictureFilterSchema]):
6969
return (
7070
filters.filter(Picture.objects.viewable_by(user))
7171
.distinct()
72-
.order_by("-parent__date", "date")
72+
.order_by("-parent__event_date", "created_at")
7373
.select_related("owner")
7474
.annotate(album=F("parent__name"))
7575
)

0 commit comments

Comments
 (0)