diff --git a/gallery/templates/gallery/album_list.html b/gallery/templates/gallery/album_list.html
index 2d1b405..f1a2841 100644
--- a/gallery/templates/gallery/album_list.html
+++ b/gallery/templates/gallery/album_list.html
@@ -4,6 +4,10 @@
{% block title %} Gallery : Albums {% endblock %}
+
+{% block parallax %}
+ {% include "./partials/parallax.html" %}
+{% endblock %}
{% block content %}
diff --git a/gallery/templates/gallery/main.html b/gallery/templates/gallery/main.html
deleted file mode 100644
index 6da4000..0000000
--- a/gallery/templates/gallery/main.html
+++ /dev/null
@@ -1,27 +0,0 @@
-{% extends "base_dark.html" %}
-{% load top_tags %}
-
-
-{% block title %} Gallery {% endblock %}
-
-
-{% block content %}
- Hello World!
-
-
- {% last_albums as albums %}
- {% for album in albums %}
- - {{ album.name }}
- {% endfor %}
-
-
-
- {% top_photos as photos %}
- {% for photo in photos %}
- - {{ photo.views }} {{ photo.likes }} {{ photo.is_favorite }} {{ photo }}
- {% endfor %}
-
-
- Istunto vanhenee: {{ session_expiry|date:"d.m.Y H:i" }}
-
-{% endblock %}
\ No newline at end of file
diff --git a/gallery/templates/gallery/partials/parallax.html b/gallery/templates/gallery/partials/parallax.html
new file mode 100644
index 0000000..efeb491
--- /dev/null
+++ b/gallery/templates/gallery/partials/parallax.html
@@ -0,0 +1,21 @@
+{% load top_tags %}
+{% load static %}
+
+
+
+ {% random_photos_landscape as top_photos %}
+ {% if top_photos %}
+ {% for photo in top_photos %}
+ -
+
+
+ {% endfor %}
+ {% else %}
+ -
+
+
+ {% endif %}
+
+
+
+
\ No newline at end of file
diff --git a/gallery/templates/gallery/photo_list.html b/gallery/templates/gallery/photo_list.html
index 44ef8b1..8882277 100644
--- a/gallery/templates/gallery/photo_list.html
+++ b/gallery/templates/gallery/photo_list.html
@@ -1,16 +1,22 @@
{% extends "base_dark.html" %}
-
+{% load static %}
{% block title %} Gallery : Photostream {% endblock %}
+
+{% block parallax %}
+ {% include "./partials/parallax.html" %}
+{% endblock %}
+
{% block content %}
{% load link_tags %}
-
+
+
diff --git a/gallery/templatetags/top_tags.py b/gallery/templatetags/top_tags.py
index 94ee617..0b3fa7f 100644
--- a/gallery/templatetags/top_tags.py
+++ b/gallery/templatetags/top_tags.py
@@ -1,4 +1,5 @@
from django import template
+from django.db.models import F
from gallery.models import Album, Photo
@@ -10,12 +11,25 @@ def last_albums(count=5):
albums = Album.objects.filter(is_public=True).order_by("-album_date")[:count]
return albums
-
@register.simple_tag
def top_photos(count=5):
photos = Photo.objects.filter(album__is_public=True).order_by('-is_favorite', '-likes', '-views').select_related('album')[:count]
return photos
+@register.simple_tag
+def random_photos_landscape(count=5):
+ photos = Photo.objects.filter(album__is_public=True, width__gt=F('height')).order_by('?')[:count]
+ return photos
+
+@register.simple_tag
+def top_photos_landscape(count=5):
+ photos = Photo.objects.filter(album__is_public=True, width__gt=F('height')).order_by('-views').select_related('album')[:count]
+ return photos
+
+@register.simple_tag
+def top_photos_portrait(count=5):
+ photos = Photo.objects.filter(album__is_public=True, height__gt=F('width')).order_by('-views').select_related('album')[:count]
+ return photos
@register.simple_tag
def top_photos_in_album(album, count=5):
diff --git a/gallery/urls.py b/gallery/urls.py
index 884fe21..e4c696b 100644
--- a/gallery/urls.py
+++ b/gallery/urls.py
@@ -6,7 +6,7 @@ app_name = 'gallery'
urlpatterns = [
- path('', views.Main.as_view(), name='main_url'),
+ path('', views.AlbumsList.as_view(), name='main_url'),
path('photostream/', views.PhotosList.as_view(), name='photos_url'),
path('albums///', views.PhotoDetail.as_view(), name='photo_url'),
path('albums//', views.AlbumDetail.as_view(), name='album_url'),
diff --git a/gallery/views.py b/gallery/views.py
index f80403c..bf80354 100644
--- a/gallery/views.py
+++ b/gallery/views.py
@@ -1,20 +1,12 @@
+from collections import defaultdict
+
from django.core.paginator import Paginator
-from django.shortcuts import get_object_or_404, redirect, render
+from django.shortcuts import get_object_or_404, redirect
from django.views.generic import DetailView, ListView, TemplateView
from .models import Album, Photo, Redir
-class Main(TemplateView):
- template_name = "gallery/main.html"
-
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- session_expiry = self.request.session.get_expiry_date()
- context['session_expiry'] = session_expiry
- return context
-
-
class AlbumsList(ListView):
model = Album
template_name = 'gallery/album_list.html'