optimize view
This commit is contained in:
@@ -15,6 +15,18 @@ from .utils import create_thumbs, get_folder_list, get_image_list
|
|||||||
def index(request):
|
def index(request):
|
||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
albums = deque(Album.objects.all().order_by("-event_date"))
|
albums = deque(Album.objects.all().order_by("-event_date"))
|
||||||
|
|
||||||
|
# get albums that are in the server but not in the db.
|
||||||
|
folders = get_folder_list()
|
||||||
|
if folders:
|
||||||
|
for folder in folders:
|
||||||
|
if not Album.objects.filter(folder_name=folder):
|
||||||
|
album = Album(
|
||||||
|
title=folder,
|
||||||
|
slug=slugify(folder),
|
||||||
|
folder_name=folder,
|
||||||
|
event_date=None,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# show only PUBLIC albums.
|
# show only PUBLIC albums.
|
||||||
albums = deque(
|
albums = deque(
|
||||||
@@ -36,27 +48,10 @@ def index(request):
|
|||||||
value = randint(0, len(img_list) - 1)
|
value = randint(0, len(img_list) - 1)
|
||||||
album.thumbnail = img_list[value]["thumb_url"]
|
album.thumbnail = img_list[value]["thumb_url"]
|
||||||
else:
|
else:
|
||||||
# empty album is set to DRAFT.
|
# empty album is temporarily set to DRAFT.
|
||||||
|
album.thumbnail = settings.STATIC_URL + "img/FET-Logo-2014-quadrat.png"
|
||||||
album.status = Album.DRAFT
|
album.status = Album.DRAFT
|
||||||
|
|
||||||
if request.user.is_authenticated:
|
|
||||||
folders = get_folder_list()
|
|
||||||
if folders:
|
|
||||||
for folder in folders:
|
|
||||||
if not Album.objects.filter(folder_name=folder):
|
|
||||||
album = Album(
|
|
||||||
title=folder,
|
|
||||||
slug=slugify(folder),
|
|
||||||
folder_name=folder,
|
|
||||||
event_date=None,
|
|
||||||
)
|
|
||||||
|
|
||||||
img_list = get_image_list(album.folder_name)
|
|
||||||
if img_list:
|
|
||||||
value = randint(0, len(img_list) - 1)
|
|
||||||
album.thumbnail = img_list[value]["thumb_url"]
|
|
||||||
albums.append(album)
|
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"albums": albums,
|
"albums": albums,
|
||||||
}
|
}
|
||||||
@@ -80,6 +75,10 @@ def show_album(request, slug):
|
|||||||
raise Http404("wrong album slug")
|
raise Http404("wrong album slug")
|
||||||
|
|
||||||
img_list = get_image_list(album.folder_name)
|
img_list = get_image_list(album.folder_name)
|
||||||
|
if not img_list:
|
||||||
|
# empty album is temporarily set to DRAFT.
|
||||||
|
album.status = Album.DRAFT
|
||||||
|
|
||||||
create_thumbs(album.folder_name)
|
create_thumbs(album.folder_name)
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
<a href="{% url 'admin:gallery_album_change' album.id %}" class="page-subtitle block btn-small btn-primary w-full sm:w-max sm:mr-0 sm:ml-auto">
|
<a href="{% url 'admin:gallery_album_change' album.id %}" class="page-subtitle block btn-small btn-primary w-full sm:w-max sm:mr-0 sm:ml-auto">
|
||||||
<i class="fa-regular fa-folder-open mr-1"></i>Album bearbeiten
|
<i class="fa-solid fa-folder-open mr-1"></i>Album bearbeiten
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|||||||
@@ -15,15 +15,19 @@
|
|||||||
|
|
||||||
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 justify-items-center gap-4">
|
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 justify-items-center gap-4">
|
||||||
{% for album in albums %}
|
{% for album in albums %}
|
||||||
{% if album.status == "10" %}
|
{% if request.user.is_authenticated and album.status == album.DRAFT %}
|
||||||
<a href="{% url 'gallery:draft-album' album.slug %}" class="block max-w-xs sm:max-w-none">
|
<a href="{% url 'gallery:draft-album' album.slug %}" class="block max-w-xs sm:max-w-none">
|
||||||
{% else %}
|
|
||||||
<a href="{% url 'gallery:album' album.slug %}" class="block max-w-xs sm:max-w-none">
|
|
||||||
{% endif %}
|
|
||||||
<img src="{{ album.thumbnail }}" class="rounded">
|
<img src="{{ album.thumbnail }}" class="rounded">
|
||||||
<h2 class="px-2 text-proprietary-dark dark:text-sky-300">{{ album.title }}</h2>
|
<h2 class="px-2 text-proprietary-dark dark:text-sky-300">{{ album.title }}</h2>
|
||||||
<h3 class="px-2 text-sm text-proprietary dark:text-sky-400 font-normal"><i class="fa-solid fa-calendar-day mr-1"></i>{{ album.event_date }}</h3>
|
<h3 class="px-2 text-sm text-proprietary dark:text-sky-400 font-normal"><i class="fa-solid fa-calendar-day mr-1"></i>{{ album.event_date }}</h3>
|
||||||
</a>
|
</a>
|
||||||
|
{% elif album.status == album.PUBLIC %}
|
||||||
|
<a href="{% url 'gallery:album' album.slug %}" class="block max-w-xs sm:max-w-none">
|
||||||
|
<img src="{{ album.thumbnail }}" class="rounded">
|
||||||
|
<h2 class="px-2 text-proprietary-dark dark:text-sky-300">{{ album.title }}</h2>
|
||||||
|
<h3 class="px-2 text-sm text-proprietary dark:text-sky-400 font-normal"><i class="fa-solid fa-calendar-day mr-1"></i>{{ album.event_date }}</h3>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user