From d83842af27efc34b2ba0e0b1c5d485eb91a78f4a Mon Sep 17 00:00:00 2001 From: Julien Constant <49886317+Juknum@users.noreply.github.com> Date: Wed, 5 Apr 2023 14:32:32 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20probl=C3=A8me=20de=20cache=20dans=20le=20?= =?UTF-8?q?SAS=20&=20am=C3=A9liore=20le=20CSS=20du=20SAS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartuccio Antoine --- core/static/sas/album.scss | 5 +++++ core/static/sas/picture.scss | 5 +++-- sas/models.py | 23 +++++++++++------------ sas/templates/sas/album.jinja | 2 +- sas/templates/sas/picture.jinja | 2 +- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/core/static/sas/album.scss b/core/static/sas/album.scss index fbbba94b..b84d0dd3 100644 --- a/core/static/sas/album.scss +++ b/core/static/sas/album.scss @@ -160,6 +160,7 @@ main { > .photo, > .album { box-sizing: border-box; + background-color: #333333; background-size: cover; background-repeat: no-repeat; background-position: center center; @@ -167,6 +168,10 @@ main { width: calc(16 / 9 * 128px); height: 128px; + &.vertical { + background-size: contain; + } + margin: 0; padding: 0; box-shadow: none; diff --git a/core/static/sas/picture.scss b/core/static/sas/picture.scss index 520c8d9d..d65bf826 100644 --- a/core/static/sas/picture.scss +++ b/core/static/sas/picture.scss @@ -70,7 +70,7 @@ > #next { width: calc(50% - 5px); aspect-ratio: 16/9; - background: #aaa; + background: #333333; > a { display: flex; @@ -241,6 +241,7 @@ > .infos { display: flex; flex-direction: column; + width: 50%; > div > div { display: flex; @@ -260,7 +261,7 @@ > .tools { display: flex; flex-direction: column; - width: 100%; + width: 50%; > div { display: flex; diff --git a/sas/models.py b/sas/models.py index d6a10e49..639c3898 100644 --- a/sas/models.py +++ b/sas/models.py @@ -63,7 +63,12 @@ class Picture(SithFile): return (w / h) < 1 def can_be_edited_by(self, user): - return user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID) + perm = cache.get("%d_can_edit_pictures" % (user.id), None) + if perm is None: + perm = user.is_root or user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID) + + cache.set("%d_can_edit_pictures" % (user.id), perm, timeout=4) + return perm def can_be_viewed_by(self, user): # SAS pictures are visible to old subscribers @@ -72,19 +77,13 @@ class Picture(SithFile): return False perm = cache.get("%d_can_view_pictures" % (user.id), False) + if not perm: + perm = user.was_subscribed - # use cache only when user is in SAS Admins or when picture is moderated - if perm and (self.is_moderated or self.can_be_edited_by(user)): - return perm - - perm = ( - self.is_in_sas - and (self.is_moderated or self.can_be_edited_by(user)) - and user.was_subscribed - ) cache.set("%d_can_view_pictures" % (user.id), perm, timeout=4) - - return perm + return (perm and self.is_moderated and self.is_in_sas) or self.can_be_edited_by( + user + ) def get_download_url(self): return reverse("sas:download", kwargs={"picture_id": self.id}) diff --git a/sas/templates/sas/album.jinja b/sas/templates/sas/album.jinja index 16ae6d29..ca3f7804 100644 --- a/sas/templates/sas/album.jinja +++ b/sas/templates/sas/album.jinja @@ -88,7 +88,7 @@ {% if p.can_be_viewed_by(user) %}
{% if not p.is_moderated %} diff --git a/sas/templates/sas/picture.jinja b/sas/templates/sas/picture.jinja index f22fbdb0..848f0aec 100644 --- a/sas/templates/sas/picture.jinja +++ b/sas/templates/sas/picture.jinja @@ -38,7 +38,7 @@

{{ picture.get_display_name() }}

{{ picture.parent.children.filter(id__lte=picture.id).count() }} / {{ picture.parent.children.count() }}

- +
{% if not picture.is_moderated %} {% set next = picture.get_next() %}