Add main homepage
This commit is contained in:
parent
59a4ffc4ff
commit
4436042738
3 changed files with 95 additions and 3 deletions
79
gallery/templates/gallery/main.html
Normal file
79
gallery/templates/gallery/main.html
Normal file
|
@ -0,0 +1,79 @@
|
|||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
{% load image_tags %}
|
||||
|
||||
<!-- Title -->
|
||||
{% block title %} Home {% endblock %}
|
||||
|
||||
<!-- Parallax -->
|
||||
{% block parallax %}
|
||||
{% include "./partials/parallax.html" %}
|
||||
{% endblock %}
|
||||
|
||||
<!-- Content -->
|
||||
{% block content %}
|
||||
|
||||
<!-- Favorite random portrait photos -->
|
||||
{% load top_tags %}
|
||||
{% random_favorite_photos_portrait 10 as top_portrait_photos %}
|
||||
|
||||
{% if top_portrait_photos %}
|
||||
<div uk-slider>
|
||||
<div class="uk-position-relative uk-visible-toggle uk-light" tabindex="-1">
|
||||
<div class="uk-slider-items uk-child-width-1-2 uk-child-width-1-3@s uk-child-width-1-4@m">
|
||||
{% for photo in top_portrait_photos %}
|
||||
<div>
|
||||
<a href="{{ photo.get_absolute_url }}">
|
||||
<img src="{{ photo.photo_md.url }}" alt="{{ photo.album.slug }}" width="400" height="600" style="object-fit: cover;">
|
||||
</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<a class="uk-position-center-left uk-position-small uk-hidden-hover" href uk-slidenav-previous uk-slider-item="previous"></a>
|
||||
<a class="uk-position-center-right uk-position-small uk-hidden-hover" href uk-slidenav-next uk-slider-item="next"></a>
|
||||
</div>
|
||||
<ul class="uk-slider-nav uk-dotnav uk-flex-center uk-margin"></ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Latest albums -->
|
||||
<div class="uk-grid-small uk-child-width-1-2@s uk-child-width-1-3@m" uk-grid="masonry: true">
|
||||
|
||||
{% for album in latest_albums %}
|
||||
<div>
|
||||
<div class="uk-card uk-card-default uk-height-1-1">
|
||||
|
||||
<!-- Album cover image -->
|
||||
<div class="uk-card-media-top">
|
||||
<a href="{{ album.get_absolute_url }}">
|
||||
{% with album|cover_image_data as img %}
|
||||
<img
|
||||
src="{{ img.url }}"
|
||||
width="{{ img.width }}"
|
||||
height="{{ img.height }}"
|
||||
style="aspect-ratio: {{ img.aspect_ratio }};"
|
||||
alt="Cover image for {{ album.name }}"
|
||||
title="{{ album.name }}"
|
||||
loading="lazy">
|
||||
{% endwith %}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Album info overlay -->
|
||||
<div class="uk-overlay uk-overlay-primary uk-position-bottom uk-padding-small">
|
||||
<h3 class="uk-card-title uk-margin-remove-bottom">
|
||||
<a href="{{ album.get_absolute_url }}">{{ album }}</a>
|
||||
</h3>
|
||||
<p class="uk-text-small uk-margin-remove-top">
|
||||
{{ album.photos_in_album }} photos •
|
||||
{{ album.photos_views }} views
|
||||
</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
|
@ -5,7 +5,7 @@ from . import converters, views
|
|||
app_name = 'gallery'
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.AlbumsList.as_view(), name='main_url'),
|
||||
path('', views.Main.as_view(), name='main_url'),
|
||||
path('about/', views.About.as_view(), name='about_url'),
|
||||
path('search/', views.Search.as_view(), name='search_url'),
|
||||
path('photostream/', views.PhotosList.as_view(), name='photos_url'),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.core.paginator import Paginator
|
||||
from django.db.models import Count, Q, Sum
|
||||
from django.db.models import Count, F, Q, Sum
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.urls import reverse
|
||||
|
@ -11,6 +11,18 @@ from django.views.generic import DetailView, ListView, TemplateView
|
|||
from .models import Album, Photo, Redir
|
||||
|
||||
|
||||
class Main(TemplateView):
|
||||
"""Main homepage."""
|
||||
template_name = "gallery/main.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['canonical_url'] = self.request.build_absolute_uri(reverse('gallery:main_url'))
|
||||
context['latest_albums'] = Album.objects.filter(is_public=True).order_by('-album_date')[:6]
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class AlbumsList(ListView):
|
||||
"""Displays a paginated list of public albums."""
|
||||
model = Album
|
||||
|
@ -88,7 +100,8 @@ class PhotosList(ListView):
|
|||
ordering_options = {
|
||||
'latest': '-taken_at',
|
||||
'liked': 'likes',
|
||||
'popular': '-views'
|
||||
'popular': '-views',
|
||||
'favorite': '-is_favorite'
|
||||
}
|
||||
order = ordering_options.get(self.request.GET.get('order', 'latest'), '-taken_at')
|
||||
return Photo.objects.filter(album__is_public=True).order_by(order).select_related('album')
|
||||
|
|
Loading…
Add table
Reference in a new issue