mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 20:09:25 +00:00
Migrate albums and pictures to their own tables
This commit is contained in:
@ -79,9 +79,9 @@ class PageAdmin(admin.ModelAdmin):
|
||||
|
||||
@admin.register(SithFile)
|
||||
class SithFileAdmin(admin.ModelAdmin):
|
||||
list_display = ("name", "owner", "size", "date", "is_in_sas")
|
||||
list_display = ("name", "owner", "size", "date")
|
||||
autocomplete_fields = ("parent", "owner", "moderator")
|
||||
search_fields = ("name", "parent__name")
|
||||
search_fields = ("name",)
|
||||
|
||||
|
||||
@admin.register(OperationLog)
|
||||
|
@ -73,7 +73,7 @@ class SithFileController(ControllerBase):
|
||||
)
|
||||
@paginate(PageNumberPaginationExtra, page_size=50)
|
||||
def search_files(self, search: Annotated[str, annotated_types.MinLen(1)]):
|
||||
return SithFile.objects.filter(is_in_sas=False).filter(name__icontains=search)
|
||||
return SithFile.objects.filter(name__icontains=search)
|
||||
|
||||
|
||||
@api_controller("/group")
|
||||
|
@ -118,7 +118,6 @@ class Command(BaseCommand):
|
||||
p.save(force_lock=True)
|
||||
|
||||
club_root = SithFile.objects.create(name="clubs", owner=root)
|
||||
sas = SithFile.objects.create(name="SAS", owner=root)
|
||||
main_club = Club.objects.create(
|
||||
id=1,
|
||||
name=settings.SITH_MAIN_CLUB["name"],
|
||||
@ -809,14 +808,7 @@ Welcome to the wiki page!
|
||||
# SAS
|
||||
for f in self.SAS_FIXTURE_PATH.glob("*"):
|
||||
if f.is_dir():
|
||||
album = Album(
|
||||
parent=sas,
|
||||
name=f.name,
|
||||
owner=root,
|
||||
is_folder=True,
|
||||
is_in_sas=True,
|
||||
is_moderated=True,
|
||||
)
|
||||
album = Album(name=f.name)
|
||||
album.clean()
|
||||
album.save()
|
||||
for p in f.iterdir():
|
||||
@ -824,17 +816,13 @@ Welcome to the wiki page!
|
||||
pict = Picture(
|
||||
parent=album,
|
||||
name=p.name,
|
||||
file=file,
|
||||
original=file,
|
||||
owner=root,
|
||||
is_folder=False,
|
||||
is_in_sas=True,
|
||||
is_moderated=True,
|
||||
mime_type="image/webp",
|
||||
size=file.size,
|
||||
)
|
||||
pict.file.name = p.name
|
||||
pict.clean()
|
||||
pict.original.name = pict.name
|
||||
pict.generate_thumbnails()
|
||||
pict.save()
|
||||
|
||||
img_skia = Picture.objects.get(name="skia.jpg")
|
||||
img_sli = Picture.objects.get(name="sli.jpg")
|
||||
|
27
core/migrations/0045_remove_sithfiles.py
Normal file
27
core/migrations/0045_remove_sithfiles.py
Normal file
@ -0,0 +1,27 @@
|
||||
# Generated by Django 4.2.17 on 2025-01-26 15:01
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from django.db import migrations
|
||||
from django.db.migrations.state import StateApps
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import core.models
|
||||
|
||||
|
||||
def remove_sas_sithfiles(apps: StateApps, schema_editor):
|
||||
SithFile: type[core.models.SithFile] = apps.get_model("core", "SithFile")
|
||||
SithFile.objects.filter(is_in_sas=True).delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("core", "0044_alter_userban_options"),
|
||||
("sas", "0006_alter_peoplepicturerelation_picture_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
remove_sas_sithfiles, reverse_code=migrations.RunPython.noop, elidable=True
|
||||
)
|
||||
]
|
9
core/migrations/0046_remove_sithfile_is_in_sas.py
Normal file
9
core/migrations/0046_remove_sithfile_is_in_sas.py
Normal file
@ -0,0 +1,9 @@
|
||||
# Generated by Django 4.2.17 on 2025-02-14 11:58
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [("core", "0045_remove_sithfiles")]
|
||||
|
||||
operations = [migrations.RemoveField(model_name="sithfile", name="is_in_sas")]
|
@ -867,9 +867,6 @@ class SithFile(models.Model):
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
asked_for_removal = models.BooleanField(_("asked for removal"), default=False)
|
||||
is_in_sas = models.BooleanField(
|
||||
_("is in the SAS"), default=False, db_index=True
|
||||
) # Allows to query this flag, updated at each call to save()
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("file")
|
||||
@ -878,24 +875,12 @@ class SithFile(models.Model):
|
||||
return self.get_parent_path() + "/" + self.name
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
sas = SithFile.objects.filter(id=settings.SITH_SAS_ROOT_DIR_ID).first()
|
||||
self.is_in_sas = sas in self.get_parent_list() or self == sas
|
||||
copy_rights = False
|
||||
if self.id is None:
|
||||
copy_rights = True
|
||||
super().save(*args, **kwargs)
|
||||
if copy_rights:
|
||||
self.copy_rights()
|
||||
if self.is_in_sas:
|
||||
for user in User.objects.filter(
|
||||
groups__id__in=[settings.SITH_GROUP_SAS_ADMIN_ID]
|
||||
):
|
||||
Notification(
|
||||
user=user,
|
||||
url=reverse("sas:moderation"),
|
||||
type="SAS_MODERATION",
|
||||
param="1",
|
||||
).save()
|
||||
|
||||
def is_owned_by(self, user: User) -> bool:
|
||||
if user.is_anonymous:
|
||||
@ -908,8 +893,6 @@ class SithFile(models.Model):
|
||||
return user.is_board_member
|
||||
if user.is_com_admin:
|
||||
return True
|
||||
if self.is_in_sas and user.is_in_group(pk=settings.SITH_GROUP_SAS_ADMIN_ID):
|
||||
return True
|
||||
return user.id == self.owner_id
|
||||
|
||||
def can_be_viewed_by(self, user: User) -> bool:
|
||||
@ -1075,18 +1058,6 @@ class SithFile(models.Model):
|
||||
def is_file(self):
|
||||
return not self.is_folder
|
||||
|
||||
@cached_property
|
||||
def as_picture(self):
|
||||
from sas.models import Picture
|
||||
|
||||
return Picture.objects.filter(id=self.id).first()
|
||||
|
||||
@cached_property
|
||||
def as_album(self):
|
||||
from sas.models import Album
|
||||
|
||||
return Album.objects.filter(id=self.id).first()
|
||||
|
||||
def get_parent_list(self):
|
||||
parents = []
|
||||
current = self.parent
|
||||
|
@ -402,7 +402,7 @@ class FileDeleteView(AllowFragment, CanEditPropMixin, DeleteView):
|
||||
class FileModerationView(AllowFragment, ListView):
|
||||
model = SithFile
|
||||
template_name = "core/file_moderation.jinja"
|
||||
queryset = SithFile.objects.filter(is_moderated=False, is_in_sas=False)
|
||||
queryset = SithFile.objects.filter(is_moderated=False)
|
||||
ordering = "id"
|
||||
paginate_by = 100
|
||||
|
||||
|
Reference in New Issue
Block a user