Commit 46930458 authored by Skia's avatar Skia

sas: update models managers

Signed-off-by: Skia's avatarSkia <skia@libskia.so>
parent 3a16c7aa
......@@ -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()
......
......@@ -10,7 +10,7 @@
<div class="album">
<div>
{% if a.file %}
<img src="{{ a.as_picture.get_download_url() }}" alt="{% trans %}preview{% endtrans %}">
<img src="{{ a.get_download_url() }}" alt="{% trans %}preview{% endtrans %}">
{% elif a.children.filter(is_folder=False, is_moderated=True).exists() %}
<img src="{{ a.children.filter(is_folder=False).first().as_picture.get_download_thumb_url() }}" alt="{% trans %}preview{% endtrans %}">
{% else %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment