mirror of
https://github.com/kennethreitz/photos.kennethreitz.org.git
synced 2026-06-05 06:46:13 +00:00
Add Years browsing: /years/ list and /years/<year>/ detail with infinite scroll
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
<a href="{% url 'tree:lens-list' %}">Lenses</a>
|
||||
<a href="{% url 'tree:tag-cloud' %}">Tags</a>
|
||||
<a href="{% url 'tree:city-list' %}">Cities</a>
|
||||
<a href="{% url 'tree:year-list' %}">Years</a>
|
||||
{% if has_collections %}<a href="{% url 'gallery:collection-list' %}">Collections</a>{% endif %}
|
||||
<a href="{% url 'search:search' %}">Search</a>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}{{ year }} — {{ site_title }}{% endblock %}
|
||||
{% block meta_description %}Photos from {{ year }}{% endblock %}
|
||||
{% block og_title %}{{ year }}{% endblock %}
|
||||
{% block og_description %}Photos from {{ year }}{% endblock %}
|
||||
{% block content %}
|
||||
<div class="page-header">
|
||||
<h1>{{ year }}</h1>
|
||||
</div>
|
||||
|
||||
<div class="image-grid" style="grid-template-columns: repeat(4, 1fr);">
|
||||
{% include "includes/image_grid_page.html" %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,19 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Years — {{ site_title }}{% endblock %}
|
||||
{% block content %}
|
||||
<div class="page-header">
|
||||
<h1>Years</h1>
|
||||
<p>Browse photos by year</p>
|
||||
</div>
|
||||
|
||||
<div class="gear-grid">
|
||||
{% for y in years %}
|
||||
<a href="/years/{{ y.year }}/" class="gear-card" style="color: inherit;">
|
||||
<h3>{{ y.year }}</h3>
|
||||
<span class="count">{{ y.image_count }} images</span>
|
||||
</a>
|
||||
{% empty %}
|
||||
<div class="empty" style="grid-column: 1 / -1;">No dated photos yet.</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -15,4 +15,6 @@ urlpatterns = [
|
||||
path('tags/<slug:slug>/', views.tag_detail, name='tag-detail'),
|
||||
path('cities/', views.city_list, name='city-list'),
|
||||
path('cities/<slug:slug>/', views.city_detail, name='city-detail'),
|
||||
path('years/', views.year_list, name='year-list'),
|
||||
path('years/<int:year>/', views.year_detail, name='year-detail'),
|
||||
]
|
||||
|
||||
@@ -230,6 +230,40 @@ def city_detail(request, slug):
|
||||
})
|
||||
|
||||
|
||||
def year_list(request):
|
||||
from core.models import ExifData
|
||||
from django.db.models.functions import ExtractYear
|
||||
|
||||
years = (
|
||||
ExifData.objects.filter(date_taken__isnull=False)
|
||||
.annotate(year=ExtractYear('date_taken'))
|
||||
.values('year')
|
||||
.annotate(image_count=Count('id'))
|
||||
.order_by('-year')
|
||||
)
|
||||
return render(request, 'tree/year_list.html', {'years': years})
|
||||
|
||||
|
||||
def year_detail(request, year):
|
||||
qs = (
|
||||
Image.objects.filter(
|
||||
exif__date_taken__year=year,
|
||||
visibility=Image.Visibility.PUBLIC,
|
||||
is_processing=False,
|
||||
)
|
||||
.select_related('user', 'exif', 'exif__camera', 'exif__lens')
|
||||
)
|
||||
images, page, has_more = _paginate_shuffled(request, qs)
|
||||
|
||||
if request.headers.get('HX-Request'):
|
||||
return render(request, 'includes/image_grid_page.html', {
|
||||
'images': images, 'page': page, 'has_more': has_more,
|
||||
})
|
||||
return render(request, 'tree/year_detail.html', {
|
||||
'year': year, 'images': images, 'page': page, 'has_more': has_more,
|
||||
})
|
||||
|
||||
|
||||
def lens_detail(request, slug):
|
||||
lens = get_object_or_404(Lens, slug=slug)
|
||||
qs = (
|
||||
|
||||
Reference in New Issue
Block a user