mirror of
https://github.com/ae-utbm/sith.git
synced 2025-06-19 09:35:20 +00:00
fix album grouping on user pictures page
This commit is contained in:
parent
9c3820f986
commit
75b37cd6e3
16
sas/api.py
16
sas/api.py
@ -2,7 +2,6 @@ from typing import Any, Literal
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db.models import F
|
||||
from django.urls import reverse
|
||||
from ninja import Body, File, Query
|
||||
from ninja.security import SessionAuth
|
||||
@ -105,8 +104,7 @@ class PicturesController(ControllerBase):
|
||||
filters.filter(Picture.objects.viewable_by(user))
|
||||
.distinct()
|
||||
.order_by("-parent__date", "date")
|
||||
.select_related("owner")
|
||||
.annotate(album=F("parent__name"))
|
||||
.select_related("owner", "parent")
|
||||
)
|
||||
|
||||
@route.post(
|
||||
@ -153,7 +151,9 @@ class PicturesController(ControllerBase):
|
||||
|
||||
@route.put("/{picture_id}/identified", permissions=[IsAuthenticated, CanView])
|
||||
def identify_users(self, picture_id: NonNegativeInt, users: set[NonNegativeInt]):
|
||||
picture = self.get_object_or_exception(Picture, pk=picture_id)
|
||||
picture = self.get_object_or_exception(
|
||||
Picture.objects.select_related("parent"), pk=picture_id
|
||||
)
|
||||
db_users = list(User.objects.filter(id__in=users))
|
||||
if len(users) != len(db_users):
|
||||
raise NotFound
|
||||
@ -166,13 +166,15 @@ class PicturesController(ControllerBase):
|
||||
]
|
||||
PeoplePictureRelation.objects.bulk_create(relations)
|
||||
for u in identified:
|
||||
html_id = f"album-{picture.parent_id}"
|
||||
url = reverse(
|
||||
"sas:user_pictures", kwargs={"user_id": u.id}, fragment=html_id
|
||||
)
|
||||
Notification.objects.get_or_create(
|
||||
user=u,
|
||||
viewed=False,
|
||||
type="NEW_PICTURES",
|
||||
defaults={
|
||||
"url": reverse("sas:user_pictures", kwargs={"user_id": u.id})
|
||||
},
|
||||
defaults={"url": url, "param": picture.parent.name},
|
||||
)
|
||||
|
||||
@route.delete("/{picture_id}", permissions=[IsSasAdmin])
|
||||
|
@ -18,6 +18,12 @@ class AlbumFilterSchema(FilterSchema):
|
||||
parent_id: int | None = Field(None, q="parent_id")
|
||||
|
||||
|
||||
class SimpleAlbumSchema(ModelSchema):
|
||||
class Meta:
|
||||
model = Album
|
||||
fields = ["id", "name"]
|
||||
|
||||
|
||||
class AlbumSchema(ModelSchema):
|
||||
class Meta:
|
||||
model = Album
|
||||
@ -70,7 +76,7 @@ class PictureSchema(ModelSchema):
|
||||
full_size_url: str
|
||||
compressed_url: str
|
||||
thumb_url: str
|
||||
album: str
|
||||
album: SimpleAlbumSchema = Field(alias="parent")
|
||||
report_url: str
|
||||
edit_url: str
|
||||
|
||||
|
@ -22,11 +22,11 @@ document.addEventListener("alpine:init", () => {
|
||||
} as PicturesFetchPicturesData);
|
||||
|
||||
this.albums = this.pictures.reduce(
|
||||
(acc: Record<string, PictureSchema[]>, picture: PictureSchema) => {
|
||||
if (!acc[picture.album]) {
|
||||
acc[picture.album] = [];
|
||||
(acc: Record<number, PictureSchema[]>, picture: PictureSchema) => {
|
||||
if (!acc[picture.album.id]) {
|
||||
acc[picture.album.id] = [];
|
||||
}
|
||||
acc[picture.album].push(picture);
|
||||
acc[picture.album.id].push(picture);
|
||||
return acc;
|
||||
},
|
||||
{},
|
||||
|
@ -20,11 +20,11 @@
|
||||
{{ download_button(_("Download all my pictures")) }}
|
||||
{% endif %}
|
||||
|
||||
<template x-for="[album, pictures] in Object.entries(albums)" x-cloak>
|
||||
<template x-for="[album_id, pictures] in Object.entries(albums)" x-cloak>
|
||||
<section>
|
||||
<br />
|
||||
<div class="row">
|
||||
<h4 x-text="album"></h4>
|
||||
<h4 x-text="pictures[0].album.name" :id="`album-${album_id}`"></h4>
|
||||
{% if user.id == object.id %}
|
||||
{{ download_button("") }}
|
||||
{% endif %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user