add exceptions
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
|
||||
from django.http import HttpResponse
|
||||
from collections import deque
|
||||
from django.http import Http404, HttpResponse
|
||||
from django.shortcuts import render
|
||||
|
||||
from .models import Album
|
||||
@@ -8,12 +9,11 @@ from .models import Album
|
||||
|
||||
def __get_image_list(file_path):
|
||||
img_list = []
|
||||
valid_images = [".jpg", ".png"]
|
||||
|
||||
if os.path.exists(file_path):
|
||||
for f in os.listdir(file_path):
|
||||
ext = os.path.splitext(f)[1]
|
||||
valid_images = [".jpg", ".png"]
|
||||
|
||||
if ext.lower() not in valid_images:
|
||||
continue
|
||||
|
||||
@@ -28,16 +28,19 @@ def index(request):
|
||||
_path = "/static/images/"
|
||||
|
||||
if request.user.is_authenticated:
|
||||
albums = Album.objects.all()
|
||||
albums = deque(Album.objects.all())
|
||||
else:
|
||||
albums = Album.objects.filter(status="20")
|
||||
# show only PUBLIC albums ("20" -> PUBLIC)
|
||||
albums = deque(Album.objects.filter(status="20"))
|
||||
|
||||
for album in albums:
|
||||
for album in list(albums):
|
||||
if not album.thumbnail:
|
||||
file_path = os.path.join(_base_dir + _path, album.folder_path)
|
||||
img_list = __get_image_list(file_path)
|
||||
if img_list:
|
||||
album.thumbnail = img_list[0]
|
||||
else:
|
||||
albums.remove(album)
|
||||
|
||||
context = {
|
||||
"albums": albums,
|
||||
@@ -53,6 +56,8 @@ def show_album(request, slug):
|
||||
_path = "/static/images/"
|
||||
|
||||
album = Album.objects.filter(slug=slug).first()
|
||||
if not album:
|
||||
raise Http404("wrong album slug")
|
||||
|
||||
file_path = os.path.join(_base_dir + _path, album.folder_path)
|
||||
img_list = __get_image_list(file_path)
|
||||
|
||||
Reference in New Issue
Block a user