From 469304585c2929046680ddccb80a6215deed72cc Mon Sep 17 00:00:00 2001 From: Skia Date: Mon, 25 Sep 2017 12:34:05 +0200 Subject: [PATCH] sas: update models managers Signed-off-by: Skia --- sas/models.py | 21 +++++++++++++++++---- sas/templates/sas/main.jinja | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/sas/models.py b/sas/models.py index b88d599d..33ef8899 100644 --- a/sas/models.py +++ b/sas/models.py @@ -34,11 +34,22 @@ import os from core.models import SithFile, User from core.utils import resize_image, exif_auto_rotate +class SASPictureManager(models.Manager): + def get_queryset(self): + return super(SASPictureManager, self).get_queryset().filter(is_in_sas=True, + is_folder=False) + +class SASAlbumManager(models.Manager): + def get_queryset(self): + return super(SASAlbumManager, self).get_queryset().filter(is_in_sas=True, + is_folder=True) class Picture(SithFile): class Meta: proxy = True + objects = SASPictureManager() + @property def is_vertical(self): with open(os.path.join(settings.MEDIA_ROOT, self.file.name).encode('utf-8'), 'rb') as f: @@ -104,27 +115,29 @@ class Picture(SithFile): return self.parent.children.filter(is_moderated=True, asked_for_removal=False, is_folder=False, id__gt=self.id).order_by('id').first() else: - return Picture.objects.filter(id__gt=self.id, is_moderated=False, is_in_sas=True).order_by('id').first() + return Picture.objects.filter(id__gt=self.id, is_moderated=False).order_by('id').first() def get_previous(self): if self.is_moderated: return self.parent.children.filter(is_moderated=True, asked_for_removal=False, is_folder=False, id__lt=self.id).order_by('id').last() else: - return Picture.objects.filter(id__lt=self.id, is_moderated=False, is_in_sas=True).order_by('-id').first() + return Picture.objects.filter(id__lt=self.id, is_moderated=False).order_by('-id').first() class Album(SithFile): class Meta: proxy = True + objects = SASAlbumManager() + @property def children_pictures(self): - return Picture.objects.filter(parent=self, is_folder=False) + return Picture.objects.filter(parent=self) @property def children_albums(self): - return Album.objects.filter(parent=self, is_folder=True) + return Album.objects.filter(parent=self) def can_be_edited_by(self, user): # file = SithFile.objects.filter(id=self.id).first() diff --git a/sas/templates/sas/main.jinja b/sas/templates/sas/main.jinja index 30cd0797..db14bb86 100644 --- a/sas/templates/sas/main.jinja +++ b/sas/templates/sas/main.jinja @@ -10,7 +10,7 @@
{% if a.file %} - {% trans %}preview{% endtrans %} + {% trans %}preview{% endtrans %} {% elif a.children.filter(is_folder=False, is_moderated=True).exists() %} {% trans %}preview{% endtrans %} {% else %}