From 5f529dc2b90d4b2ac57c4c0645667e001da60405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9DNyymix=E2=80=9D?= Date: Fri, 28 Mar 2025 21:37:50 +0200 Subject: [PATCH] Update about page --- config/settings.py | 41 +++++++++++----- gallery/migrations/0001_initial.py | 8 +++- gallery/templates/gallery/about.html | 50 ++++++++++++++++---- gallery/templates/gallery/photo_detail.html | 2 +- gallery/templatetags/stats.py | 13 +++++ gallery/templatetags/top_tags.py | 7 +++ gallery/views.py | 6 +++ static/img/{profile.png => default.png} | Bin 8 files changed, 102 insertions(+), 25 deletions(-) create mode 100644 gallery/templatetags/stats.py rename static/img/{profile.png => default.png} (100%) diff --git a/config/settings.py b/config/settings.py index 3a8298f..14eebd4 100644 --- a/config/settings.py +++ b/config/settings.py @@ -138,19 +138,13 @@ MEDIA_ROOT = BASE_DIR / 'media' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' -# Import local settings -try: - from .local_settings import * -except ImportError: - pass - # Session lifetime 1 year SESSION_COOKIE_AGE = 31556000 # Gotify -#GOTIFY_URL = "https://gotify....." -#GOTIFY_TOKEN = "topsecret" +# GOTIFY_URL = "https://gotify....." +# GOTIFY_TOKEN = "topsecret" LOGGING = { 'version': 1, @@ -166,10 +160,10 @@ LOGGING = { }, }, 'handlers': { - #'gotify': { + # 'gotify': { # 'level': 'ERROR', - # 'class': 'gallery.logging_handlers.GotifyHandler', - #}, + # 'class': 'gallery.logging_handlers.GotifyHandler', + # }, 'error_file': { 'level': 'ERROR', 'class': 'logging.FileHandler', @@ -185,10 +179,31 @@ LOGGING = { }, 'loggers': { 'django': { - #'handlers': ['error_file', 'warning_file', 'gotify'], + # 'handlers': ['error_file', 'warning_file', 'gotify'], 'handlers': ['error_file', 'warning_file'], 'level': 'WARNING', 'propagate': True, }, }, -} \ No newline at end of file +} + +ABOUT_PAGE_SETTINGS = { + + "title": "Muistox gallery", + "description": "Just another wannabe photographer...", + "profile_image": "img/default.png", + + "contact_email": "muistox@gallery.invalid", + + "bluesky_url": "https://bsky.app/", + "twitter_url": "https://twitter.com/", + "instagram_url": "https://www.instagram.com/", + +} + + +# Import local settings +try: + from .local_settings import * +except ImportError: + pass diff --git a/gallery/migrations/0001_initial.py b/gallery/migrations/0001_initial.py index c9535d6..e27c6f7 100644 --- a/gallery/migrations/0001_initial.py +++ b/gallery/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.1.4 on 2025-02-23 15:54 +# Generated by Django 5.1.7 on 2025-03-28 19:11 import datetime import django.db.models.deletion @@ -56,7 +56,7 @@ class Migration(migrations.Migration): name='Photo', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('slug', models.CharField(editable=False, max_length=15, verbose_name='Photo Slug')), + ('slug', models.CharField(editable=False, max_length=15, unique=True, verbose_name='Photo Slug')), ('photo', models.ImageField(height_field='height', upload_to=gallery.models.photo.get_upload_path, verbose_name='Photo', width_field='width')), ('width', models.PositiveIntegerField(default=0, editable=False, verbose_name='Photo Width')), ('height', models.PositiveIntegerField(default=0, editable=False, verbose_name='Photo Height')), @@ -88,4 +88,8 @@ class Migration(migrations.Migration): 'verbose_name_plural': 'Redirs', }, ), + migrations.AddConstraint( + model_name='photo', + constraint=models.UniqueConstraint(fields=('slug',), name='unique_photo_slug'), + ), ] diff --git a/gallery/templates/gallery/about.html b/gallery/templates/gallery/about.html index 157d51a..54c233a 100644 --- a/gallery/templates/gallery/about.html +++ b/gallery/templates/gallery/about.html @@ -1,5 +1,6 @@ {% extends "base_dark.html" %} -{% load top_tags %} +{% load static %} +{% load stats %} {% block title %} Gallery : About{% endblock %} @@ -7,17 +8,48 @@ {% block content %} -
-
- {% load static %} - Contact +{% gallery_stats as counts %} -
- - - +
+
+

{{ about.title }}

+ + Nyymix profiilikuva + +

+ {{ about.description }} +

+ + +

+ Contact: + + {{ about.contact_email }} + +

+ + +
+ {% if about.bluesky_url %} + + {% endif %} + {% if about.twitter_url %} + + {% endif %} + {% if about.instagram_url %} + + {% endif %}
+
+ +
+

+ {{ counts.0 }} Albums (public {{ counts.1 }}), + {{ counts.2 }} Photos

+
diff --git a/gallery/templates/gallery/photo_detail.html b/gallery/templates/gallery/photo_detail.html index 8b36f82..52a4b4e 100644 --- a/gallery/templates/gallery/photo_detail.html +++ b/gallery/templates/gallery/photo_detail.html @@ -42,7 +42,7 @@
-
+
  • diff --git a/gallery/templatetags/stats.py b/gallery/templatetags/stats.py new file mode 100644 index 0000000..c80e57c --- /dev/null +++ b/gallery/templatetags/stats.py @@ -0,0 +1,13 @@ +from django import template + +from gallery.models import Album, Photo + +register = template.Library() + + +@register.simple_tag +def gallery_stats(): + total_photos = Photo.objects.count() + total_albums = Album.objects.count() + public_albums = Album.objects.filter(is_public=True).count() + return total_albums, public_albums, total_photos \ No newline at end of file diff --git a/gallery/templatetags/top_tags.py b/gallery/templatetags/top_tags.py index 0b3fa7f..9b8fc64 100644 --- a/gallery/templatetags/top_tags.py +++ b/gallery/templatetags/top_tags.py @@ -11,27 +11,34 @@ 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): photos = Photo.objects.filter(album=album).order_by('-is_favorite', '-likes', '-views').select_related('album')[:count] return photos + + diff --git a/gallery/views.py b/gallery/views.py index b8b627e..be191fe 100644 --- a/gallery/views.py +++ b/gallery/views.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.core.paginator import Paginator from django.shortcuts import get_object_or_404, redirect from django.views.generic import DetailView, ListView, TemplateView @@ -90,6 +91,11 @@ class PhotoDetail(DetailView): class About(TemplateView): template_name = "gallery/about.html" + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["about"] = settings.ABOUT_PAGE_SETTINGS # Haetaan asetukset + return context + def redirect_to_album(request, redir_path): redir = get_object_or_404(Redir, path=redir_path) diff --git a/static/img/profile.png b/static/img/default.png similarity index 100% rename from static/img/profile.png rename to static/img/default.png