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.conf import settings
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db.models import F
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from ninja import Body, File, Query
|
from ninja import Body, File, Query
|
||||||
from ninja.security import SessionAuth
|
from ninja.security import SessionAuth
|
||||||
@ -105,8 +104,7 @@ class PicturesController(ControllerBase):
|
|||||||
filters.filter(Picture.objects.viewable_by(user))
|
filters.filter(Picture.objects.viewable_by(user))
|
||||||
.distinct()
|
.distinct()
|
||||||
.order_by("-parent__date", "date")
|
.order_by("-parent__date", "date")
|
||||||
.select_related("owner")
|
.select_related("owner", "parent")
|
||||||
.annotate(album=F("parent__name"))
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@route.post(
|
@route.post(
|
||||||
@ -153,7 +151,9 @@ class PicturesController(ControllerBase):
|
|||||||
|
|
||||||
@route.put("/{picture_id}/identified", permissions=[IsAuthenticated, CanView])
|
@route.put("/{picture_id}/identified", permissions=[IsAuthenticated, CanView])
|
||||||
def identify_users(self, picture_id: NonNegativeInt, users: set[NonNegativeInt]):
|
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))
|
db_users = list(User.objects.filter(id__in=users))
|
||||||
if len(users) != len(db_users):
|
if len(users) != len(db_users):
|
||||||
raise NotFound
|
raise NotFound
|
||||||
@ -166,13 +166,15 @@ class PicturesController(ControllerBase):
|
|||||||
]
|
]
|
||||||
PeoplePictureRelation.objects.bulk_create(relations)
|
PeoplePictureRelation.objects.bulk_create(relations)
|
||||||
for u in identified:
|
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(
|
Notification.objects.get_or_create(
|
||||||
user=u,
|
user=u,
|
||||||
viewed=False,
|
viewed=False,
|
||||||
type="NEW_PICTURES",
|
type="NEW_PICTURES",
|
||||||
defaults={
|
defaults={"url": url, "param": picture.parent.name},
|
||||||
"url": reverse("sas:user_pictures", kwargs={"user_id": u.id})
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@route.delete("/{picture_id}", permissions=[IsSasAdmin])
|
@route.delete("/{picture_id}", permissions=[IsSasAdmin])
|
||||||
|
@ -18,6 +18,12 @@ class AlbumFilterSchema(FilterSchema):
|
|||||||
parent_id: int | None = Field(None, q="parent_id")
|
parent_id: int | None = Field(None, q="parent_id")
|
||||||
|
|
||||||
|
|
||||||
|
class SimpleAlbumSchema(ModelSchema):
|
||||||
|
class Meta:
|
||||||
|
model = Album
|
||||||
|
fields = ["id", "name"]
|
||||||
|
|
||||||
|
|
||||||
class AlbumSchema(ModelSchema):
|
class AlbumSchema(ModelSchema):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Album
|
model = Album
|
||||||
@ -70,7 +76,7 @@ class PictureSchema(ModelSchema):
|
|||||||
full_size_url: str
|
full_size_url: str
|
||||||
compressed_url: str
|
compressed_url: str
|
||||||
thumb_url: str
|
thumb_url: str
|
||||||
album: str
|
album: SimpleAlbumSchema = Field(alias="parent")
|
||||||
report_url: str
|
report_url: str
|
||||||
edit_url: str
|
edit_url: str
|
||||||
|
|
||||||
|
@ -22,11 +22,11 @@ document.addEventListener("alpine:init", () => {
|
|||||||
} as PicturesFetchPicturesData);
|
} as PicturesFetchPicturesData);
|
||||||
|
|
||||||
this.albums = this.pictures.reduce(
|
this.albums = this.pictures.reduce(
|
||||||
(acc: Record<string, PictureSchema[]>, picture: PictureSchema) => {
|
(acc: Record<number, PictureSchema[]>, picture: PictureSchema) => {
|
||||||
if (!acc[picture.album]) {
|
if (!acc[picture.album.id]) {
|
||||||
acc[picture.album] = [];
|
acc[picture.album.id] = [];
|
||||||
}
|
}
|
||||||
acc[picture.album].push(picture);
|
acc[picture.album.id].push(picture);
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{},
|
{},
|
||||||
|
@ -20,11 +20,11 @@
|
|||||||
{{ download_button(_("Download all my pictures")) }}
|
{{ download_button(_("Download all my pictures")) }}
|
||||||
{% endif %}
|
{% 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>
|
<section>
|
||||||
<br />
|
<br />
|
||||||
<div class="row">
|
<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 %}
|
{% if user.id == object.id %}
|
||||||
{{ download_button("") }}
|
{{ download_button("") }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user